Robert Smith avatar Robert Smith committed f94737d

Add FUNCTION-ARITY, correct dox for UNARY-FUNCTION-P

Comments (0)

Files changed (1)

symbolic-function.lisp

     (make-symbolic-function parameters
                             (list f expression))))
 
+(defun function-arity (sf)
+  "What is the arity of the symbolic function SF?"
+  (length (symbolic-function.parameters sf)))
+
 (defun bound-variable-p (var sf)
   "Is the variable VAR bound in the symbolic function SF?"
   (and (member var (symbolic-function.parameters sf) :test 'eq)
 
 (defun nullary-function-p (sf)
   "Is the symbolic function SF nullary?"
-  (null (symbolic-function.parameters sf)))
+  (zerop (function-arity sf)))
 
 (defun unary-function-p (sf)
-  "Is the symbolic function SF nullary?"
-  (= 1 (length (symbolic-function.parameters sf))))
+  "Is the symbolic function SF unary?"
+  (= 1 (function-arity sf)))
+
+(defun binary-function-p (sf)
+  "Is the symbolic function SF binary?"
+  (= 2 (function-arity sf)))
+
 
 ;;; XXX: This should probably make a copy/new function.
 (defun alpha-convert (sf new-var &optional old-var)
          (t (error "Don't know how to diff ~S" expr))))))
 
 (defun differentiate (sf)
-  (assert (= 1 (length (symbolic-function.parameters sf)))
+  (assert (unary-function-p sf)
           (sf)
           "Symbolic function must have exactly one parameter.")
   (let ((var (first (symbolic-function.parameters sf)))
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.