aboutsummaryrefslogtreecommitdiff
path: root/src/interp/sys-utility.boot
diff options
context:
space:
mode:
Diffstat (limited to 'src/interp/sys-utility.boot')
-rw-r--r--src/interp/sys-utility.boot22
1 files changed, 22 insertions, 0 deletions
diff --git a/src/interp/sys-utility.boot b/src/interp/sys-utility.boot
index d047296e..6895926e 100644
--- a/src/interp/sys-utility.boot
+++ b/src/interp/sys-utility.boot
@@ -391,3 +391,25 @@ stringAssoc(s,l) ==
symbolLassoc(s,l) ==
p := symbolAssoc(s,l) => rest p
nil
+
+
+--% substitute
+
+substitute(new,old,tree) ==
+ sameObject?(old,tree) => new
+ cons? tree =>
+ h := substitute(new,old,first tree)
+ t := substitute(new,old,rest tree)
+ sameObject?(h,first tree) and sameObject?(t,rest tree) => tree
+ [h,:t]
+ tree
+
+substitute!(new,old,tree) ==
+ sameObject?(old,tree) => new
+ cons? tree =>
+ h := substitute!(new,old,first tree)
+ t := substitute!(new,old,rest tree)
+ tree.first := h
+ tree.rest := t
+ tree
+