Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Special token for marking a function as a promise generator #127

Open
ckknight opened this issue Jul 15, 2013 · 9 comments
Open

Special token for marking a function as a promise generator #127

ckknight opened this issue Jul 15, 2013 · 9 comments

Comments

@ckknight
Copy link
Owner

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?

@unc0
Copy link
Contributor

unc0 commented Jul 16, 2013

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

Two | metaphors fulfill/reject, my 2 cents.

@ckknight
Copy link
Owner Author

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.

@unc0
Copy link
Contributor

unc0 commented Jul 16, 2013

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

@andreyvit
Copy link

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

@ckknight
Copy link
Owner Author

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
Copy link
Owner Author

This depends on #131 now.

@goldfeld
Copy link

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

@ckknight
Copy link
Owner Author

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?

@kkirby
Copy link

kkirby commented Apr 8, 2015

In my community repo, I made this:

#**
    yield stuff()

Be a promise generator.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants