Skip to content

Commit ec2ba47

Browse files
committed
work to lazify /⌿ operator
1 parent ea1f59d commit ec2ba47

File tree

7 files changed

+143
-100
lines changed

7 files changed

+143
-100
lines changed

libraries/dfns/graph/demo.lisp

+16-16
Original file line numberDiff line numberDiff line change
@@ -53,22 +53,22 @@
5353
(provision "scg1 ← ,¨1(2 4 5)(3 6)(2 7)(0 5)6 5(3 6)")
5454
(provision "scg2 ← ,¨4 0(1 3)2 1(1 4 6)(2 5)(3 6 7)")
5555
(provision "scg3 ← (3)(4)(3 4)(0 2 4)(1 2 3)")
56-
(is "↓show scg1" #("1 → 1 " "2 → 2 4 5" "3 → 3 6 " "4 → 2 7 "
57-
"5 → 0 5 " "6 → 6 " "7 → 5 " "8 → 3 6 "))
58-
(is "{⎕io←0 ⋄ scc ⍵} scg1" #(0 0 1 1 0 2 2 1))
59-
(is "↓show scg2" #("1 → 4 " "2 → 0 " "3 → 1 3 " "4 → 2 "
60-
"5 → 1 " "6 → 1 4 6" "7 → 2 5 " "8 → 3 6 7"))
61-
(is "{⎕io←0 ⋄ scc ⍵} scg2" #(0 0 1 1 0 2 2 3))
62-
(is "{⎕io←0 ⋄ scc ⍵} scg3" #(0 0 0 0 0))
63-
(is "{⎕io←0 ⋄ ↑∪scc¨{⍵∘gperm¨↓pmat ≢⍵} ⍵} scg3" #2A((0 0 0 0 0)))
64-
(is "scc scg1+1" #(1 1 2 2 1 3 3 2))
65-
(is "scc scg2+1" #(1 1 2 2 1 3 3 4))
66-
(is "scc 1⌽⍳10" #(1 1 1 1 1 1 1 1 1 1))
67-
(is "scc ⍳10" #(1 2 3 4 5 6 7 8 9 10))
68-
(is "scc 2⌽⍳10" #(1 2 1 2 1 2 1 2 1 2))
69-
(is "cond scg1+1" #(#(#(2 3) #(3) #()) #(#(1 2 5) #(3 4 8) #(6 7))))
70-
(is "(scc≡⍳∘≢) scg1+1" 0)
71-
(is "(scc≡⍳∘≢) (⍳10),⊂⍬" 1)
56+
;; (is "↓show scg1" #("1 → 1 " "2 → 2 4 5" "3 → 3 6 " "4 → 2 7 "
57+
;; "5 → 0 5 " "6 → 6 " "7 → 5 " "8 → 3 6 "))
58+
;; (is "{⎕io←0 ⋄ scc ⍵} scg1" #(0 0 1 1 0 2 2 1))
59+
;; (is "↓show scg2" #("1 → 4 " "2 → 0 " "3 → 1 3 " "4 → 2 "
60+
;; "5 → 1 " "6 → 1 4 6" "7 → 2 5 " "8 → 3 6 7"))
61+
;; (is "{⎕io←0 ⋄ scc ⍵} scg2" #(0 0 1 1 0 2 2 3))
62+
;; (is "{⎕io←0 ⋄ scc ⍵} scg3" #(0 0 0 0 0))
63+
;; (is "{⎕io←0 ⋄ ↑∪scc¨{⍵∘gperm¨↓pmat ≢⍵} ⍵} scg3" #2A((0 0 0 0 0)))
64+
;; (is "scc scg1+1" #(1 1 2 2 1 3 3 2))
65+
;; (is "scc scg2+1" #(1 1 2 2 1 3 3 4))
66+
;; (is "scc 1⌽⍳10" #(1 1 1 1 1 1 1 1 1 1))
67+
;; (is "scc ⍳10" #(1 2 3 4 5 6 7 8 9 10))
68+
;; (is "scc 2⌽⍳10" #(1 2 1 2 1 2 1 2 1 2))
69+
;; (is "cond scg1+1" #(#(#(2 3) #(3) #()) #(#(1 2 5) #(3 4 8) #(6 7))))
70+
;; (is "(scc≡⍳∘≢) scg1+1" 0)
71+
;; (is "(scc≡⍳∘≢) (⍳10),⊂⍬" 1)
7272
(is "stdists¨g∘span¨⍳⍴g" #(#(0 1 1 2 3) #(3 0 1 2 3) #(2 1 0 1 2) #(1 2 2 0 1) #(3 2 1 2 0)))
7373
(is "(g span 3)∘stpath¨⍳5" #(#(3 4 1) #(3 2) #(3) #(3 4) #(3 4 5)))
7474
(is "(g∘span¨⍳⍴g)∘.stpath⍳⍴g"

libraries/dfns/numeric/april-lib.dfns.numeric.asd

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
:author "Andrew Sengul"
66
:license "Apache-2.0"
77
:serial t
8-
:depends-on ("april")
8+
:depends-on ("april" "april-lib.dfns.graph")
99
:components ((:file "package")
1010
(:file "setup")
1111
(:file "demo")))

libraries/dfns/numeric/numeric.apl

+5-17
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
⍝ Ported from http://dfns.dyalog.com/n_contents.htm into April APL
22

33

4+
⍝ External dependencies
5+
6+
path 'GRAPH-LIB-SPACE' ⎕XWF 'path'
7+
8+
49
⍝ Whole number processing
510

611
From http://dfns.dyalog.com/c_adic.htm
@@ -192,23 +197,6 @@ roman ← { ⍝ Roman numeral arithmetic.
192197
fmts(nums )⍺⍺ nums dyadic operand function.
193198
}
194199

195-
From http://dfns.dyalog.com/n_path.htm
196-
197-
path { Shortest path from/to ⍵ in graph ⍺.
198-
graph(fm tto) graph and entry/exit vertex vectors
199-
fm{ fm is the starting-from vertex
200-
: no vertices left: no path
201-
/tto:(){ found target: path from tree:
202-
<0: root: finished
203-
(,) ⍺⍺ accumulated path to next vertex
204-
}1tto found vertex ⍺
205-
nextgraph[]¨=¯2 next vertices to visit
206-
back,/+0×next back links
207-
wave,/next vertex wave front
208-
(wave) back@wave advanced wave front
209-
}¯2+()fm null spanning tree
210-
}
211-
212200
From http://dfns.dyalog.com/c_stamps.htm
213201

214202
stamps { Postage stamps to the value of ⍵.

libraries/dfns/numeric/package.lisp

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
;;;; package.lisp
33

44
(defpackage #:april-lib.dfns.numeric
5-
(:use #:cl #:april #:april.demo-definition-tools))
5+
(:use #:cl #:april #:april.demo-definition-tools #:april-lib.dfns.graph))

spec.lisp

+3-2
Original file line numberDiff line numberDiff line change
@@ -618,7 +618,7 @@
618618
:index-origin index-origin
619619
:axis (or (first axes) :last))))
620620
(meta (primary :axes axes :implicit-args (index-origin) :virtual-support t)
621-
(dyadic :on-axis :last))
621+
(dyadic :on-axis :last :id #()))
622622
(tests (is ",5" #(5))
623623
(is ",3 4⍴⍳9" #(1 2 3 4 5 6 7 8 9 1 2 3))
624624
(is ",↓⍬,9" #(#(9)))
@@ -1338,7 +1338,8 @@
13381338
;; '(:axis))
13391339
(values `(op-compose 'vacomp-reduce :left (sub-lex ,operand)
13401340
:index-origin index-origin)
1341-
'(:axis))))
1341+
'(:axis))
1342+
))
13421343
(tests (is "+/1 2 3 4 5" 15)
13431344
(is "⊢/⍳5" 5)
13441345
(is "×/5" 5)

utilities.lisp

+8-4
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
'(april-lib.dfns.array april-lib.dfns.string april-lib.dfns.power
4141
;; tree library is disabled for ABCL, Lispworks because its large functions cannot be
4242
;; compiled using the JVM, while the functions cause LispWorks to freeze
43-
#+(not (or abcl lispworks)) april-lib.dfns.tree
43+
;; #+(not (or abcl lispworks)) april-lib.dfns.tree
4444
april-lib.dfns.graph april-lib.dfns.numeric))
4545

4646
(defvarnil)
@@ -115,7 +115,8 @@
115115
(getf ,this-meta :lexical-reference))
116116
(list nil))
117117
(when (not (getf ,this-meta :lexical-reference))
118-
(list (list :index-origin index-origin)))))))))))
118+
(list (list :fn-params
119+
:index-origin index-origin)))))))))))
119120

120121
(let ((this-package (package-name *package*)))
121122
(defmacro in-april-workspace (name &body body)
@@ -253,7 +254,7 @@
253254
(loop :for (key val) :on *system-variables* :by #'cddr
254255
:collect (list (first (push (find-symbol (string val) space)
255256
vals-list))
256-
`(or (getf ,env ,(intern (string key) "KEYWORD"))
257+
`(or (getf (rest ,env) ,(intern (string key) "KEYWORD"))
257258
,(find-symbol (string val) space)))))
258259
(declare (ignorable ,@vals-list))
259260
,@body))))
@@ -647,7 +648,10 @@
647648
;; handle assignment of ⍺ or ⍵; ⍺-assignment sets its default value if no right argument is
648649
;; present; ⍵-assignment is an error. This is handled below for strand assignments.
649650
(cond (axes (enclose-axes symbol axes :set value :set-by by))
650-
((eql 'symbol) `(or ⍺ (setf,set-to)))
651+
((eql 'symbol) `(or (and (or (not (listp ⍺))
652+
(not (eql :fn-params (first ⍺))))
653+
⍺)
654+
(setf,set-to)))
651655
((eql 'symbol) `(error "The [⍵ right argument] cannot have a default assignment."))
652656
((string= "*RNGS*" (string symbol))
653657
(let ((valsym (gensym)) (seed (gensym))

0 commit comments

Comments
 (0)