Even doing nothing , I haven't had blocks of time to make much
progress on 4th(reva).CoSy since APL2007 . I just , however ,
uploaded a new copy with a corrected version of my "atomic" apply
"adverb" . Below is the msg I've posted both on the Reva Forth forum
at http://ronware.org/reva/viewtopic.php?pid=5993#p5993
and on the
CoSy forum at http://www.cosy.com/Forum/viewtopic.php?pid=28#p28
where
it has the advantage of better formatting . Anybody is welcome to
download and "join" CoSy development at any time , of course , but
it's better to think of it as extensions to Forth than a full APL at
this time .
4th.CoSy at this level executes directly in Forth which means each
word ( chars delimited by whitespace ) is interpreted as
encountered .
| ================================================== |
I've uploaded updated files to http://cosy.com/CoSy/CoSy/CoSy.zip
.
Not many changes . I'll wait for float x^y etc for the integrated Reva
release .
Actually , I uploaded a new copy mainly to be sure to support a few
lines ( below ) I composed without crashing once . ( Did a ctrl_s
"save" virtually every step tho . )
I decided I wanted to get a full list of all the days of the year . I
ended up thinking it's not very useful . I really would like to pull
up the brilliant calendar formatting APL from Gene McDonnell I used in
2nd.CoSy .
You will see I added a new word ^+ which will be the "CoSy" level
definition of + . Right now it's just integer add . This would be
called an atomic function in APL . The operator or adverb aaply
applies the ticked function over the corresponding leaves of LA and
RA . Remember indexing in CoSy is modulo the length of the longer list
argument .
Because this is such a quintessential "APL"ish function , and shows
what a major generalization and simplification modulo indexing is ,
here are a number of examples with results of aaply on simple arrays .
Code:
: ^+ ( LA RA -- itemwise_LA+RA ) ['] + aaply ; | "atomic" apply
integer + | applies fn between leaves of LA and RA
i( 1 2 3 )i dup ^+ lst | sum of vector with itself
2 4 6
12 _iota i( 3 4 )i reshape >t0> lst | A 3 item list of 4 atom
lists
(
0 1 2 3
4 5 6 7
8 9 10 11
)
i( 10 )i t0 ^+ lst | APL's "scalar extension"
(
10 11 12 13
14 15 16 17
18 19 20 21
)
t0 dup ^+ lst | "matrix" addition
(
0 2 4 6
8 10 12 14
16 18 20 22
)
i( 10 20 30 )i t0 ^+ lst | Vector + matrix
(
10 11 12 13
24 25 26 27
38 39 40 41
)
i( 10 20 30 40 )i t0 ' ^+ eachright lst |
(
10 21 32 43
14 25 36 47
18 29 40 51
)
12 _iota i( 3 2 2 )i reshape >t0> lst | A 3 item list of 4
atom lists
(
(
0 1
2 3
) (
4 5
6 7
) (
8 9
10 11
) )
i( 10 20 )i t0 ^+ lst
(
(
10 11
12 13
) (
24 25
26 27
) (
18 19
20 21
) )
| Some other examples to try :
i( 10 20 30 )i enc enc t0 ^+ lst
i( 10 20 30 )i ' _iv eachM> lst
i( 10 20 )i i( 20 )i ,l i( 30 )i cL t0 ^+ lst
Now to get to the original ( pointless ) calendar example which
motivated all this . Download CoSy if you want to dissect each line .
Code:
1 1 2008 date>fixed _iv 365 _iota ^+ | Convert New Years to
"julian" date , make into CoSy vec , add 365 days
{ fixed>date dtpk } eachMcr fmtI | convert each back to
"gregorian" dates and pack as yyyymmdd integers , then format as
strings .
4 _iv ' cut eachleft ' cL across lst | Lop off "yyyy" from each ,
list
(
s" 0101"
s" 0102"
s" 0103"
s" 0104"
s" 0105"
s" 0106"
... )


|