jsoftware / jsource

J engine source mirror
Other
650 stars 90 forks source link

Change definition of negative level (strawman) #58

Open tangentstorm opened 2 years ago

tangentstorm commented 2 years ago

Negative level u L:(-n) will be redefined to mean "execute u within the boxed noun, on every cell that is enclosed by exactly n boxes."

Examples: u L:_1 means the same as u&.> when applied to a boxed noun.

   phi=. * -.@%@~.&.q:      NB. Euler's totient function
   ]t=. 5!:2 <'phi'
+-+-----------------------+
|*|+---------------+--+--+|
| ||+--------+-+--+|&.|q:||
| |||+--+-+-+|@|~.||  |  ||
| ||||-.|@|%|| |  ||  |  ||
| |||+--+-+-+| |  ||  |  ||
| ||+--------+-+--+|  |  ||
| |+---------------+--+--+|
+-+-----------------------+
   $L:_1 t
+-+-+
|1|3|
+-+-+
   $L:_2 t
+-+-------+
|*|+-+-+-+|
| ||3|2|2||
| |+-+-+-+|
+-+-------+
   $L:_3 t
+-+---------------+
|*|+-------+--+--+|
| ||+-+-+-+|&.|q:||
| |||3|1|2||  |  ||
| ||+-+-+-+|  |  ||
| |+-------+--+--+|
+-+---------------+

As the examples illustrate, cells whose boxing level is less than n are left unchanged.

At each level, the argument(s) are inspected to see if they are ripe for processing: far enough from the top level if the level is negative, or close enough to the bottom level is level is nonnegative. If all argument(s) are ripe, the verb is executed on it(them) and the y argument is replaced with the result of the execution.

If an argument is not ripe, there are several cases:

-- @HenryHRich 20:56, 22 July 2018 (UTC)