Perhaps I should also point out the grammatical distinction between
".&'flag1_z_'"_ and ".&('flag1_z_'"_ )?

   require 'trace'
   trace '".&''flag1_z_''"_ '
 --------------- 4 Conj -------
 ".
 &
 'flag1_z_'
 ".&'flag1_z_'
 --------------- 4 Conj -------
 ".&'flag1_z_'
 "
 _
 ".&'flag1_z_'"_
 ==============================

   trace '".&(''flag1_z_''"_) '
 --------------- 4 Conj -------
 'flag1_z_'
 "
 _
 'flag1_z_'"_
 --------------- 8 Paren ------
 (
 'flag1_z_'"_
 )
 'flag1_z_'"_
 --------------- 4 Conj -------
 ".
 &
 'flag1_z_'"_
 ".&('flag1_z_'"_)
 ==============================

Does this help?

Thanks,

-- 
Raul

On Tue, Sep 17, 2013 at 1:54 PM, Pascal Jasmin <[email protected]> wrote:
> Thank you Raul,
>
>    if =. (`])(@.([: -. [: ". 'flag1_z_'"_))
>    2 + if i.10
> 0 1 2 3 4 5 6 7 8 9
>    2 + if controlA i.10
> 2 3 4 5 6 7 8 9 10 11
>
>    +: if controlA i.10
> 0 2 4 6 8 10 12 14 16 18
>
> Though looking up ". page helped, what I really needed to do was to recall 
> that:
>
> ".&'flag1_z_'"_ was actually u&v and not u&n.  u&n would not have been what I 
> wanted anyway I think, as it would be applying numbers instead of do when run.
>
> On 2nd thought, u&v should still work as hoped, and the above fix is supposed 
> to be equivalent to @: or &:, but versions with those give a domain error.  I 
> prefer [: to @: anyway (the dyad confusion being the main reason), so no 
> biggie, but I can't say I understand why @: or &: is failing. 
> (".&'flag1_z_'"_)
>
>
> ________________________________
> From: Raul Miller <[email protected]>
> To: General forum <[email protected]>
> Sent: Tuesday, September 17, 2013 1:20:24 PM
> Subject: Re: [Jgeneral] Bug in adverb define
>
>
> If an expression is giving you an error which you do not understand,
> you might want to isolate the error.  But describing this process
> might not make sense, so perhaps I should show you instead:
>
> This will be a bit long, so feel free to skip over the boring parts:
>
>    +:`]@.([: -. ".&'flag1_z_'"_) i. 20
> |rank error
> |       +:`]@.([:-.".&'flag1_z_'"_)i.20
>    ([: -. ".&'flag1_z_'"_) i. 20
> |rank error
> |       ([:-.".&'flag1_z_'"_)i.20
>    (".&'flag1_z_'"_) i. 20
> |rank error
> |       (".&'flag1_z_'"_)i.20
>    (".&'flag1_z_'"_) 0
> 0
>    (".&'flag1_z_'"_) 0 1
> |rank error
> |       (".&'flag1_z_'"_)0 1
>    (".&'flag'"_) 0 1
> |rank error
> |       (".&'flag'"_)0 1
>    (".&'fl'"_) 0 1
> |rank error
> |       (".&'fl'"_)0 1
>    (".&'f'"_) 0 1
> |rank error
> |       (".&'f'"_)0 1
>    (".&'f') 0 1
> |rank error
> |       (".&'f')0 1
>    0 1 ".&'f'
> |syntax error
> |       0 1".&'f'
>    0 1 ". 'f'
> |rank error
> |   0 1    ".'f'
>    0 1 ". 'fl'
> |rank error
> |   0 1    ".'fl'
>
> At this point, I think I've shown that it's likely that the rank error
> is coming from ". so perhaps its dictionary page would be interesting:
> http://www.jsoftware.com/help/dictionary/d601.htm
>
> If you need further hints, we can try to provide them.
>
> Thanks,
>
> --
> Raul
>
>
> On Tue, Sep 17, 2013 at 12:14 PM, Pascal Jasmin <[email protected]> 
> wrote:
>>> I was not thinking about performance when I was rewriting them but theseare 
>>> the numbers I get...
>>
>> I tried making a version with @. to see, and this compiles
>>
>> if =. (`])(@.([: -. ".&'flag1_z_'"_)) NB. same results as @: replacing 
>> capped fork below
>>
>> and looks right with
>>
>>    +: if
>> +:`]@.(-.@:".&'flag1_z_'"_)
>>
>> but:
>>    +: if i.20
>> |rank error
>> |       +:if i.20
>>
>> and:
>>
>>    +: if("0) i.20
>> |index error
>> |       +:if("0)i.20
>>
>> I don't understand the reason for either error.
>>
>>
>>
>>
>>
>> ----- Original Message -----
>> From: Jose Mario Quintana <[email protected]>
>> To: [email protected]
>> Cc:
>> Sent: Sunday, September 15, 2013 11:10:42 PM
>> Subject: Re: [Jgeneral] Bug in adverb define
>>
>> I was not thinking about performance when I was rewriting them but these
>> are the numbers I get...
>>
>>    NB.Performance
>>
>>    st=. 7!:2@:] ; 6!:2
>>
>>    NB. Explicitly...
>>
>>    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"0 controlA )
>> (test"0) (1 : 0)
>> flag1_z_ =: 1
>> o=. u y
>> flag1_z_ =: 0
>> o
>> )
>>
>>    10 st 'test"0            i.100000' NB. 8794368 is very puzzling!
>> ┌───────┬────────┐
>> │8794368│0.249716│
>> └───────┴────────┘
>>    10 st 'test"0 controlA   i.100000'
>> ┌───────┬────────┐
>> │1052544│0.249951│
>> └───────┴────────┘
>>    10 st 'test   controlA"0 i.100000'
>> ┌───────┬────────┐
>> │1052544│0.583864│
>> └───────┴────────┘
>>
>>    test"0            i.10
>> 0 1 2 3 4 5 6 7 8 9
>>    test"0 controlA   i.10
>> 0 2 4 6 8 10 12 14 16 18
>>    test   controlA"0 i.10
>> 0 2 4 6 8 10 12 14 16 18
>>
>>    NB. Tacitly...
>>
>>    ifC=. ^: (". @: ('flag1_z_'"_))
>>
>>    ( test=: +: ifC )
>> +:^:(".@:('flag1_z_'"_))
>>
>>    controlA_z_=. (`'' (&,) (@:(,&<)) ((([ ".@:('flag1_z_=:
>> 0'"_))@:((((<'`:') (0:`)(,^:)&6))@:(0&{ , <@:((,'0') ,&< ])@:(1&{::)))@:([
>> ".@:('flag1_z_=: 1'"_)))@:))
>>
>>    ( test"0 controlA )
>> ((([ (".@:('flag1_z_=: 0'"_)))@:(((,^:((0:)``:))&6)@:((0&{) , ((<@:((,'0')
>> (,&<) ]))@:(1&({::))))))@:([ (".@:('flag1_z_=:
>> 1'"_))))@:(((,<(<,'"'),<(<'test'),<(,'0');0)&,)@:(,&<))
>>
>>    10 st 'test"0            i.100000'
>> ┌───────┬────────┐
>> │1050560│0.120329│
>> └───────┴────────┘
>>    10 st 'test"0 controlA   i.100000'
>> ┌───────┬────────┐
>> │1576832│0.124354│
>> └───────┴────────┘
>>    10 st 'test   controlA"0 i.100000'
>> ┌───────┬───────┐
>> │1052416│0.71766│
>> └───────┴───────┘
>>
>>    test"0            i.10
>> 0 1 2 3 4 5 6 7 8 9
>>    test"0 controlA   i.10
>> 0 2 4 6 8 10 12 14 16 18
>>    test   controlA"0 i.10
>> 0 2 4 6 8 10 12 14 16 18
>>
>>
>>
>> On Sun, Sep 15, 2013 at 5:47 PM, Pascal Jasmin <[email protected]>wrote:
>>
>>> btw, your tacit definition of ifC (and test) is twice as fast as the
>>> explicit one when applied to 0 cells.
>>>
>>>    10 ts 'test1"0 controlA i.100000'  -- tacit  ^: (". @: ('flag1_z_'"_))
>>> 7.74526/sec 2.10483MB
>>>    10 ts 'test"0 controlA i.100000'   -- explicit 1 : 'if. flag1_z_ do. u
>>> y else. y end.'
>>> 4.18765/sec 2.10598MB
>>>    10 ts 'test1"0  i.100000'
>>> 8.76733/sec 2.10099MB
>>>    10 ts 'test"0  i.100000'
>>>
>>> 4.11696/sec 16.5399MB
>>>
>>> I assume that it is because the if. structure is just slower rather than
>>> the J engine not being able to peek inside.  The explicit version is 50%
>>> faster on "_ rank though, probably because the explicit one is evaluated
>>> once.  The tacit version of controlA seems slower than the explicit one,
>>> probably because it does so much.
>>>
>>>
>>>
>>> ----- 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
>> ----------------------------------------------------------------------
>> 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