From 8f6c77831b9403a58542e7fb3afe5b6aee3755c3 Mon Sep 17 00:00:00 2001 From: "Paul R. Tagliamonte" Date: Mon, 18 Mar 2013 16:11:29 -0400 Subject: [PATCH] Adding `first' / `car' --- hy/core/bootstrap.py | 12 ++++++++++++ tests/native_tests/language.hy | 6 ++++++ 2 files changed, 18 insertions(+) diff --git a/hy/core/bootstrap.py b/hy/core/bootstrap.py index dc38de0..45f5ae2 100644 --- a/hy/core/bootstrap.py +++ b/hy/core/bootstrap.py @@ -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)]) diff --git a/tests/native_tests/language.hy b/tests/native_tests/language.hy index b853337..b532353 100644 --- a/tests/native_tests/language.hy +++ b/tests/native_tests/language.hy @@ -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)))