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

error referencing function defined using lazy specifier #2077

Open
jvasileff opened this issue Feb 28, 2015 · 9 comments
Open

error referencing function defined using lazy specifier #2077

jvasileff opened this issue Feb 28, 2015 · 9 comments
Labels
Milestone

Comments

@jvasileff
Copy link
Member

I'm not sure it ever makes sense to have a variable parameter on a function defined using the lazy specifier, but doing so can result in a backend error:

    Boolean foo<Element>(variable Element x) => x exists;

    print (foo<Anything>(null)); // ok
    print (foo<Anything>("")); // ok
    value fooAnything = foo<Anything>; // Cannot find symbol: class Element
@quintesse quintesse added the BUG label Feb 28, 2015
@quintesse quintesse modified the milestones: 1.2, 1.3 Feb 28, 2015
@quintesse
Copy link
Member

Indeed, doesn't really seem to make much sense. But on the other had I also don't see a reason to forbid it in the spec for example, so we should probably just fix it.
Not really high prio so assigning to 1.3

@lucaswerkmeister
Copy link
Member

Well, it’s definitely possible to write legal code that actually varies the parameter:

Boolean complicatedFalse<Element>(variable Element? x) => ((x = null) of Element?) exists;

With let expressions you could also get the old value, then assign to it, then use both the old and the new value. Probably still doesn’t make sense, but I don’t think it should be illegal either.

@jvasileff
Copy link
Member Author

Oh, nice @lucaswerkmeister! I forgot about that. Now I can finally write a memoizer without ugly braces!

Result memoize<Result>
        (Result() f, variable Result? memo=null)()
        given Result satisfies Object
    =>  memo = memo else f();

@lucaswerkmeister
Copy link
Member

Wow, that’s fancy.

@quintesse
Copy link
Member

I might be completely wrong but I doubt that will work, the memo wouldn't be stored between calls to the function AFAIK.

@lucaswerkmeister
Copy link
Member

@quintesse seems to work as intended. gist

@quintesse
Copy link
Member

Color me surprised :)

@gavinking
Copy link
Member

Haha, cool :)

Sent from my iPhone

On 24 Mar 2015, at 9:17 pm, John Vasileff notifications@github.com wrote:

Oh, nice @lucaswerkmeister! I forgot about that. Now I can finally write a memoizer without ugly braces!

Result memoize
(Result() f, variable Result? memo=null)()
given Result satisfies Object
=> memo = memo else f();

Reply to this email directly or view it on GitHub.

@quintesse
Copy link
Member

I hadn't really noticed the extra pair of parenthesis, nice :)

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

No branches or pull requests

4 participants