"(+/ % #)`''  NB. turns verb into ar, display ommitted"

There is a subtle difference between the atomic representation of a verb  u
and the gerund form (u`'') (both are gerunds); sometimes it can make all
the difference.  Consider the following implementation of a verb (process)
in the spirit of Mutiple/Single Instruction Multiple/Single Data processors.

   mean=. +/ % #
   AR=. (5!:1)@< 'mean'

   GT=.  (+/ % #)`''

   AR -: GT
0


   o=. @:
   y=. @:]
   an=. <@:((,'0') ,&< ])
   train=. 'y `:6'(3 :)          NB. Orthodox explicit version

   process=. < o train o ([ ; (an o >) y)("0)


   Y=. 1 2 3 ; 4 5

   AR            process Y       NB. SIMD
┌─┬───┐
│2│4.5│
└─┴───┘
   GT            process Y       NB. SIMD does not work with GT
|length error: process
|   GT     process Y
|[-20]


   (''$GT)       process Y       NB. SIMD
┌─┬───┐
│2│4.5│
└─┴───┘

   AR -: ''$GT
1

   AR            process <1 2 3  NB. SISD
┌─┐
│2│
└─┘
   (*:`(+/ % #)) process <1 2 3  NB. MISD
┌─────┬─┐
│1 4 9│2│
└─────┴─┘
   (*:`(+/ % #)) process Y       NB. MIMD
┌─────┬───┐
│1 4 9│4.5│
└─────┴───┘

Alternatively,

   train=. (<'`:')(0:`)(,^:)&6   NB. Unorthodox tacit version

   AR            process Y       NB. SIMD
┌─┬───┐
│2│4.5│
└─┴───┘
   AR            process <1 2 3  NB. SISD
┌─┐
│2│
└─┘
   (*:`(+/ % #)) process <1 2 3  NB. MISD
┌─────┬─┐
│1 4 9│2│
└─────┴─┘
   (*:`(+/ % #)) process Y       NB. MIMD
┌─────┬───┐
│1 4 9│4.5│
└─────┴───┘

There is also a subtle difference between the orthodox and the unorthodox
versions of train: the unorthodox version is more general; for example, one
can produce a genuine array of boxed verbs easily,

   (''$ (train o <)`'') process (*:`(+/ % #))  NB. SIMD
┌──┬──────┐
│*:│+/ % #│
└──┴──────┘


On Tue, Apr 14, 2015 at 4:31 AM, 'Pascal Jasmin' via Programming <
[email protected]> wrote:

> > But how would I  convert a verb to a string in the first place?
>
> J has 2 such useful representations:  linear and atomic.  atomic is that
> of gerunds, and several built in modifiers can turn gerunds/ar's back into
> verbs.
>
> I find linear representation easier to read and work with.
>
> lrA =: 1 : '5!:5 < ''u'''
>
>
> (+/ % #)`''  NB. turns verb into ar, display ommitted
>
> (+/ % #) lrA NB. result is string.
> +/ % #
>
>
> the eval function (for lr s) that I prefer is:
>
> eval =: 1 : ' a: 1 :  m' NB. can return any form of speech.
>
>
> though (".) works well if your phrase will return a noun.
>
> +: '@' eval +
> +:@+
>
>
>   +/ lrA , 1 2 3 lrA
> +/1 2 3 NB. string result
>
>
>
>
>
> ________________________________
> From: Jon Hough <[email protected]>
> To: "[email protected]" <[email protected]>
> Sent: Tuesday, April 14, 2015 4:11 AM
> Subject: [Jprogramming] Verb to string and Verb array
>
>
> I have a couple of questions:
> 1. Is it possible to convert a verb, e.g. +/%# ,  to a string?": '+/%# 2 3
> 4' executes a stringed verb with an argument. But how would I  convert a
> verb to a string in the first place?
> Also, I discovered the eval verb
>
>
> eval=: 1 : 0
>
> ". 'w =. ' , u
>
> (ar < 'w') ab
>
> )
>
>
> Does this have an inverse?
>
> 2. If I have two verbs (or conjunctions, adverbs for that matter), can I
> not pass them around in a list?
> e.g. in other languages, like C# I can put functions into a list
> (List<Action> for example).
> I searched JforC and the J website and couldn't find any way to do this.
> Thanks Jon
> ----------------------------------------------------------------------
> 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

Reply via email to