Skip to content

Commit

Permalink
Even clearer docs
Browse files Browse the repository at this point in the history
  • Loading branch information
tcr committed Mar 25, 2012
1 parent 935be70 commit 4242917
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 31 deletions.
43 changes: 22 additions & 21 deletions README.md
Expand Up @@ -11,37 +11,38 @@

## Syntax

Syrup is whitespace-significant. Function calls are made as so:
Syrup is whitespace-significant. Function calls are made by a colon
following an atom. All subsequent arguments on a line are passed to the
function until a newline of the same indentation, the end of a parenthetical,
or a period `.`

print: "Cool language x" 5000
print: "Cool language x" 5000 # Parses as (print "Cool language x" 5000)
print: # Equivalent
"Cool language x"
5000
print: square: 5. square: 6. # "25", "36"

Where a colon following an atom indicates all subsequent arguments
are part of the list. This parse tree is equivalent to (in Clojure):

(print "Cool language x" 5000)

Parentheses are for disambiguation, and are insignificant:
Parentheses are for disambiguation, and are insignificant.
Commas are allowed, but not required.

calc-fib: (n - 1) b (a + b)
calc-fib: n - 1, b, a + b

Commas are allowed, but not required in lists of arguments/literals.
Array/list syntax is like JavaScript array literals:
Vector (array) syntax is like JavaScript's array literals. Vectors
are not executed as functions.

[5 6 7 8] # equivalent to list: 5 6 7 8

Because arrays evaluate to lists, they are not equivalent to lists
in Lisp (which can be evaluated).

Quoting uses \`.

print: `apples # prints "apples"
print: `apples # prints "apples"

Infix notation is supported for arithmetic operations
and for the assign operator:

5 + 6 # these two lines are
(+: 5 6) # equivalent
test = fn: [] print: 'hi' # declares the function 'test'
5 + 6 # these two lines are
(+: 5 6) # equivalent
test = fn: [] print: 'hi' # declares the function 'test'

Macros are supported:

Expand All @@ -55,10 +56,10 @@ as keys (as in python). Any arguments after the first passed to a string
function have their properties copied to the new object literal. Finally,
curly-braces combine all listed objects into one.

"a": 1 # JSON: {"a": 1}
("some" + "key"): "val" # JSON: {"somekey": "val"}
obj = "b": 2 "c": 3 # parses to ("b" 2 ("c" 3)) and JSON: {"b": 2, "c": 3}
obj2 = {"a": 1, obj} # parses to (combine ("a", 1) obj) and JSON: {"a": 1, "b": 2, "c": 3}
"a": 1 # JSON: {"a": 1}
("some" + "key"): "val" # JSON: {"somekey": "val"}
obj = "b": 2 "c": 3 # parses to ("b" 2 ("c" 3)) and JSON: {"b": 2, "c": 3}
obj2 = {"a": 1, obj} # parses to (combine ("a", 1) obj) and JSON: {"a": 1, "b": 2, "c": 3}

## TODO

Expand Down
11 changes: 1 addition & 10 deletions anonymous.syrup
@@ -1,13 +1,4 @@
test = fn: []
(fn: [f] f: [`b `c]):
fn: [x] concat: `a x
print: test.

print: {
"apple": 5,
"bear": 6,
"candy": 7
}

c = "cat": 7
map: print {"apple": 5, "bear": 6, c}
print: test.

0 comments on commit 4242917

Please sign in to comment.