Arc Forumnew | comments | leaders | submitlogin
4 points by rocketnia 5134 days ago | link | parent

Macro: (thunk body). It's simple enough. Just like the square bracket syntax covers one-argument functions, this can cover zero-argument functions.

  (fn () (err "Ack! You called me!"))
  (thunk:err "Ack! You called me!")
When the function body is long, this helps reduce indentation and parentheses. (That's sort of a hobby of mine, I guess. :-p )


3 points by evanrmurphy 5119 days ago | link

> Macro: (thunk body). It's simple enough. Just like the square bracket syntax covers one-argument functions, this can cover zero-argument functions.

A side effect of making all function arguments optional [1] is that the square bracket syntax can then cover zero-argument functions too, so we get this additional (shorter) way to express your thunk example:

  [err "Ack! You called me!"]
---

[1] http://arclanguage.org/item?id=13030

-----

1 point by akkartik 5119 days ago | link

Nice. So you can use [] if it saves you a set of parens, and thunk to sidestep the implicit function call:

  (thunk 34)

-----

1 point by rocketnia 5119 days ago | link

Actually, I don't use 'thunk when it doesn't save me parens. Both "thunk" and "fn ()" take up the same number of characters (albeit not the same number of tokens), and I figure Arc programmers will have to look up what 'thunk means more often than they look up 'fn. :-p

Incidentally, it actually does save parens in that case:

  thunk.34

-----

1 point by akkartik 5134 days ago | link

Like do but without a set of parens. Nice. Wish I could define do in terms of thunk, but it's too early in arc.arc.

-----