gorillascript
gorillascript copied to clipboard
Special token for marking a function as a promise generator
In some cases, the existing syntax of promise! #()* ... seems a little unwieldy, especially in the case of something like:
def get-something = promise! #(key)*
yield ...
or
{
get-something: promise! #(key)*
yield ...
}
It could be better to have another token such as % or & or something along those lines that would automatically mark the function as a generator and wrap it with promise!
The previous examples would then look like the following:
def get-something(key)%
yield ...
{
get-something(key)%
yield ...
}
Any thoughts?
def get-something |key|
yield ...
{
get-something: |key|
yield...
}
Two | metaphors fulfill/reject, my 2 cents.
I don't see the benefit of having it look completely different from the other tokens.
One would be able to do #(a, b, c)@^% to have it curried, bound to outer this, and a promise generator.
I didn't know this feature, that modifier composition is awesome. You should add this to the document.
Why not have a syntactic support for decorators? I know Python decorators are kinda stupid when one has first-class functions, but the syntax of wrapping a function into another function isn't pleasant (as you've noticed here).
I'm just thinking that maybe what we're looking at here is a new kind of concept (a function decorator) and, specifically, a new kind of macro operator (‘function postfix operator’) that should be (re-)definable? Currying, (un)binding and promise generation could all fit nicely into a single API (esp if we have a choice of making it a compile-time macro-based API).
I actually was thinking about this and is likely the way I'll be going. You'd be able to register a single-character token that you could postfix a function's parameter list with. Currying would be redefined to use this, and then adding the % for promises or whatever would be something that could take up all of three lines.
This depends on #131 now.
Totally agree with the converging solution. The army of sigils gets a bit cryptic, characters/words seem better and allow custom ones (in VimScript you can do e.g. "function! func(a, b) abort" where abort is one such special keyword. But I guess full words wouldn't lend themselves well to anonymous functions?)
Well, I'm not against the idea of >1 char signifiers on functions, but I'm not sure what the best syntax for specifying it would be. Sure the single char sigils may be cryptic, but I don't know a better way to keep the terseness of the code.
At least for the builtin function modifiers, I'd like to keep them single-char. What would be a good syntax to specify multi-char, without confusing the distinction between a single-line function, e.g.
let f() thing
from a function with a modifier?