diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2019-10-16 08:39:11 -0700 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2019-10-16 08:39:11 -0700 |
commit | e35dadd463a6de59f361c0be665d25ab5cf166b3 (patch) | |
tree | 9d65f0819a4919fc3e7f2fa108df2f839c594a36 /lib.c | |
parent | 5d0eb90d21bf830fdfc91337b4b3975a64a406f7 (diff) | |
download | txr-e35dadd463a6de59f361c0be665d25ab5cf166b3.tar.gz txr-e35dadd463a6de59f361c0be665d25ab5cf166b3.tar.bz2 txr-e35dadd463a6de59f361c0be665d25ab5cf166b3.zip |
New function: copy-tree.
* eval.c (eval_init): Register copy-tree intrinsic.
* lib.c (copy_tree): New function.
* lib.h (copy_tree): Declared.
* txr.1: Documented.
Diffstat (limited to 'lib.c')
-rw-r--r-- | lib.c | 15 |
1 files changed, 15 insertions, 0 deletions
@@ -8175,6 +8175,21 @@ val copy_cons(val cell) } } +val copy_tree(val tree) +{ + if (atom(tree)) { + return tree; + } else { + val car = copy_tree(tree->c.car); + val cdr = copy_tree(tree->c.cdr); + val copy = make_obj(); + *copy = *tree; + copy->c.car = car; + copy->c.cdr = cdr; + return copy; + } +} + val copy_alist(val list) { list_collect_decl (out, ptail); |