gorillascript icon indicating copy to clipboard operation
gorillascript copied to clipboard

Special token for marking a function as a promise generator

Open ckknight opened this issue 12 years ago • 9 comments

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?

ckknight avatar Jul 15 '13 22:07 ckknight

def get-something |key|
   yield ...
{
  get-something: |key|
     yield...
}

Two | metaphors fulfill/reject, my 2 cents.

unc0 avatar Jul 16 '13 01:07 unc0

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.

ckknight avatar Jul 16 '13 01:07 ckknight

I didn't know this feature, that modifier composition is awesome. You should add this to the document.

unc0 avatar Jul 16 '13 02:07 unc0

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).

andreyvit avatar Jul 16 '13 10:07 andreyvit

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.

ckknight avatar Jul 16 '13 21:07 ckknight

This depends on #131 now.

ckknight avatar Jul 16 '13 22:07 ckknight

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?)

goldfeld avatar Jul 17 '13 23:07 goldfeld

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?

ckknight avatar Jul 17 '13 23:07 ckknight

In my community repo, I made this:

#**
    yield stuff()

Be a promise generator.

kkirby avatar Apr 08 '15 21:04 kkirby