You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
The text was updated successfully, but these errors were encountered:
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.
I found this paragraph very confusing, and even after re-reading it I couldn't figure out why
val
andref
would be mutually incompatible. The answer came later in the Capabilities chapter; I had been thinking ofval
acting more likebox
(or likeconst
in C++), so I didn't understand why you couldn't pass aref
reference to aval
parameter.I'd suggest you simplify this example by declaring the
reduce
function's lambda parameter asbox
, and then just glossing over that by saying it allows either aval
or aref
to be passed to it, and linking ahead to the Capabilities chapter.The text was updated successfully, but these errors were encountered: