浏览代码

Add substitution for addition

Samuel W. Flint 5 年之前
父节点
当前提交
f88d673a45
共有 1 个文件被更改,包括 8 次插入0 次删除
  1. 8 0
      larcs.org

+ 8 - 0
larcs.org

@@ -372,6 +372,14 @@ Compound types are the majority of expressions.  An atom is well and good, but o
   (defmethod copy-expression ((expression <addition>))
     (make-instance '<addition>
                    :terms (mapcar #'copy-expression (slot-value expression 'terms))))
+
+  (defmethod substitute-expression (replace replacement (expression <addition>))
+    (if (eqal expression replace)
+        replacement
+        (make-instance '<addition>
+                       :terms (mapcar #'(lambda (exp)
+                                          (substitute-expression replace replacement exp))
+                                      (slot-value expression 'terms)))))
 #+END_SRC
 
 *** WORKING Subtractions