trigger=: outp1, outp2 verb ^: (trigger */@:-.@e.~ ])^:_ input
R.E. Boss -----Oorspronkelijk bericht----- Van: programming-boun...@jsoftware.com [mailto:programming-boun...@jsoftware.com] Namens David Vaughan Verzonden: zaterdag 8 oktober 2011 16:47 Aan: Programming forum Onderwerp: Re: [Jprogramming] Repeated application of a verb Well, the idea is to repeatedly perform the verb on its own output until one of two outputs occur, at which point the verb should stop being performed. Also, I need to have some way of knowing which of the two outputs were achieved. The result of the verb on each application will a positive integer. Does this sound like ^: would be of use? If so then how should it be applied? If not, then what would be the best approach? Thanks. On 8 Oct 2011, at 13:04, Raul Miller wrote: > On Sat, Oct 8, 2011 at 6:23 AM, David Vaughan > <purpleblue...@googlemail.com> wrote: >> Hi, I am looking to repeatedly apply a verb on itself until a >> certain value is reached, with the prior knowledge that there are >> two values that can be reached. The idea is to count how many times >> one of the two values comes up. I know about the power verb but I'm >> not sure how to use it properly beyond the simple v^:n y form. I've >> read about using it like a C while loop but in my case, there are >> two values I want to 'exit the loop' with. >> >> Any pointers? Thanks. > > Depending on what specifically you are trying to do, ^: may or may not > be the right thing to use. > > The issue is that ^: assumes that it is dealing with a mathematical > function. If its function gives the same result twice in a row, it > will stop right there. > > This is how ^:(test)^:_ works something like a while loop -- when > (test) returns false, the inner ^: becomes an identity function and > the outer ^: knows that it's time to stop. > > That said, note that ^: functions -- like pretty much everything else > in J -- can take list arguments and produce list results. > > -- > Raul > ---------------------------------------------------------------------- > 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