Skip to content

Instantly share code, notes, and snippets.

@fogus
Created July 23, 2009 13:29
Show Gist options
  • Save fogus/152916 to your computer and use it in GitHub Desktop.
Save fogus/152916 to your computer and use it in GitHub Desktop.
/*
{} // map literal syntax
() // tuple literal syntax
[] // list literal syntax
foo // a symbol
"foo" // a string
foo => bar // a pair
:. // a block (similar to progn)
= // bind
~ // merge
<~ // merge bind
? // property query
foo(42) // a symbol followed by a tuple is a function call
foo.fun() // call a method
$ // similar to `this` or `self`
*/
def foo = {} // start with an empty map
foo.n = 42 // put a property
foo?n // does foo have property n?
foo.n // lookup property n
def bar = {() => [print("Hello Cleveland")]}
bar() // prints Hello Cleveland
bar.() // returns the list `[print("Hello Cleveland")]`
bar?() // does this function accept zero args?
bar.().first() // returns the symbol `print`
def baz = {() => [print($.n)]}
baz() // returns special object `notset`
baz.n = 138 // sets property `n`
baz() // prints 138
def qux = {()=> baz.()} // grab the body of baz's empty arity function
qux() // returns special object `notset` (no property `n`)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment