adding in rest macros

This commit is contained in:
Paul R. Tagliamonte 2013-03-18 19:49:36 -04:00
parent a58c813dda
commit 83a9bdc87d
2 changed files with 16 additions and 0 deletions

View File

@ -103,3 +103,14 @@ def first_macro(tree):
return HyExpression([HySymbol('get'),
ret,
HyInteger(0)])
@macro("cdr")
@macro("rest")
def rest_macro(tree):
tree.pop(0) # "first"
ret = tree.pop(0) # the list
# assert tree is empty
return HyExpression([HySymbol('slice'),
ret,
HyInteger(1)])

View File

@ -183,3 +183,8 @@
(assert (= (slice [1 2 3 4 5] 1) [2 3 4 5]))
(assert (= (slice [1 2 3 4 5] 1 3) [2 3]))
(assert (= (slice [1 2 3 4 5]) [1 2 3 4 5])))
(defn test-rest []
"NATIVE: test rest"
(assert (= (rest [1 2 3 4 5]) [2 3 4 5])))