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

Confusing use of val and ref in Object Literals section on lambdas #129

Open
snej opened this issue Jun 8, 2016 · 1 comment
Open

Confusing use of val and ref in Object Literals section on lambdas #129

snej opened this issue Jun 8, 2016 · 1 comment
Labels
good first issue Good for newcomers help wanted Extra attention is needed

Comments

@snej
Copy link

snej commented Jun 8, 2016

A lambda object is always returned as val if it does not close over any other variables. If it does capture values from the lexical scope then it is returned as a ref. The reference capability in the type declaration can be supplied by adding it before the closing curly bracket. If it is not provided it defaults to ref. The following is an example of a val lambda object:

I found this paragraph very confusing, and even after re-reading it I couldn't figure out why val and ref would be mutually incompatible. The answer came later in the Capabilities chapter; I had been thinking of val acting more like box (or like const in C++), so I didn't understand why you couldn't pass a ref reference to a val parameter.

I'd suggest you simplify this example by declaring the reduce function's lambda parameter as box, and then just glossing over that by saying it allows either a val or a ref to be passed to it, and linking ahead to the Capabilities chapter.

@rhagenson rhagenson added the good first issue Good for newcomers label Dec 16, 2020
@rhagenson
Copy link
Member

I am willing to help on this issue, but it seems clarification is available already, just not at the point where clarification is expected. Never a fan of "glossing over" intentionally, but there is some complexity around box which we may be able to avoid so as to not distract from the intention here: learning about object literals/lambdas.

@SeanTAllen SeanTAllen added the help wanted Extra attention is needed label Feb 8, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

3 participants