Adding first' /
car'
This commit is contained in:
parent
4cb4e7384e
commit
8f6c77831b
@ -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)])
|
||||||
|
@ -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)))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user