Browse Source

Fix eqal, as well as name of substitute, now substitute-expression

Samuel W. Flint 5 years ago
parent
commit
cb3f1bdda7
1 changed files with 15 additions and 10 deletions
  1. 15 10
      larcs.org

+ 15 - 10
larcs.org

@@ -251,7 +251,7 @@ This is where the common functions and constants are assembled into their own pa
 
 All expressions are built from various ~<expression>~ objects.  These objects are specialized to contain only certain, specific information, relevant to a particular expression.  The most basic expressions (besides expression itself) are ~<atomic>~ (holding things like numbers or variables) and ~<compound>~ (holding things like multiplicatinos, divisions, exponents, trigonometric expressions, arithmetic expressions, /etc./).  All subtypes of ~<expression>~ must know if they are atomic, so we define a generic for this, they must also tell if they are ~eqal~ (a form of equality), and be able to perform substitution, evaluation, and simplification, however, the latter three are implemented elsewhere.  The organization of the various types may be found in Figure~[[fig:expression-types]].
 
-Note, by default, ~eqal~ will check to see if it canswitch the order of the arguments, and if so, will use that method.  Otherwise, it will warn that there's no defined method for the combination, and return ~nil~.
+Note, by default, ~eqal~ will handle ~type-error~ by trying to switch the order of the arguments.  If this fails, it will warn that an applicable method for the given types, and return ~nil~.
 
 #+Caption: Basic Expressions Types
 #+Name: type-basic
@@ -261,16 +261,21 @@ Note, by default, ~eqal~ will check to see if it canswitch the order of the argu
   (defgeneric atomicp (expression))
 
   (defgeneric eqal (expression-a expression-b))
+
   (defmethod eqal ((expression-a <expression>) (expression-b <expression>))
-    (let ((other-methods (compute-applicable-methods #'eqal
-                                                     (list expression-b expression-a))))
-      (if (> (length other-methods) 1)
-          (eqal expression-b expression-a)
-          (warn "No definition of `eqal' for types `~a' and `~a'."
-                (type-of expression-a)
-                (type-of expression-b)))))
-
-  (defgeneric substitute (expression with in))
+    (if (> (length (compute-applicable-methods #'eqal (list expression-b expression-a))) 2)
+        (eqal expression-b expression-a)
+        (warn "No definition of `eqal' for types `~a' and `~a'."
+              (type-of expression-a)
+              (type-of expression-b))))
+
+  (defmethod eqal :around ((expression-a <expression>) (expression-b <expression>))
+    (handler-case (call-next-method)
+      (type-error (err)
+        (declare (ignore err))
+        (eqal expression-b expression-a))))
+
+  (defgeneric substitute-expression (expression with in))
 
   (defgeneric evaluate (expression &key substitutions-list resolve-constants-light-p resolve-constants-hard-p))