108
108
, form (lambda (&rest , args)
109
109
(let ((, this-meta (apply , form (cons :get-metadata
110
110
(when (second , args) (list nil ))))))
111
- ; ; pass the environment variables if this is a user-defined function
112
- (apply , form (append , args (when (not (second , args)) (list nil ))
111
+ ; ; pass the environment variables if this is a user-defined function;
112
+ ; ; remember not to add the nil argument if an internal
113
+ ; ; variable state is being set
114
+ (apply , form (append , args (when (and (not (second , args))
115
+ (getf , this-meta :lexical-reference ))
116
+ (list nil ))
113
117
(when (not (getf , this-meta :lexical-reference ))
114
118
(list (list :index-origin index-origin)))))))))))
115
119
242
246
, env))
243
247
,@ (loop :for var :in params :when (not (eql ' &optional var))
244
248
:collect ` (setq , var (render-varrays , var)))
249
+ ; ; (print (list :par ,@(remove '&optional (append params (list env 'abc)))))
245
250
(if (eq :get-metadata , (first params))
246
251
, (cons ' list meta)
247
252
(let , (if space
1081
1086
(cddr function)))))))
1082
1087
` (let ((, arg-list (list ,@ arguments ))) ; ,@(if axes-present (list (third function))))))
1083
1088
(apply ,@ (if is-scalar (list ' #'apply-scalar))
1084
- , (if t ; (not axes-present)
1085
- function (butlast function 1 ))
1086
- , arg-list))))))
1089
+ , function , arg-list))))))
1087
1090
1088
1091
(defun join-fns (form &optional wrap)
1089
1092
" Compose multiple successive scalar functions into a larger scalar function. Used to expand (a-call)."
@@ -1273,23 +1276,56 @@ It remains here as a standard against which to compare methods for composing APL
1273
1276
(>= 2 (length function)))
1274
1277
function (list (first function) (second function))))
1275
1278
(axes (and (listp function) (eql ' apl-fn (first function))
1276
- (third function))))
1279
+ (third function)))
1280
+ (fn-quoted (if (not (symbolp function)) function (list ' function function))))
1277
1281
` (lambda (&rest , args)
1278
1282
(let ((, ax-sym (third , args)))
1279
1283
(declare (ignorable , ax-sym))
1280
- (if (eq :get-metadata (first , args))
1281
- , (append ' (list :scalar t ) meta)
1282
- , (if is-virtual
1283
- ` (make-instance ' vader-operate
1284
- :base (coerce (if (not , ax-sym)
1285
- , args (butlast , args))
1286
- ' vector)
1287
- :function , (if (not (symbolp function)) function ` (function , function))
1288
- :index-origin 0 :axis , ax-sym :params (list ,@ meta))
1289
- ` (apply-scalar , (if (not (symbolp function)) function ` (function , function))
1290
- (first , args) (second , args)
1291
- ; ; ,@(if axes (list axes))
1292
- , ax-sym)))))))
1284
+ ; ; (print (list :ff ',function))
1285
+ (case (first , args)
1286
+ (:get-metadata , (append ' (list :scalar t ) meta))
1287
+ (:arg-vector (make-instance ' vader-operate
1288
+ :base (second , args) :index-origin 0 :params (list ,@ meta)
1289
+ :axis , ax-sym :function , fn-quoted))
1290
+ (:call-scalar (apply , fn-quoted (rest , args)))
1291
+ (t , (if is-virtual
1292
+ ` (make-instance ' vader-operate
1293
+ ; ; :base (coerce (if (not ,ax-sym) ,args (butlast ,args))
1294
+ ; ; 'vector)
1295
+ ; ; :base (reverse (if (not ,ax-sym) ,args (butlast ,args)))
1296
+ :base (if (not , ax-sym) , args (butlast , args))
1297
+ :function , fn-quoted :index-origin 0 :axis , ax-sym
1298
+ :params (list ,@ meta))
1299
+ ` (apply-scalar , fn-quoted (first , args) (second , args)
1300
+ ; ; ,@(if axes (list axes))
1301
+ , ax-sym))))))))
1302
+
1303
+ ; ; (defmacro scalar-function (function &rest meta)
1304
+ ; ; "Wrap a scalar function. This is a passthrough macro used by the scalar composition system in (a-call)."
1305
+ ; ; (let ((args (gensym)) (ax-sym (gensym))
1306
+ ; ; (is-virtual (getf meta :va))
1307
+ ; ; (function (if (or (not (listp function))
1308
+ ; ; (not (eql 'apl-fn (first function)))
1309
+ ; ; (>= 2 (length function)))
1310
+ ; ; function (list (first function) (second function))))
1311
+ ; ; (axes (and (listp function) (eql 'apl-fn (first function))
1312
+ ; ; (third function))))
1313
+ ; ; `(lambda (&rest ,args)
1314
+ ; ; (let ((,ax-sym (third ,args)))
1315
+ ; ; (declare (ignorable ,ax-sym))
1316
+ ; ; (if (eq :get-metadata (first ,args))
1317
+ ; ; ,(append '(list :scalar t) meta)
1318
+ ; ; ,(if is-virtual
1319
+ ; ; `(make-instance 'vader-operate
1320
+ ; ; :base (coerce (if (not ,ax-sym)
1321
+ ; ; ,args (butlast ,args))
1322
+ ; ; 'vector)
1323
+ ; ; :function ,(if (not (symbolp function)) function `(function ,function))
1324
+ ; ; :index-origin 0 :axis ,ax-sym :params (list ,@meta))
1325
+ ; ; `(apply-scalar ,(if (not (symbolp function)) function `(function ,function))
1326
+ ; ; (first ,args) (second ,args)
1327
+ ; ; ;; ,@(if axes (list axes))
1328
+ ; ; ,ax-sym)))))))
1293
1329
1294
1330
(defun validate-arg-unitary (value)
1295
1331
" Verify that a form like (vector 5) represents a unitary value."
@@ -2051,6 +2087,8 @@ It remains here as a standard against which to compare methods for composing APL
2051
2087
(defmacro amb-ref (fn-monadic fn-dyadic &optional axes is-virtual)
2052
2088
" Generate a function aliasing a lexical function which may be monadic or dyadic; an ambivalent reference."
2053
2089
(let ((args (gensym )) (iargs (gensym )) (reduced-args (gensym )) (this-fn (gensym )) (a (gensym ))
2090
+ (m-scalar (when (eq ' scalar-function (first fn-monadic)) ' (:scalar t )))
2091
+ (d-scalar (when (eq ' scalar-function (first fn-dyadic)) ' (:scalar t )))
2054
2092
(m-meta (if (member (first fn-monadic) ' (fn-meta scalar-function))
2055
2093
(cddr fn-monadic)))
2056
2094
(d-meta (if (member (first fn-dyadic) ' (fn-meta scalar-function))
@@ -2069,8 +2107,8 @@ It remains here as a standard against which to compare methods for composing APL
2069
2107
(setq , axes (second , args)
2070
2108
, args (cddr , args)))))
2071
2109
(if (eq :get-metadata (first , args))
2072
- (if (= 1 (length , args)) , (if m-meta (cons ' list m- meta))
2073
- , (if d-meta (cons ' list d- meta)))
2110
+ (if (= 1 (length , args)) , (if m-meta (cons ' list ( append m-scalar m- meta) ))
2111
+ , (if d-meta (cons ' list ( append d-scalar d- meta) )))
2074
2112
(if (= 2 (length , args))
2075
2113
(if (null (second , args))
2076
2114
(a-call , fn-monadic (first , args))
0 commit comments