>>
<<
Ndx
Usr
Pri
Phr
Dic
Rel
Voc
!:
wd
Help
Dictionary
{::y has the same boxing as y and its
elements are the paths to each leaf (each open array).
|
|
x{::y fetches a subarray of y according to
path x ; the selection at each level is based
on { and, except at the last level, must result in an atom.
|
Map and Fetch can be modeled as follows:
cat =: { @: (i.&.>) @: $
mapp =: 4 : 'if. L. y. do. (<"0 x.,&.><"0 cat y.) mapp&.> y.
else. >x. end.'
map =: a:&mapp
fetch=: >@({&>/)@(<"0@|.@[ , <@]) " 1 _
The following phrases illustrate the use of Map and Fetch:
] y=: 1 2 3;4 5;i.4 5
+-----+---+--------------+
|1 2 3|4 5| 0 1 2 3 4|
| | | 5 6 7 8 9|
| | |10 11 12 13 14|
| | |15 16 17 18 19|
+-----+---+--------------+
(2;_1 _1){::y | The number 19 |
(_1;3 4) {::y | The number 19 |
{::y | Paths to each open array |
{::cat L: 0 y | Paths to each open scalar |
] t=: 5!:2 <'fetch' An array with an interesting structure
+------------------------------------------------------+-+---+
|+-----------------+-+--------------------------------+|"|1 _|
||+-+-+-----------+|@|+--------------------+-+-------+|| | |
|||>|@|+-------+-+|| ||+--------------+-+-+|,|+-+-+-+||| | |
||| | ||+-+-+-+|/||| |||+-------+-+--+|@|[|| ||<|@|]|||| | |
||| | |||{|&|>|| ||| ||||+-+-+-+|@||.|| | || |+-+-+-+||| | |
||| | ||+-+-+-+| ||| |||||<|"|0|| | || | || | ||| | |
||| | |+-------+-+|| ||||+-+-+-+| | || | || | ||| | |
||+-+-+-----------+| |||+-------+-+--+| | || | ||| | |
|| | ||+--------------+-+-+| | ||| | |
|| | |+--------------------+-+-------+|| | |
|+-----------------+-+--------------------------------+| | |
+------------------------------------------------------+-+---+
(0;2;0;0;0){:: t |
Fetch the subarray corresp. to <"0 in t |
(0;2;0;0;0;_1){:: t |
Fetch the 0 in that |
t ,&< L: 0 1 {:: t |
Label each leaf with its path |
< S: 0 t |
The boxed leaves of t |
< S: 1 {:: t |
The boxed paths of t |
t ,&< S: 0 1 {:: t |
A 2-column table of leaves and paths |
# 0: S: 0 t |
The number of leaves in t |
>>
<<
Ndx
Usr
Pri
Phr
Dic
Rel
Voc
!:
wd
Help
Dictionary