Adding first' / car'

This commit is contained in:
Paul R. Tagliamonte 2013-03-18 16:11:29 -04:00
parent 4cb4e7384e
commit 8f6c77831b
2 changed files with 18 additions and 0 deletions

View File

@ -21,6 +21,7 @@
from hy.macros import macro from hy.macros import macro
from hy.models.expression import HyExpression from hy.models.expression import HyExpression
from hy.models.integer import HyInteger
from hy.models.symbol import HySymbol from hy.models.symbol import HySymbol
from hy.models.list import HyList from hy.models.list import HyList
@ -91,3 +92,14 @@ def threading_macro(tree):
node.insert(1, ret) node.insert(1, ret)
ret = node ret = node
return ret return ret
@macro("car")
@macro("first")
def first_macro(tree):
tree.pop(0) # "first"
ret = tree.pop(0) # the list
# assert tree is empty
return HyExpression([HySymbol('get'),
ret,
HyInteger(0)])

View File

@ -170,3 +170,9 @@
(def ret 0) (def ret 0)
(for [y (gen)] (def ret (+ ret y))) (for [y (gen)] (def ret (+ ret y)))
(assert (= ret 10))) (assert (= ret 10)))
(defn test-first []
"NATIVE: test firsty things"
(assert (= (first [1 2 3 4 5]) 1))
(assert (= (car [1 2 3 4 5]) 1)))