Adding first' /
car'
This commit is contained in:
parent
4cb4e7384e
commit
8f6c77831b
@ -21,6 +21,7 @@
|
||||
|
||||
from hy.macros import macro
|
||||
from hy.models.expression import HyExpression
|
||||
from hy.models.integer import HyInteger
|
||||
from hy.models.symbol import HySymbol
|
||||
from hy.models.list import HyList
|
||||
|
||||
@ -91,3 +92,14 @@ def threading_macro(tree):
|
||||
node.insert(1, ret)
|
||||
ret = node
|
||||
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)])
|
||||
|
@ -170,3 +170,9 @@
|
||||
(def ret 0)
|
||||
(for [y (gen)] (def ret (+ ret y)))
|
||||
(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)))
|
||||
|
Loading…
x
Reference in New Issue
Block a user