Closed zenon closed 4 years ago
Ohhh nice! I am pleased to see that you were able to refactor that example, and I must say I like it a lot! I'll add it as default example 😊.
I also find it interesting how you rewrote the string interoplation using quote... I get carried away with symbol shorthands too much maybe lol
I'll go for the example with variable... it is definitely more readable even though the other one is definitely more "concatenative".
EDIT I just spotted the links for the / url... nice touch 😉 -- Maybe I could add a new module for easily output HTML...
Updated: https://min-lang.org/reference-http/
Thanks again!
Did I mention my surprise about your speed already? :-)
I also find it interesting how you rewrote the string interoplation using quote
Well, I didn't understand the quote/unquote logic completely, so I went the easy way. After some pondering, I now see that your solution qeneralizes to quotes with more than one element, mine doesn't.
Greetings from Hamburg!, z.
Maybe I could add a new module for easily output HTML...
Hm. Maybe like this?
("<a href='$1'>$2</a>" swap => %) :a
Now I can write the case statement like
; Constuct response body
(
((dup "/datetime" ==) (timestamp datetime))
((dup "/timestamp" ==) (timestamp string))
((dup "/shutdown" ==) ("Stopping server..." puts! stop-server))
((dup "/" ==) (
; this is a bit short, but works with Chrome, IE, Edge, Safari
((("/datetime" "Datetime") a)
(("/timestamp" "Timestamp") a)
(("/shutdown" "stop") a))
apply
", " join
))
((true) ("Invalid Request: $1" swap quote %))
) case
Hi Fabio,
as I always fool around with code while attempting to understand it, the example changed a bit, to match my own taste. I paste it here so you can decide whether to use it for the docu.
The main changes are a case structure instead of when, and
"Invalid Request: $1" (url) => %
into
"Invalid Request: $1" url quote %
as I deem this to be easyer to understand.
Then a version without variable naming
Kind greetings,
z