Good idea. Shouldn't hurt even if y is U32. On Fri, Dec 11, 2020, 9:28 AM Raul Miller <[email protected]> wrote:
> Since this does force a conversion from u8 to u16, and since it's the > wrong conversion in some cases, it's probably best to define words as > > words=: (0;sj;mj) ;: 2&u: > > (If loss of unicode4 characters is a concern, an additional guard > which protects using an assertion would be good.) > > Thanks, > > -- > Raul > > On Fri, Dec 11, 2020 at 10:38 AM Don Guinn <[email protected]> wrote: > > > > Recently there was a discussion on recognizing APL characters from other > > characters for ";:". I had wanted to try using the boxed form for "mj" > > instead of the literal form in ";:". So I gave it a try. Attached is a > > script containing "sj" and "mj" which will recognize APL characters for > U16 > > and U32. It also extends ";:" to handle U16 and U32. > > > > Here a few examples: > > > > NB. Normal J Statement > > > > words 'sum=. (i.3 4)+/ .*0j4+pru 4' > > > > +---+--+-+--+---+-+-+-+-+-+---+-+---+-+ > > > > |sum|=.|(|i.|3 4|)|+|/|.|*|0j4|+|pru|4| > > > > +---+--+-+--+---+-+-+-+-+-+---+-+---+-+ > > > > NB. An equivalent APL statement > > > > words U16 'sum← (⍳3 4)+.×0j4+pru 4' > > > > +---+-+-+-+---+-+--+-+---+-+---+-+ > > > > |sum|←|(|⍳|3 4|)|+.|×|0j4|+|pru|4| > > > > +---+-+-+-+---+-+--+-+---+-+---+-+ > > > > NB. Support for unicode > > > > words '¿Qué tan difícil es aprender el lenguaje de programación J?' > > > > +----+---+-------+--+--------+--+--------+--+------------+-+-+ > > > > |¿Qué|tan|difícil|es|aprender|el|lenguaje|de|programación|J|?| > > > > +----+---+-------+--+--------+--+--------+--+------------+-+-+ > > > > NB. A mixture of types > > > > ,.<;.2 words U16 {{)n > > > > x u^:(v0`v1`v2)y NB. <==> (x v0 y)u^:(x v1 y) (x v2 y) > > > > (~R∊R∘.×R)/R←1↓ιR ⍝ Find all primes from 1 to R > > > > Hvað er með alla umlóta? > > > > The amount is £100 > > > > 1 3 2j1+2 ¯3 2r7 > > > > }} > > > > +-------------------------------------------------------------------+ > > > > |+-+-+--+-+--+-+--+-+--+-+-+-------------------------------------+-+| > > > > ||x|u|^:|(|v0|`|v1|`|v2|)|y|NB. <==> (x v0 y)u^:(x v1 y) (x v2 y)| || > > > > |+-+-+--+-+--+-+--+-+--+-+-+-------------------------------------+-+| > > > > +-------------------------------------------------------------------+ > > > > |+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-----------------------------+-+| > > > > ||(|~|R|∊|R|∘|.|×|R|)|/|R|←|1|↓|ι|R|⍝ Find all primes from 1 to R| || > > > > |+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-----------------------------+-+| > > > > +-------------------------------------------------------------------+ > > > > |+----+--+---+----+------+-+-+ | > > > > ||Hvað|er|með|alla|umlóta|?| | | > > > > |+----+--+---+----+------+-+-+ | > > > > +-------------------------------------------------------------------+ > > > > |+---+------+--+----+-+ | > > > > ||The|amount|is|£100| | | > > > > |+---+------+--+----+-+ | > > > > +-------------------------------------------------------------------+ > > > > |+-------+-+----+---+-+ | > > > > ||1 3 2j1|+|2 ¯3|2r7| | | > > > > |+-------+-+----+---+-+ | > > > > +-------------------------------------------------------------------+ > > > > NB. A speed test > > > > ts=:6!:2,7!:2@] > > > > y=: 1e6$' fourscore and seven years ago, our fathers' > > > > ts ';: y' > > > > 0.0211792 4.26892e7 > > > > ts 'words y' > > > > 0.022107 2.8022e7 > > > > (;:-:words)y > > > > 1 > > > > I found the boxed form for "mj" quite workable. In addition it is able to > > handle a wider range of data types. > > > > > > As expected it is a little slower than the standard ";:" as it forces > ";:" > > to convert "literal" to "literal2". But I was surprised to see the > drastic > > reduction in memory required to run the modified version of ";:". > > ---------------------------------------------------------------------- > > For information about J forums see http://www.jsoftware.com/forums.htm > ---------------------------------------------------------------------- > For information about J forums see http://www.jsoftware.com/forums.htm > ---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm
