Created
December 26, 2009 18:31
-
-
Save atg/264006 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
foo bar | |
=> foo['bar'] | |
# assignment (no, this is impossible to handle in userspace without breaking/crippling lookup overloading) | |
... = ... | |
# methods (this is just syntactic sugar) | |
foo.bar | |
=> foo['isa']['bar'] | |
# Dereference using an expression instead of a string | |
foo [bar] | |
=> foo[bar] | |
# Arrays | |
# Associative arrays like in PHP. Order matters. This helps with handling named arguments | |
(1, 'foo', x: (7, 8, 9)) | |
=> [0 => 1, 1 => 'foo', :x => [7, 8, 9]] | |
# Function calls | |
foo(...) | |
=> foo(...) | |
# Blocks (meaningful indentation). The block is passed as a closure as the item in the arguments array | |
foo ... | |
... | |
=> foo(..., {...}) | |
# Blocks (braces). As above | |
foo ... { | |
... | |
} | |
=> foo(..., {...}) | |
# These two are preset by the runtime, but they're nothing special - code can reassign them/change them | |
@ the arguments of a block | |
^ the enclosing scope | |
# If a block called 'space' is defined in a scope, then that overloads the space operator (arguments to space are stored in @ as normal). | |
# For example: | |
s = | |
space = | |
^ [@0] = "hello" | |
s foo | |
# Arithmetic operators in descending order of precedence | |
** Exponentiation | |
* / Multiplication, Division | |
+ - Addition, Subtraction | |
# TODO: AND, OR, NOT, etc | |
: Named array items | |
, Separate array items | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment