Yes.

> if. -. (2 = sideff y)"_ ^: (*./ y) 1 do. 'bad' return. end.

J needs to resolve the contents of the parenthesis to a single entity
(noun, verb, adverb or conjunction).

In this case I think you want a verb, which would be controlled by ^:

Also, I do not see that that "_ does anything useful for you.

So, to accomplish what I think you are describing, I would get rid of
the 'y' in the places it currently exists on that line. That would
give you verb phrases inside both of the parenthesis where currently
you have noun phrases. I would also delete the "_

Then, I would replace that 1 with y. The 1 currently does nothing
useful and you want y as the argument for both of your verb phrases.

Does this line of reasoning make sense to you?

Thanks,

-- 
Raul


On Tue, Jan 14, 2014 at 11:13 PM, Pascal Jasmin <[email protected]> wrote:
> the following attempts to code the one line pattern with one less if. :
> if. test1 y do. if. -. test2 x do. 'test2 failed' return. end. end.
>
> The problem is that the verb sideff is called even if it shouldn't be.
>
> test=: 3 : 0
> if. -. (2 = sideff y)"_ ^: (*./ y) 1 do. 'bad' return. end.
> )
> sideff =: 3 : 'a=: +/ y'
>
>
>    test 1 2
> bad
>    a
> 3
>    test 1 1
>    a
> 2
>    test 1 0
>    a
> 1
>
> is this just due to nature of parentheses, and the interpreter needing to 
> parse what is on other side of "_
>
>
> This works as a one liner including shortcircuiting out the side effect when 
> appropriate :
>
>    3 (2 = sideff)@:[ ^: (* 0) 1
> 1
>    3 (2 = sideff)@:[ ^: (* 1) 1
> 0
>    2 (2 = sideff)@:[ ^: (* 1) 1
> 1
>
> but I don't understand why this fails:
>
> guard =: 2 : 0
> :
> (u@:[)^: (v y) 1
> )
>
>    3 (2 = sideff) guard *  1
> 0
>    2 (2 = sideff) guard *  1  NB. should be 1
> 0
>
> is there a way to define guard to properly short circuit and give the right 
> answer?  Is it impossible if the u argument evaluates to a noun as it was 
> used in first example?
> ----------------------------------------------------------------------
> 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