evincarofautumn / kitten

A statically typed concatenative systems programming language.
http://kittenlang.org/
Other
1.1k stars 42 forks source link

Allow “else” in “do” #188

Open evincarofautumn opened 7 years ago

evincarofautumn commented 7 years ago

Currently, do (f) { x } is desugared to { x } f, that is, it lets you use a combinator like a flow control construct:

xs do (each):
  (* 42) say

I figure it would be useful for success/error callbacks in async code if a do block allowed an optional else:

do (http_get) -> result:
  ...
else -> error:
  ...

So do (f) { x } else { y } would desugar to { x } { y } f or maybe { y } { x } f if that turns out to work well with more functions.

I’m not sure if this needs an equivalent to elif (eldo?) for chaining multiple doelse together. It seems logical but I don’t have a specific use case in mind.