Skip to content

Instantly share code, notes, and snippets.

@josher19
Created September 4, 2012 05:39
Show Gist options
  • Save josher19/3617147 to your computer and use it in GitHub Desktop.
Save josher19/3617147 to your computer and use it in GitHub Desktop.

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'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment