[pypy-commit] stmgc default: implement pair?
fijal
noreply at buildbot.pypy.org
Tue Jul 9 11:33:53 CEST 2013
Author: Maciej Fijalkowski <fijall at gmail.com>
Branch:
Changeset: r377:ffe6884d33a4
Date: 2013-07-09 11:33 +0200
http://bitbucket.org/pypy/stmgc/changeset/ffe6884d33a4/
Log: implement pair?
diff --git a/duhton/demo/trees.duh b/duhton/demo/trees.duh
--- a/duhton/demo/trees.duh
+++ b/duhton/demo/trees.duh
@@ -1,6 +1,6 @@
(defun create-tree (n)
- (if (== n 0) (cons 1) (cons (create-tree (- n 1)) (create-tree (- n 1))))
+ (if (== n 0) 1 (cons (create-tree (- n 1)) (create-tree (- n 1))))
)
(defun walk-tree (tree)
diff --git a/duhton/glob.c b/duhton/glob.c
--- a/duhton/glob.c
+++ b/duhton/glob.c
@@ -588,6 +588,16 @@
return DuInt_FromInt(res != NULL);
}
+DuObject *du_pair(DuObject *cons, DuObject *locals)
+{
+ _du_read1(cons);
+ if (cons == Du_None || _DuCons_NEXT(cons) != Du_None)
+ Du_FatalError("pair?: expected one argument");
+
+ DuObject *ob = _DuCons_CAR(cons);
+ return DuInt_FromInt(DuCons_Check(ob));
+}
+
DuObject *du_assert(DuObject *cons, DuObject *locals)
{
DuObject *obj;
@@ -640,6 +650,7 @@
DuFrame_SetBuiltinMacro(Du_Globals, "transaction", du_transaction);
DuFrame_SetBuiltinMacro(Du_Globals, "sleepms", du_sleepms);
DuFrame_SetBuiltinMacro(Du_Globals, "defined?", du_defined);
+ DuFrame_SetBuiltinMacro(Du_Globals, "pair?", du_pair);
DuFrame_SetBuiltinMacro(Du_Globals, "assert", du_assert);
DuFrame_SetSymbolStr(Du_Globals, "None", Du_None);
}
diff --git a/duhton/test/test_cons.py b/duhton/test/test_cons.py
--- a/duhton/test/test_cons.py
+++ b/duhton/test/test_cons.py
@@ -7,6 +7,10 @@
assert run("(print (quote (1 2 3)))") == "( 1 2 3 )\n"
assert run("(print (cons 1 2))") == "( 1 . 2 )\n"
+def test_pair():
+ assert run("(print (pair? 1))") == "0\n"
+ assert run("(print (pair? (cons 1 2)))") == "1\n"
+
def test_car_cdr():
assert run("(print (car (quote (2 3))))") == "2\n"
assert run("(print (cdr (quote (2 3))))") == "( 3 )\n"
More information about the pypy-commit
mailing list