Browse Source

Mostly finished about define-operation

Samuel W. Flint 7 years ago
parent
commit
9f35f7b94a
1 changed files with 77 additions and 20 deletions
  1. 77 20
      larcs.org

+ 77 - 20
larcs.org

@@ -943,12 +943,20 @@ To aid in the design and implementation of various sub-systems, from simplificat
                        (cons :trigonometrics trigonometrics)))))
 #+END_SRC
 
-** WORKING Define Expression Manipulator
+** WORKING Define Expression Manipulator [2/3]
 :PROPERTIES:
 :CREATED:  <2016-04-30 Sat 22:57>
 :ID:       63909972-428d-47f3-9dc3-3e1fb213aa70
 :END:
 
+This is an extremely complicated macro, and as such is quite long.  However, to explain it adequately is not hard, especially when it is broken into sections.
+
+In the first part, we define ~*manipulator-map*~, which store the names of the manipulators and the short-names.
+
+Following that, we define the macro ~define-operation~ which takes three arguments: a name, function arity, and a short name (operation name).  It verifies the types of the passed arguments, and then begins the ~let*~ block, binding as seen in [[id:b8c75ae9-137f-42c4-bb54-ee103ada11f1][Variable Bindings]].
+
+To expand this macro, it begins a ~progn~, which starts by pushing the a cons cell in the form of ~(short . long)~ onto the manipulator mapping.  From there, a variable is defined with the name bound to ~rules-name~, an applicability predicate is defined, a manipulator finder is also defined, as is a function to properly call the manipulator on a given set of arguments.  Following that, it defines the macro used to define manipulators for the specified operation, as explained in [[id:9aa262c7-c536-48e8-a0e7-4504b330bb60][The Inner Macro]].
+
 #+Caption: Define Expression Manipulator
 #+Name: am-define-expression-manipulator
 #+BEGIN_SRC lisp
@@ -958,19 +966,9 @@ To aid in the design and implementation of various sub-systems, from simplificat
     (check-type name symbol)
     (check-type arity (integer 1 26))
     (check-type short symbol)
-    (let* ((args (gen-args-list arity))
-           (expression-types (map 'list #'(lambda (x)
-                                            (symbolicate x '-type)) args))
-           (rules-name (symbolicate '*manipulators- name '*))
-           (base-manipulator-name (symbolicate name '-manipulator-))
-           (manipulator-define-name (symbolicate 'define- name '-manipulator))
-           (is-applicable-name (symbolicate name '-is-applicable-p))
-           (get-operations-name (symbolicate 'get- name '-manipulators))
-           (type-check-list (let ((i 0))
-                              (loop for arg in args
-                                 collect (prog1
-                                             `(classified-as-p ,arg (nth ,i types))
-                                           (incf i))))))
+    (let* (
+           <<am-variable-bindings>>
+           )
       `(progn
          (push '(,short . ,name) *manipulator-map*)
          (defvar ,rules-name '())
@@ -987,14 +985,73 @@ To aid in the design and implementation of various sub-systems, from simplificat
          (defun ,name (,@args)
            (funcall (first (,get-operations-name ,@args))
                     ,@args))
-         (defmacro ,manipulator-define-name ((,@expression-types) &body body)
-           (let ((manipulator-name (symbolicate ',base-manipulator-name ,@expression-types)))
-             `(progn
-                (setf ,',rules-name (append ,',rules-name '(((,,@expression-types) . ,manipulator-name))))
-                (defun ,manipulator-name ,',args
-                  ,@body)))))))
+         <<am-manipulation-definition-macro>>
+         )))
+#+END_SRC
+
+*** DONE Variable Bindings
+CLOSED: [2016-09-23 Fri 18:12]
+:PROPERTIES:
+:CREATED:  <2016-09-23 Fri 17:13>
+:ID:       b8c75ae9-137f-42c4-bb54-ee103ada11f1
+:END:
+
+To accomplish the job of defining a group of manipulators, for the macro expansion to succeed, there must be a few variables bound.  These include:
+
+ - Arguments, types and others:
+   - args :: This is a list of arguments used for a manipulation function's lambda list.
+   - expression-types :: This is a list used to keep the various types for finding the correct manipulator.
+   - type-check-list :: This is a list of expressions used to check whether or not a given argument is of a type.  This is specifically used in determining applicability of a manipulator to the given arguments.
+ - Names of things
+   - rules-name :: This is the name of the rules container, where the types-to-manipulator mapping is kept.
+   - base-manipulator-name :: This is the base name of the manipulator, used in the definition of a specific manipulator for a given group of types.
+   - manipulator-define-name :: This is the name of the macro used to define manipulators.
+   - is-applicable-name :: The name of the function used to check whether or not a manipulator is applicable.
+   - get-operations-name :: The name of the function used to retrieve possible manipulators for a given set of arguments.
+
+#+Caption: Variable Bindings
+#+Name: am-variable-bindings
+#+BEGIN_SRC lisp
+  (args (gen-args-list arity))
+  (expression-types (map 'list #'(lambda (x)
+                                   (symbolicate x '-type)) args))
+  (rules-name (symbolicate '*manipulators- name '*))
+  (base-manipulator-name (symbolicate name '-manipulator-))
+  (manipulator-define-name (symbolicate 'define- name '-manipulator))
+  (is-applicable-name (symbolicate name '-is-applicable-p))
+  (get-operations-name (symbolicate 'get- name '-manipulators))
+  (type-check-list (let ((i 0))
+                     (loop for arg in args
+                        collect (prog1
+                                    `(classified-as-p ,arg (nth ,i types))
+                                  (incf i)))))
 #+END_SRC
 
+*** DONE The Inner Macro
+CLOSED: [2016-09-23 Fri 18:53]
+:PROPERTIES:
+:CREATED:  <2016-09-23 Fri 17:14>
+:ID:       9aa262c7-c536-48e8-a0e7-4504b330bb60
+:END:
+
+This defines a macro, named ~manipulator-define-name~, taking a list of expression types and a body.  It generates a name for the manipulator and then adds a mapping for the manipulator to the manipulator map, defining a function with the manipulator name, the pre-defined arguments list and the given body.
+
+#+Caption: Manipulation Definition Macro (Inner)
+#+Name: am-manipulation-definition-macro
+#+BEGIN_SRC lisp 
+  (defmacro ,manipulator-define-name ((,@expression-types) &body body)
+    (let ((manipulator-name (symbolicate ',base-manipulator-name ,@expression-types)))
+      `(progn
+         (setf ,',rules-name (append ,',rules-name '(((,,@expression-types) . ,manipulator-name))))
+         (defun ,manipulator-name ,',args
+           ,@body))))
+#+END_SRC
+
+*** TODO Manipulation Example
+:PROPERTIES:
+:CREATED:  <2016-09-23 Fri 17:13>
+:END:
+
 #+Caption: Manipulation Example
 #+Name: am-ex-manip-example
 #+BEGIN_SRC lisp :results output raw :exports results :cache yes