Open TwitchBronBron opened 2 years ago
would you offer return short hand "return value by default" that other languages have?
e.g.
mc.collections.filter(items, (i) => i.rating > 3.5)
Yeah, I think so!
It really hurts to see the JS syntax though.
General approach makes sense though we shouldn't have all the locals go in the closure object if possible.
Naming of things could be better :D
@philippe-elsass-deltatre I assume you're talking about the curly braces for the arrow function? Since there's no opening keyword, I didn't really see any way around it. What would you suggest?
Also, what would you name the things? All this is in the air, so we should work out those things now.
@philippe-elsass-deltatre
we shouldn't have all the locals go in the closure object if possible.
This could definitely be a compiler optimization, but it felt easier to just rewrite everything for now. But I agree, properties not used in closures don't need to be on the local
collections.
Actually the naming part is fine, but there is some ambiguity around "Closure" (a local function has access to local vars in parent scopes) VS "ArrowFunction" (a closure where this
is the parent scope's)
And about the as ArrowFunction
- I'm envisioning cases where we want to accept both normal functions and arrow ones; granted it would be a case where you'd have to poke at the object to check whether it's a function or an arrow function.
Is that a big problem to consider introducing a keyword? Maybe we could use the term lambda
to describe these functions - it's quite common in other languages.
Definitely not a problem to consider a keyword. I like how the arrow functions are concise, but it does feel like a deviation from the rest of the language. Lambda doesn't feel quite right. What about 'closure' instead?
checkEmail = closure(domain)
inputValue = m.emailAddressTextEditBox.text
if inputValue.endsWith(domain) then
response ="valid"
else
response = "invalid"
end if
end closure
I actually think we should lean into lambdas, as we can't really do closures - it will never be a proper implementation; but hte limitatinos we've described here, are actually the design of lambdas, as pointed out by @philippe-elsass-deltatre : https://docs.microsoft.com/en-us/dotnet/visual-basic/programming-guide/language-features/procedures/lambda-expressions
Just to be clear, the vb lambda design DOES have access to its containing scope, as outlined here: https://docs.microsoft.com/en-us/dotnet/visual-basic/programming-guide/language-features/procedures/lambda-expressions#context
BrighterScript should support closures.
Here's a quick example:
would transpile to:
Considerations:
ArrowFunction
interface type which can be used as function parameters and other types.ArrowFunction
transpiles to: