jamiebuilds / ghost-lang

:ghost: A friendly little language for you and me.
302 stars 10 forks source link

Do blocks #9

Closed aleclarson closed 5 years ago

aleclarson commented 5 years ago

WDYT of do blocks (basically lighter IIFEs)?

let foo = do {
  let bar = doSomething()
  bar > 0 ? 1 : 0
}
jamiebuilds commented 5 years ago

Hm, somehow these got dropped when I was moving everything into markdown

aleclarson commented 5 years ago

And if you need to bind some variable(s) to scope:

let a = 2
let b = 16
let c = fn (a, b) {
  while (--a >= 0) { b /= 2 }
  b
}(a, b)
assert(a == 2) // `a` and `b` are unchanged out here
assert(b == 16)
assert(c == 4)
jamiebuilds commented 5 years ago

do {} and do async {} have been added back https://github.com/jamiebuilds/ghost-lang#do