Seeing intermediate results using an example might help,

     (+/%#) (`'' )  NB. Getting the gerundial (atomic) representation of
the verb,
┌─────────────────┐
│┌─┬─────────────┐│
││3│┌───────┬─┬─┐││
││ ││┌─┬───┐│%│#│││
││ │││/│┌─┐││ │ │││
││ │││ ││+│││ │ │││
││ │││ │└─┘││ │ │││
││ ││└─┴───┘│ │ │││
││ │└───────┴─┴─┘││
│└─┴─────────────┘│
└─────────────────┘

     (+/%#) (`'' (&,)) NB. bonding it to append and
(,<(<,'3'),<(<(<,'/'),<,<,'+'),(<,'%'),<,'#')&,

     (+/%#) (`'' (&,) (@:(,&<)) ) NB. appending it to the argument(s)
(,<(<,'3'),<(<(<,'/'),<,<,'+'),(<,'%'),<,'#')&,@:(,&<)

     (+/%#) (`'' (&,) (@:(,&<)) ) 1 2 3 NB. For example,
┌─────────────────┬─────┐
│┌─┬─────────────┐│1 2 3│
││3│┌───────┬─┬─┐││     │
││ ││┌─┬───┐│%│#│││     │
││ │││/│┌─┐││ │ │││     │
││ │││ ││+│││ │ │││     │
││ │││ │└─┘││ │ │││     │
││ ││└─┴───┘│ │ │││     │
││ │└───────┴─┴─┘││     │
│└─┴─────────────┘│     │
└─────────────────┴─────┘
At this point (core@:) allows for core to take over,

    core T=. (+/%#) (`'' (&,) (@:(,&<)) ) 1 2 3
2

Again, seeing intermediate results might help,

    show=. ((1!:2)&2)

    ([ ".@:('flag1_z_=: 0'"_))@:(train@:(0&{ , an@:(1&{::)))@:([
".@:('flag1_z_=: 1'"_)) T
2
2
    ([ ".@:('flag1_z_=: 0'"_))@:show@:(train@:(0&{ , an@:(1&{::)))@:show@:([
".@:('flag1_z_=: 1'"_))@:show T
┌─────────────────┬─────┐
│┌─┬─────────────┐│1 2 3│
││3│┌───────┬─┬─┐││     │
││ ││┌─┬───┐│%│#│││     │
││ │││/│┌─┐││ │ │││     │
││ │││ ││+│││ │ │││     │
││ │││ │└─┘││ │ │││     │
││ ││└─┴───┘│ │ │││     │
││ │└───────┴─┴─┘││     │
│└─┴─────────────┘│     │
└─────────────────┴─────┘
┌─────────────────┬─────┐
│┌─┬─────────────┐│1 2 3│
││3│┌───────┬─┬─┐││     │
││ ││┌─┬───┐│%│#│││     │
││ │││/│┌─┐││ │ │││     │
││ │││ ││+│││ │ │││     │
││ │││ │└─┘││ │ │││     │
││ ││└─┴───┘│ │ │││     │
││ │└───────┴─┴─┘││     │
│└─┴─────────────┘│     │
└─────────────────┴─────┘
2
2
     ([ ".@:('flag1_z_=: 0'"_))@:(train@:(0&{ , show@:an@:show@:(1&{::)))@:([
".@:('flag1_z_=: 1'"_)) T
1 2 3
┌─────────┐
│┌─┬─────┐│
││0│1 2 3││
│└─┴─────┘│
└─────────┘
2
So, train is evaluating  (u y) by means of their atomic representations; in
other words, is a verb counterpart to the adverb (`:6).  This is what (the)
Force allows us to do but it is not for the faint of hart because it relies
on an undocumented (and unintended) feature; hence, "May the Force be with
you."  (See,
http://www.jsoftware.com/pipermail/programming/2013-March/031883.html .)

I hope it helps.
On Sun, Sep 15, 2013 at 3:57 PM, Pascal Jasmin <[email protected]>wrote:

> Brilliant stuff.  I grew a brain cell reading it.
>
> a couple of points I need explanation of:
>
> controlA=. `'' (&,) (@:(,&<)) (core@:)  NB. A train of adverbs
>
>
> `''  <---  I'm guessing this just binds with u.  But I don't follow the
> design purpose yet.
>
>
> +: (`'') NB. would return same.
>
>
> core=. ([ ".@:('flag1_z_=: 0'"_))@:(train@:(0&{ , an@:(1&{::)))@:([
> ".@:('flag1_z_=: 1'"_))
>
>
>
> 1&{::) <---  when run with the example, the rhs is +:`'' ?, and so that is
> picking `''.  as a verb does that become ''"_ ?
>
>
>
> an=. <@:((,'0') ,&< ])
>
>
>    an ''
> ┌────┐
> │┌─┬┐│
> ││0│││
> │└─┴┘│
> └────┘
>
>    (0&{ , an)  '+:';''
> ┌──┬─────────┐
> │+:│┌─┬─────┐│
> │  ││0│┌──┬┐││
> │  ││ ││+:││││
> │  ││ │└──┴┘││
> │  │└─┴─────┘│
> └──┴─────────┘
> I'm probably not following correctly.
>
> When you build such an expression, do you start from the left or right?
>  meet in the middle?
>
>
>
> ----- Original Message -----
> From: Jose Mario Quintana <[email protected]>
> To: [email protected]
> Cc:
> Sent: Sunday, September 15, 2013 2:01:20 PM
> Subject: Re: [Jgeneral] Bug in adverb define
>
> > An improvement I'm not sure is possible would be to modify controlA
> and/or
> > ifC to not access y, ie. be tacit.
>
> Sure it is; as far as I know, an explicit adverb (or verb) always can be
> rewritten tacitly, in theory.
>
>
>    controlA_z_ =: 1 : 0
> flag1_z_ =: 1
> o=. u y
> flag1_z_ =: 0
> o
> )
>
>    ifC=: 1 : 'if. flag1_z_ do. u y else. y end.'
>
>    ( test=: +: ifC )
> +: (1 : 'if. flag1_z_ do. u y else. y end.')
>
>    test controlA a=. 1 2 3
> 2 4 6
>    test  a=. 1 2 3
> 1 2 3
>
>    test@:(+/%#)           1 2 3
> 2
>    test@:(+/%#) controlA  1 2 3
> 4
>    test  (+/%#) controlA  1 2 3
> 2
>
>
> In practice, it can be easy,
>
>    ifC=. ^: (". @: ('flag1_z_'"_))
>
>    ( test=: +: ifC )
> +:^:(".@:('flag1_z_'"_))
>
> or it can be difficult but not nearly as difficult as it should be (so to
> speak),
>
>
>    Force=. (0:`)(,^:)                       NB. May the Force be with you
>    train=. (<'`:') (Force (&6))
>    an=. <@:((,'0') ,&< ])                   NB. Atomizing a noun
>    core=. ([ ".@:('flag1_z_=: 0'"_))@:(train@:(0&{ , an@:(1&{::)))@:([
> ".@:('flag1_z_=: 1'"_))
>
>    controlA=. `'' (&,) (@:(,&<)) (core@:)   NB. A train of adverbs
>
>    test controlA a=. 1 2 3
> 2 4 6
>    test  a=. 1 2 3
> 1 2 3
>
>    test@:(+/%#)           1 2 3
> 2
>    test@:(+/%#) controlA  1 2 3
> 4
>    test  (+/%#) controlA  1 2 3
> 2
>
>    controlA=. (`'' (&,) (@:(,&<)) ((([ ".@:('flag1_z_=: 0'"_))@:((((<'`:')
> (0:`)(,^:)&6))@:(0&{ , <@:((,'0') ,&< ])@:(1&{::)))@:([ ".@:('flag1_z_=:
> 1'"_)))@:))
>      NB. The adverb as a long self-contained one-liner (fixed manually to
> avoid the linear representation bug)
>
>    test controlA a=. 1 2 3
> 2 4 6
>    test  a=. 1 2 3
> 1 2 3
>
>    test@:(+/%#)           1 2 3
> 2
>    test@:(+/%#) controlA  1 2 3
> 4
>    test  (+/%#) controlA  1 2 3
> 2
>
> On Fri, Sep 13, 2013 at 2:19 PM, Pascal Jasmin <[email protected]
> >wrote:
>
> > Thanks very much.
> >
> > In terms of usefulness,
> > ifC=: 1 : 'if. flag1_z_ do. u y else. y end.'
> > pD =: smoutput ifC
> > test=: +: ifC
> >
> >    test controlA a=. 1 2 3
> > 2 4 6
> >   test  a=. 1 2 3
> > 1 2 3
> >
> > The pD verb can produce verbose output for debugging only when asked.
> >
> > 2 points to a single line:
> > 1.  eliminates 11 lines of irritating clutter that I don't want to see.
> > 2.  If I or someone else copies just the definition without the
> > initialization variable into a new project, in someone's lifetime, I/they
> > will get a domain error, and will either hate the function or their lives
> > because of it.  I might make this error more likely to occur by
> > inadvertantly inserting code between the function and the initialization.
> >
> > An improvement I'm not sure is possible would be to modify controlA
> and/or
> > ifC to not access y, ie. be tacit.
> >
> > ----- Original Message -----
> > From: Raul Miller <[email protected]>
> > To: General forum <[email protected]>
> > Cc:
> > Sent: Friday, September 13, 2013 1:25:06 PM
> > Subject: Re: [Jgeneral] Bug in adverb define
> >
> > It's not at all clear to me why doing this kind of thing on "one line"
> > is useful.
> >
> > That said, this example of yours:
> >
> >    flag1_z_ =: 0  [ controlA_z_ =: 1 : ('flag1_z_ =: 1';'o=. u
> > y';'flag1_z_ =: 0';'o')
> >
> > has this grammar:
> >
> >    name =: noun verb name =: noun conjunction noun
> >
> > Which, simplifies to
> >
> >    name =: noun verb adverb
> >
> > In other words, you are executing controlA with u defined as [ which
> > then simplifies to
> >
> >    name =: noun verb
> >
> > and that's just bad grammar.  A simple transformation which would make
> > it grammatically correct would be:
> >
> >    name =: verb noun
> >
> > and... projecting this back into your original sentence, it would become
> >
> >    flag1_z_ =: ([ controlA_z_ =: 1 : ('flag1_z_ =: 1';'o=. u
> > y';'flag1_z_ =: 0';'o')) 0
> >
> > However, since I have no idea what you are trying to accomplish, I
> > have no idea if this is relevant to your efforts.
> >
> > FYI,
> >
> > --
> > Raul
> >
> > On Fri, Sep 13, 2013 at 1:09 PM, Pascal Jasmin <[email protected]>
> > wrote:
> > > thank you.  I'm still not able to combine into one line (which IIUC can
> > be done with verb defines)
> > > flag1_z_ =: 0  [ controlA_z_ =: 1 : ('flag1_z_ =: 1';'o=. u
> y';'flag1_z_
> > =: 0';'o')
> > >
> > >
> > > btw, The dyad version define is:
> > > (flag1_z_ =: 0) [ controlA_z_ =: 1 : ('flag1_z_ =: 1';'o=. u
> > y';'flag1_z_ =: 0';'o';':';'flag1_z_ =: 1';'o=. x u y';'flag1_z_ =:
> 0';'o')
> > >
> > >
> > >
> > >
> > > ----- Original Message -----
> > > From: Don Guinn <[email protected]>
> > > To: General forum <[email protected]>
> > > Cc:
> > > Sent: Friday, September 13, 2013 12:18:34 PM
> > > Subject: Re: [Jgeneral] Bug in adverb define
> > >
> > > Need to add parens.
> > >
> > > controlA_z_ =: 1 : ('flag1_z_ =: 1';'o=. u y';'flag1_z_ =: 0';'o')
> > >
> > >
> > > On Fri, Sep 13, 2013 at 9:18 AM, Pascal Jasmin <[email protected]
> > >wrote:
> > >
> > >> The following in a script should work according to
> > >> http://www.jsoftware.com/help/dictionary/dicth.htm
> > >> flag1_z_ =: 0
> > >> controlA_z_ =: 1 : 'flag1_z_ =: 1';'o=. u y';'flag1_z_ =: 0';'o'
> > >>
> > >> It results in a syntax error script in J7.  The syntax error can be
> > >> eliminated by changing 1 : to 3 :
> > >>
> > >> The adverb (and definition) works as a 4 line definition.  Its purpose
> > is
> > >> to send control flags to a verb which changes its behaviour if called
> > with
> > >> the adverb.  The importance of getting it on one line is that
> supporting
> > >> dyads would take a multiline definition 10 lines with the ending ),
> and
> > its
> > >> the type of utility function that can be cloned to control2A control3A
> > and
> > >> so, single line definitions are more reusable.
> > >>
> > >> The multiline version is:
> > >> controlA_z_ =: 1 : 0
> > >> flag1_z_ =: 1
> > >> o=. u y
> > >> flag1_z_ =: 0
> > >> o
> > >> )
> > >>
> > >> Ideally I'd like to be able to write a definition line such as:
> > >>
> > >> flag1_z_ =: 0 [ controlA_z_ =: 1 : 'flag1_z_ =: 1';'o=. u y';'flag1_z_
> > =:
> > >> 0';'o'
> > >>
> > >> (which does load if '1 :' changed to '3 :')
> > >> ----------------------------------------------------------------------
> > >> 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
> > ----------------------------------------------------------------------
> > 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
>
> ----------------------------------------------------------------------
> 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