Skip to content

Commit

Permalink
introduce implicit thunk arguments
Browse files Browse the repository at this point in the history
(#> #0) -> (function() { return arguments[0]; })
  • Loading branch information
jbr committed Nov 20, 2015
1 parent 06d25c3 commit b15370e
Show file tree
Hide file tree
Showing 29 changed files with 348 additions and 219 deletions.
31 changes: 24 additions & 7 deletions include/macros.sibilant
Expand Up @@ -124,9 +124,6 @@
(regex "\n" 'g) "\n// ")
null)))])))

(macro meta (body)
(eval (output-formatter (transpile body))))

(macro zero? (item) '(= @item 0))

(macro empty? (arr)
Expand Down Expand Up @@ -266,8 +263,27 @@
(macro until (condition ...block)
'(while (not @condition) ...@block))

(macro match? (regexp string)
'(send @string match @regexp))

(macro match-regex? (string regexp-string glim)
'(match? (regex @regexp-string @glim) @string))

(macro replace (string regexp-string replacement)
'(send @string replace
(regex @regexp-string)
@replacement))

(macro replace-all (string regexp-string replacement)
'(replace @string @regexp-string 'g))

(macro thunk (...body)
'(lambda @{ node this args [] } ...@body))
'(lambda @{ node this args [] }
...@(map-node body
(#(node)
(if (node? node 'arg-placeholder)
'(argument @(replace node.token "^#" ""))
node)))))
(alias-macro thunk #>)

(macro keys (obj)
Expand All @@ -292,6 +308,9 @@
(macro arguments ()
["(Array.prototype.slice.apply(arguments))"])

(macro argument (n)
'(get arguments @n))

(macro scoped (...body)
'(call (lambda @{node this args []} ...@body)))

Expand All @@ -306,9 +325,6 @@
]
@obj))

(macro match? (regexp string)
'(send @string match @regexp))

(macro switch (obj ...cases)
["(function() {"
(indent ["switch(" (transpile obj) ") {"
Expand Down Expand Up @@ -377,6 +393,7 @@
(macro includes? (list item)
'(!= -1 (send @list index-of @item)))


(macro excludes? (list item)
'(= -1 (send @list index-of @item)))

Expand Down

0 comments on commit b15370e

Please sign in to comment.