Work-around is:
name-to-upper = (person) -> person=^^person; person.name .= to-upper-case!
# or, in this case:
name-to-upper = (person) -> ^^person.name .= to-upper-case!
How would it handle default arguments?
(person=^^defaultV)
works: clone defaultV when person is not defined.
To add it to the grammar, would need to have the AST transform this:
% livescript--ast -e '(^^person=defaultV) -> person.name'
Block
Fun
Unary ^^
Assign =
Var person
Var defaultV
Block
Chain
Var person
Index .
Key name
into this:
Block
Fun
Assign =
Var person
Var defaultV
Block
Assign =
Var person
Unary ^^
Var person
Chain
Var person
Index .
Key name
which becomes the javascript:
(function(person){
person == null && (person = defaultV);
person = clone$(person);
return person.name;
});
Extended test:
defaultV = name: \Idol
billy = name: \Billy
name-to-upper = (^^person=defaultV) -> person.name .= to-upper-case!
name-to-upper billy #=> 'BILLY'
name-to-upper! #=> 'BILLY'
billy #=> 'Billy'
defaultV #=> 'Billy'