3 +^:1: 2
5

Looking at your definition for guard:

guard =: 2 : 0
:
(u@:[)^: (v y) 1
)

This will give you a conjunction which will define a dyadic verb, but
that dyadic verb will ignore its left argument.  I assume you meant to
say

guard =: 2 : 0
:
  x (u@:[)^: (v y) 1
)

Thanks,

-- 
Raul

On Wed, Jan 15, 2014 at 11:26 AM, Pascal Jasmin <godspiral2...@yahoo.ca> wrote:
> I see the problem with guard now.  Its related to dyadic ^: having a weird 
> static optimization by doing (x&u)
>
> so even though guard asks for (u@:[) it passes the 1 at the far end of guard. 
>  Basically the u side of ^: is always monadic, though it might be buggy:
>
>    (2 = +/) 2
> 1
>    2 (2 = +/) guard *  1 NB. should be 1
> 0
>
>    2 (2 = sideff)@:[ ^: (* 1) 1 NB. not buggy when ^: not called from another 
> definition.
> 1
>
> A workaround that is not so bad:
>
> guard2 =: 2 : '(u)^: (v y) 1'
>
>
>    (2 = +/ )bind 3 guard2 *  1
> 0
>    (2 = +/ )bind 2 guard2 *  1
> 1
>    (2 = +/ )bind 3 guard2 *  0
> 1
>
> This definition is a cleaner workaround if bind is necessary:
>
> guard3 =: 2 : 0
> :
> (u bind x)^: (v y) 1
> )
>
>   3 (2 = +/ ) guard3 *  0
> 1
>    3 (2 = +/ ) guard3 *  1
> 0
>    2 (2 = +/ ) guard3 *  1
> 1
>
>
> I think though that there is a bug with an embedded (u@:[)^: ... or of course 
> something I don't understand.
>
> original definition of guard
>
> guard =: 2 : 0
> :
> (u@:[)^: (v y) 1
> )
>
>
> ----- Original Message -----
> From: Brian Schott <schott.br...@gmail.com>
> To: Programming forum <programm...@jsoftware.com>
> Cc:
> Sent: Wednesday, January 15, 2014 8:42:23 AM
> Subject: Re: [Jprogramming] maybe a bug in short circuiting. Help with a      
>   guard structure
>
> I am not sure I can answer your question about guard, but I was able to get
> trace to work (after I loaded the exact filename) by appending "__" to the
> names as shown below. Maybe the trace will shed some light for you. I have
> to go out for a while now.
>
> load jpath '~addons/general/misc/trace.ijs'
>    trace '2 (2 = sideff__) guard__ *  1'
> --------------- 5 Trident ----
> 2
> =
> sideff__
> 2 = sideff__
> --------------- 8 Paren ------
> (
> 2 = sideff__
> )
> 2 = sideff__
> --------------- 4 Conj -------
> 2 = sideff__
> 2 : (':'; '(u@:[)^: (v y) 1')
> *
> (2 = sideff__) (2 : (':'; '(u@:[)^: (v y) 1')) *
> --------------- 2 Dyad -------
> 2
> (2 = sideff__) (2 : (':'; '(u@:[)^: (v y) 1')) *
> 1
>   ------------------------------
>   3 : 'a=: +/ y'
>   1
>   1
>   ==============================
> 0
> ==============================
> 0
>
>
>
> On Wed, Jan 15, 2014 at 1:08 AM, Pascal Jasmin <godspiral2...@yahoo.ca>wrote:
>
>> that kind of works.  It turns the expression from a noun to a fork.
>>
>> I'm still interested in the guard conjunction that I don't understand why
>> it doesn't work.
>>
>> thanks.
>>
>>
>> ----- Original Message -----
>> From: Raul Miller <rauldmil...@gmail.com>
>> To: Programming forum <programm...@jsoftware.com>
>> Cc:
>> Sent: Wednesday, January 15, 2014 12:37:08 AM
>> Subject: Re: [Jprogramming] maybe a bug in short circuiting. Help with a
>>      guard structure
>>
>> Oops, you are correct, and I was wrong. I should have tested against an
>> example.
>>
>> Anyways, a fix that retains your result pattern would be to replace
>> sideff y with sideff bind y (this will defer execution until you
>> receive the 1, which you will then ignore).
>>
>> I might be able to some up with something more elegant, but I'd want
>> test cases to play with before I make further mistakes.
>>
>> Thanks,
>>
>> --
>> Raul
>>
>>
>>
>> On Wed, Jan 15, 2014 at 12:21 AM, Pascal Jasmin <godspiral2...@yahoo.ca>
>> wrote:
>> > the 1 at the end does something useful:  m"_ ^: n 1 will return 1 if n
>> is 0 or m is 1.
>> >
>> > The overall pattern seems very common to me:  "if query1 has items then
>> if not also subquery is true signal error and exit function"
>> >
>> > I understand the confusion over my using y, but I was mostly trying to
>> illustrate noun expressions, and I understand now that it may not be
>> possible.
>> >
>> > My main question was in the second part, and asking why the 'guard'
>> conjunction doesn't work.
>> >
>> >
>> > ----- Original Message -----
>> > From: Raul Miller <rauldmil...@gmail.com>
>> > To: Programming forum <programm...@jsoftware.com>
>> > Cc:
>> > Sent: Tuesday, January 14, 2014 11:38:12 PM
>> > Subject: Re: [Jprogramming] maybe a bug in short circuiting. Help with
>> a        guard structure
>> >
>> > 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 <godspiral2...@yahoo.ca>
>> 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
>>
>> >
>> > ----------------------------------------------------------------------
>> > 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
>>
>
>
>
> --
> (B=) <-----my sig
> Brian Schott
>
> ----------------------------------------------------------------------
> 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