I'm having problems with :: adverse as an adverb
If I keep it simple, the adverse always runs.
2 + ( :: (a=:3:)) a=:0
2
a
3:
'' (+ :: (a=:3:)) a=:0
a
3:
If I make sure the compiler can't see the assignment, then it doesn't execute v
on error (or on success)
assign_z_ =: 4 : '(x) =: y'
2 + ( :: ('a' assign 3: [ ])) a=:0
2
'' + ( :: ('a' assign 3: [ ])) a
a
0
my eventual goal is to assign a side effect variable to a constant (but ideally
it should allow any assignment), and produce the output of 13!:12 or other
system message which I can do (not shown for simplicity). The problem with the
first version is that it will show the last error even if no error occurs.
A minor weirdness with :: is that (:: v) produces a spelling error, which I
understand because {:: is a thing, and so :: is treated like . and : for word
rules.
----- Original Message -----
From: Raul Miller <[email protected]>
To: General forum <[email protected]>
Cc:
Sent: Friday, September 13, 2013 4:20:07 PM
Subject: Re: [Jgeneral] Bug in adverb define
In that case, I'd probably be wanting to have my "repl sentence" be a
test which exercises the definition.
I do not see much benefit in a "passive voice" definition, all by
itself. (But if you have one, I'd be interested in hearing about it.)
That said, note also that J supports the use of scripts in much the
same way that it supports the use of single command lines. (Once your
project has gotten large enough.)
Thanks,
--
Raul
On Fri, Sep 13, 2013 at 3:45 PM, Pascal Jasmin <[email protected]> wrote:
> A 3rd point to squeezing the definition into a single line is that you can
> paste/execute it into the repl easily
>
> (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')
>
>
> test@:(+/%#) controlA 1 2 3
>
> 4
> test (+/%#) controlA 1 2 3
> 2
>
> Its much less typing and reloading of scripts (and potential restructuring
> the buildup inputs) to apply or turn off debugging output to certain parts of
> a program.
>
>
> ----- Original Message -----
> From: Raul Miller <[email protected]>
> To: General forum <[email protected]>
> Cc:
> Sent: Friday, September 13, 2013 2:27:38 PM
> Subject: Re: [Jgeneral] Bug in adverb define
>
> I use a variety of logging mechanisms, depending on what I want to focus on.
>
> One simple approach is to precede a line with smoutput.
>
> Or, if I want to log in the middle of an expression, I often use ([smoutput)
>
> (+/ %&([smoutput) #) 2 3 5 7
>
> If I want to label my results, I'll often use something like:
>
> smoutput 'label'; expression
>
> (([:([ smoutput@;~&'sum')+/) % [: ([smoutput@;~&'count') #) 2 3 5 7
>
> If the expression is really an assignment statement, I'll often use
> the name of the variable as the label.
>
> However, it's hard for me to predict where I'll be interested in
> logging, so I generally only opportunistically add logging statements
> to code when I am specifically curious about how it looks from the
> inside.
>
> And, of course other approaches are also possible. (For example, j's
> trace facility can sometimes be what I need).
>
> require'trace'
> trace '(+/ % #) 2 3 5 7'
>
> I hope this helps,
>
> --
> Raul
>
> 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