Skip to content

Commit

Permalink
more work on @ operator, compiler logic
Browse files Browse the repository at this point in the history
  • Loading branch information
phantomics committed Nov 9, 2018
1 parent 10129f6 commit c24df26
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 13 deletions.
1 change: 0 additions & 1 deletion README.md
Expand Up @@ -325,7 +325,6 @@ All :in and :out values will be nullified, :count-from will return to its defaul
#### Operators:

```
@ At
⍤ Rank
⌸ Key
⌺ Stencil
Expand Down
45 changes: 35 additions & 10 deletions april.lisp
Expand Up @@ -308,6 +308,15 @@
(not (eql #\← (third (first prior-expression)))))
(gethash (first exp)
(gethash :functions meta)))
;; break if the current expression is a pivotal operator expression composing a function
;; and there is a preceding expression, which in this case must be a monadic function with
;; something on its right side
(and prior-expression
(listp (first exp))
(listp (caar exp))
(not (loop for subex in (caar exp) never (and (listp subex)
(eq :op (first subex))
(eq :pivotal (second subex))))))
;; break if the next symbol represents a function and should be processed by assembleOperation
(and (listp (first exp))
(keywordp (caar exp))
Expand All @@ -332,7 +341,6 @@
;; disclose single symbols since any value they represent will be vectorized
(or (stringp (first output))
(symbolp (first output))
;;(symbolp (first output))
(listp (first output))
(arrayp (first output))))
(first output))
Expand Down Expand Up @@ -399,6 +407,7 @@
(let ((head (first exp))
(next (second exp))
(tail (rest exp)))
;; (print (list :asop exp precedent))
(macrolet ((get-function (symbol)
`(let ((function (if (or (characterp ,symbol)
(symbolp ,symbol))
Expand Down Expand Up @@ -462,15 +471,15 @@

((and (eq :op (first head))
(or from-pivot (not (eq :pivotal (second head))))
;; note: center operator glyphs cannot be overloaded as function glyphs if they follow
;; another center operator glyph
;; note: pivotal operator glyphs cannot be overloaded as function glyphs if they follow
;; another pivotal operator glyph
(or (not tail)
(not (or (and (listp next)
(eq :fn (first next)))
(and (symbolp next)
(not (eql #\← (third head)))
(gethash next (gethash :functions meta)))))))
;; if no function follows a right operator glyph, check whether it's actually an overloaded
;; if no function follows a lateral operator glyph, check whether it's actually an overloaded
;; function glyph and reassign if so
(if (of-overloaded? idiom (first (last head)))
(values (get-function (first (last head)))
Expand All @@ -491,7 +500,19 @@
meta (cons 'list (mapcar (lambda (item) (cons 'vector item))
axes))
following-op)
from-following-op)))))))
from-following-op)))
((and exp precedent (listp (first exp))
(listp (caar exp)))
;; if this is the beginning of a composed operation following a function character,
;; build the operation using the subprocessor and pass back the function to combine it
;; with the precedent
;; (print (list :erer exp precedent))
;; (print (funcall subprocessor idiom meta exp))
(values (lambda (meta axes omega &optional alpha)
(declare (ignore meta axes))
`(funcall ,(funcall subprocessor idiom meta exp)
,omega ,@(if alpha (list alpha))))
tail))))))

(defun left-invert-matrix (in-matrix)
(let* ((input (if (= 2 (rank in-matrix))
Expand Down Expand Up @@ -1767,7 +1788,8 @@
(funcall right-operand meta axes 'omega))))
(at-alpha (cond ((listp left-operand)
left-operand)
((functionp right-operand)
((or (functionp left-operand)
(functionp right-operand))
(funcall left-operand meta axes 'omega))
(t (funcall left-operand meta axes
`(let* ((,new-array
Expand Down Expand Up @@ -1813,13 +1835,16 @@
(of-state (local-idiom april)
:count-from)))
(aref ,alpha-var ,index)))
omega))))))))))
omega))))))))
(tests (is "(20 20@3 8) ⍳9" #(1 2 20 4 5 6 7 20 9))
(is "(0@(3∘|)) ⍳9" #(0 0 3 0 0 6 0 0 9))
(is "({⍵×2}@{⍵>3}) ⍳9" #(1 2 3 8 10 12 14 16 18)))))

(general-tests (with :title "Basic function definition and use, with comments."
:in ("⍝ This code starts with a comment.
f1←{⍵+3} ⋄ f2←{⍵×2} ⍝ A comment after the functions are defined.
⍝ This is another comment.
f2 f1 1 2 3 4 5")
f1←{⍵+3} ⋄ f2←{⍵×2} ⍝ A comment after the functions are defined.
⍝ This is another comment.
f2 f1 1 2 3 4 5")
:ex #(8 10 12 14 16))
(with :title "Monadic inline function."
:in ("{⍵+3} 3 4 5")
Expand Down
2 changes: 2 additions & 0 deletions lexicon.md
Expand Up @@ -134,4 +134,6 @@
[∘] Compose
[⍣] Power
[@] At
```
4 changes: 2 additions & 2 deletions vex/vex.lisp
Expand Up @@ -164,7 +164,7 @@
(rest (first specs)))))
(props (rest (assoc (intern "HAS" (package-name *package*))
(rest (first specs)))))
(heading (format nil "[~a] ~a~a"
(heading (format nil "[~a] ~a~a~%"
(caar specs)
(if (getf props :title)
(getf props :title)
Expand All @@ -176,7 +176,7 @@
(labels ((for-tests (tests &optional output)
(if tests
(for-tests (rest tests)
(append output (list `(princ (format nil "~% _ ~a"
(append output (list `(princ (format nil " _ ~a"
,(cadr (first tests))))
(cond ((eql 'is (caar tests))
`(is (,(intern (string-upcase symbol)
Expand Down

0 comments on commit c24df26

Please sign in to comment.