Author: Maciej Fijalkowski <fij...@gmail.com> Branch: Changeset: r378:70de751b15e8 Date: 2013-07-09 11:56 +0200 http://bitbucket.org/pypy/stmgc/changeset/70de751b15e8/
Log: fix pair and use it in tree demos diff --git a/duhton/demo/trees.duh b/duhton/demo/trees.duh --- a/duhton/demo/trees.duh +++ b/duhton/demo/trees.duh @@ -4,8 +4,9 @@ ) (defun walk-tree (tree) - (if (== (len tree) 1) (get tree 0) - (+ (walk-tree (get tree 0)) (walk-tree (get tree 1))) + (if (pair? tree) + (+ (walk-tree (car tree)) (walk-tree (cdr tree))) + 1 ) ) diff --git a/duhton/demo/trees2.duh b/duhton/demo/trees2.duh --- a/duhton/demo/trees2.duh +++ b/duhton/demo/trees2.duh @@ -1,11 +1,13 @@ + (defun create-tree (n) - (if (== n 0) (list 1) (list (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) - (if (== (len tree) 1) (get tree 0) - (+ (walk-tree (get tree 0)) (walk-tree (get tree 1))) + (if (pair? tree) + (+ (walk-tree (car tree)) (walk-tree (cdr tree))) + 1 ) ) diff --git a/duhton/glob.c b/duhton/glob.c --- a/duhton/glob.c +++ b/duhton/glob.c @@ -590,12 +590,9 @@ 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 *obj; + _du_getargs1("pair?", cons, locals, &obj); + return DuInt_FromInt(DuCons_Check(obj)); } DuObject *du_assert(DuObject *cons, DuObject *locals) _______________________________________________ pypy-commit mailing list pypy-commit@python.org http://mail.python.org/mailman/listinfo/pypy-commit