|
393 | 393 |
|
394 | 394 | (defun reg-symfn-call (function space meta-form)
|
395 | 395 | "Add a reference to a call to a symbolic function to a closure metadata object."
|
396 |
| - ;; (print (list :ff function meta-form)) |
397 |
| - ;; (print :ff) |
398 | 396 | (when (and meta-form function (listp function))
|
399 | 397 | (if (eql 'sub-lex (first function))
|
400 | 398 | (reg-symfn-call (second function) space meta-form)
|
|
1007 | 1005 | (setf (symbol-function 'parse-apl-number-string) #'nparser)
|
1008 | 1006 | #'nparser)))
|
1009 | 1007 |
|
1010 |
| -;; (defun parse-apl-number-string (number-string &optional component-of) |
1011 |
| -;; "Parse an APL numeric string into a Lisp value, handling high minus signs, J-notation for complex numbers and R-notation for rational numbers." |
1012 |
| -;; (ignore-errors ;; if number parsing fails, just return nil |
1013 |
| -;; (let ((nstring (string-upcase (regex-replace-all "[_]" number-string "")))) |
1014 |
| -;; (if (and (not (eql 'complex component-of)) |
1015 |
| -;; (position #\J nstring :test #'char=)) |
1016 |
| -;; (let ((halves (cl-ppcre:split #\J nstring))) |
1017 |
| -;; (when (and (= 2 (length halves)) |
1018 |
| -;; (< 0 (length (first halves))) |
1019 |
| -;; (< 0 (length (second halves)))) |
1020 |
| -;; (complex (parse-apl-number-string (first halves) 'complex) |
1021 |
| -;; (parse-apl-number-string (second halves) 'complex)))) |
1022 |
| -;; (if (position #\E nstring :test #'char=) |
1023 |
| -;; (let ((exp-float (parse-number:parse-number (regex-replace-all "[¯]" nstring "-") |
1024 |
| -;; :float-format 'double-float))) |
1025 |
| -;; (if (< double-float-epsilon (nth-value 1 (floor exp-float))) |
1026 |
| -;; exp-float (let ((halves (mapcar #'parse-apl-number-string (cl-ppcre:split #\E nstring)))) |
1027 |
| -;; (floor (* (first halves) (expt 10 (second halves))))))) |
1028 |
| -;; (if (and (not (eql 'rational component-of)) |
1029 |
| -;; (position #\R nstring :test #'char=)) |
1030 |
| -;; (let ((halves (cl-ppcre:split #\R nstring))) |
1031 |
| -;; (/ (parse-apl-number-string (first halves) 'rational) |
1032 |
| -;; (parse-apl-number-string (second halves) 'rational))) |
1033 |
| -;; ;; the macron character is converted to the minus sign |
1034 |
| -;; (parse-number:parse-number (regex-replace-all "[¯]" nstring "-") |
1035 |
| -;; :float-format 'double-float))))))) |
1036 |
| - |
1037 | 1008 | (defun print-apl-number-string (number &optional segments precision decimals realpart-multisegment)
|
1038 | 1009 | "Format a number as appropriate for APL, using high minus signs and J-notation for complex numbers, optionally at a given precision and post-decimal length for floats."
|
1039 | 1010 | (cond ((complexp number)
|
|
1198 | 1169 | :functions-scalar-monadic))))
|
1199 | 1170 | (arguments (loop :for arg :in arguments :collect (if (or (not (symbolp arg)))
|
1200 | 1171 | arg `(vrender ,arg :may-be-deferred t)))))
|
1201 |
| - ;; (print (list :aa arguments)) |
1202 | 1172 | (or (when (and (listp function)
|
1203 | 1173 | (eql 'function (first function))
|
1204 | 1174 | (eql 'change-namespace (second function)))
|
1205 | 1175 | `(identity t))
|
1206 | 1176 | (progn (when (and (listp function) (eql 'nspath (first function)))
|
1207 | 1177 | (let* ((ns-sym (intern "*NS-POINT*" (package-name (symbol-package (second function)))))
|
1208 | 1178 | (namespace (if (boundp ns-sym) (symbol-value ns-sym))))
|
1209 |
| - (when namespace (setq function |
| 1179 | + (when namespace (setf function |
1210 | 1180 | (cons 'nspath (append (if (listp namespace) namespace
|
1211 | 1181 | (list namespace))
|
1212 | 1182 | (list (intern (string (second function))
|
|
1216 | 1186 | (apply ,@(when is-scalar (list '#'apply-scalar))
|
1217 | 1187 | ,function ,arg-list))))))
|
1218 | 1188 |
|
1219 |
| -#| |
1220 |
| -This is a minimalistic implementation of (a-call) that doesn't perform any function composition. |
1221 |
| -It remains here as a standard against which to compare methods for composing APL functions. |
1222 |
| -
|
1223 |
| -(defmacro a-call (function &rest arguments) |
1224 |
| - `(,(if (and (listp function) |
1225 |
| - (eql 'scalar-function (first function))) |
1226 |
| - 'apply-scalar 'funcall) |
1227 |
| - ,function ,@arguments)) |
1228 |
| -|# |
1229 |
| - |
1230 | 1189 | (defmacro ac-wrap (type form)
|
1231 | 1190 | "Wrap a function form in a function that calls it via (a-call). Used for specification of inverse scalar functions."
|
1232 | 1191 | (list (if (eq :m type) 'λω 'λωα)
|
@@ -1342,9 +1301,6 @@ It remains here as a standard against which to compare methods for composing APL
|
1342 | 1301 | (= 1 (size-of ,condition)))
|
1343 | 1302 | (disclose-atom (vrender ,condition))
|
1344 | 1303 | (error "Predicates within an [$ if] statement must be unitary or scalar."))))
|
1345 |
| - ;; (if (not (is-unitary ,condition)) |
1346 |
| - ;; (error "Predicates within an [$ if] statement must be unitary or scalar.") |
1347 |
| - ;; (print (list :co ,condition ,output)) |
1348 | 1304 | (if (zerop ,output)
|
1349 | 1305 | ,(if (third clauses)
|
1350 | 1306 | (if (fourth clauses)
|
@@ -2030,7 +1986,6 @@ It remains here as a standard against which to compare methods for composing APL
|
2030 | 1986 | this-form))
|
2031 | 1987 | ((guard symbol (member symbol '(⍺ ⍵ ⍶ ⍹ ⍺⍺ ⍵⍵)))
|
2032 | 1988 | ;; handle argument symbols, adding them to the closure-meta list
|
2033 |
| - ;; (print (list :sy symbol closure-meta)) |
2034 | 1989 | (unless closure-meta
|
2035 | 1990 | ;; create the meta form if not present, needed for cases like 2{⍶⋄⍹}3⊢10
|
2036 | 1991 | (setf closure-meta (list :arg-syms nil)))
|
@@ -2116,17 +2071,6 @@ It remains here as a standard against which to compare methods for composing APL
|
2116 | 2071 | :inverse-right :inverse))
|
2117 | 2072 | ,arg1 ,(funcall to-wrap form))))))))))))))
|
2118 | 2073 |
|
2119 |
| -;; (defmacro plain-ref (function &optional axes) |
2120 |
| -;; "Wrap a lexical function; this is needed to implement some meta-functionality." |
2121 |
| -;; ;; TODO: can the functionality here and in amb-ref be factored out and merged? |
2122 |
| -;; (let ((this-fn (gensym)) (args (gensym)) (iargs (gensym))) |
2123 |
| -;; `(labels ((,this-fn (&rest ,args) |
2124 |
| -;; ,@(when axes `((when (eq :assign-axes (first ,args)) |
2125 |
| -;; (setq ,axes (second ,args) |
2126 |
| -;; ,args (cddr ,args))))) |
2127 |
| -;; (apply ,function ,args))) |
2128 |
| -;; #',this-fn))) |
2129 |
| - |
2130 | 2074 | (defmacro plain-ref (function &optional axes)
|
2131 | 2075 | "Wrap a lexical function; this is needed to implement some meta-functionality."
|
2132 | 2076 | ;; TODO: can the functionality here and in amb-ref be factored out and merged?
|
@@ -2284,7 +2228,6 @@ It remains here as a standard against which to compare methods for composing APL
|
2284 | 2228 | (push `(symbol-function ',aliased) assignment-forms)
|
2285 | 2229 | (case spec-type (functions (incf afn-count))
|
2286 | 2230 | (operators (incf aop-count)))
|
2287 |
| - ;; (print (list :ach achar lexicons)) |
2288 | 2231 | ;; assign the alias to lexicons according to the lexicon
|
2289 | 2232 | ;; membership (as specified in this form or already
|
2290 | 2233 | ;; present in the current lexicon) of the character
|
|
0 commit comments