breuleux / earl-grey

Programming language compiling to JavaScript
http://breuleux.github.io/earl-grey/
MIT License
464 stars 6 forks source link

Add `finally` support to matches #32

Open MadcapJake opened 9 years ago

MadcapJake commented 9 years ago

Support a finally branch that runs after every possible branch. Perhaps not running after else?

var hidden = false
var opacity = 0.0
nudge-opacity = match ->
   up?     -> opacity += 0.1
   down?   -> opacity -= 0.1
   finally -> if opacity == 0.0: hidden = true

A return value could be handled in two ways (not sure how easy either route would be to implement):

  1. Via an argument prior to the match's -> operator: finally rval -> ...
  2. Via the body of the branch (optionally) being a function: finally -> rval -> ...

This was discussed on gitter at one point and I just remembered it and wanted to get it logged.