Well... if you are going to go there... for something like this I
would prefer to use binary search and array indexing.

30 90&I. almost works, for giving us the right kind of indices:

   30 90 I. 15 30 45 90 100
0 0 1 1 2

The only problem is that 30 doesn't give us the right value. But
that's easy to fix:

   (30 90&I. + =&30) 15 30 45 90 100
0 1 1 1 2

Now we just need to use these values to select the proper result:

   >@{&('too cold';'OK';'too hot')@(30 90&I. +=&30) 15 30 45 90 100
too cold
OK
OK
OK
too hot

...

But this is probably a case of solving the wrong problem? The original
problem had to do with session management more than anything else.

Thanks,

-- 
Raul


On Sun, Jun 28, 2015 at 2:38 AM, Devon McCormick <[email protected]> wrote:
> Or you might want to abandon the clumsy "if...then...else" paradigm and do
> it in an array fashion:
>
>    (3 : '(''too cold'';''OK'';''too hot'')#~y=/:~y,30,90')"0 ] 10 20 39 30
> 31 89 90 91
> +--------+-------+
> |too cold|       |
> +--------+-------+
> |too cold|       |
> +--------+-------+
> |OK      |       |
> +--------+-------+
> |too cold|OK     |
> +--------+-------+
> |OK      |       |
> +--------+-------+
> |OK      |       |
> +--------+-------+
> |OK      |too hot|
> +--------+-------+
> |too hot |       |
> +--------+-------+
>
> This highlights the ambiguous cases where y is equal to the break-points.
>
> Not only that, but the array solution gives us a hint as to how we might
> generalize this further by supplying the break-points as our left argument:
>
>    (30 90) (4 : '(''too cold'';''OK'';''too hot'')#~y=/:~y,x')"_ 0 ] 10 20
> 39 30 31 89 90 91
> +--------+-------+
> |too cold|       |
> +--------+-------+
> |too cold|       |
> +--------+-------+
> |OK      |       |
> +--------+-------+
> |too cold|OK     |
> +--------+-------+
> |OK      |       |
> +--------+-------+
> |OK      |       |
> +--------+-------+
> |OK      |too hot|
> +--------+-------+
> |too hot |       |
> +--------+-------+
>
> The next most obvious step after this is to extend the left argument to
> include both the ('too cold';'OK';'too hot') labels with the breakpoints as
> the left argument.
>
>
>
> On Sun, Jun 28, 2015 at 2:02 AM, 'Bo Jacoby' via Programming <
> [email protected]> wrote:
>
>> Highlight the corrected program definition and type ctrl-E to execute the
>> highlighted text.
>>
>>
>>      Den 5:51 søndag den 28. juni 2015 skrev Raul Miller <
>> [email protected]>:
>>
>>
>>
>>  Oh, yes - my control-N comment assumed he was using jqt. If he was
>> using JHS it's different.
>>
>> Thanks,
>>
>> --
>> Raul
>>
>>
>> On Sat, Jun 27, 2015 at 11:28 PM, Joe Bogner <[email protected]> wrote:
>> > For throwaway definitions, the JHS (web-based ide) scratch window is good
>> > too.
>> > On Jun 27, 2015 11:20 PM, "Raul Miller" <[email protected]> wrote:
>> >
>> >> For multi-line definitions like this, you should be putting your
>> >> script in a file.
>> >>
>> >> Hit control-N to get a blank editor window.
>> >>
>> >> Thanks,
>> >>
>> >> --
>> >> Raul
>> >>
>> >>
>> >> On Sat, Jun 27, 2015 at 10:24 PM, Daniel Roe <[email protected]> wrote:
>> >> > I'm just learning J so this is a bit of a newbie question.
>> >> > 1) I open up the J session window
>> >> > 2) I type in a definition of a verb from the Learning J document -
>> >> Chapter 12...
>> >> >
>> >> > dog =: 3 : 0
>> >> > if. y>90 do. 'too hot'
>> >> > elseif. y<30 do. 'too cold'
>> >> > elseif. 1 do. 'OK'
>> >> > end.
>> >> > )
>> >> > It's the porridge - too hot - too cold - example - I called it dog
>> >> > Now I want to go back in and change the parameters a bit - for
>> example I
>> >> want to make too cold be < 40 not 30.3) I put the cursor in the
>> definition
>> >> and change the 30 to a 40
>> >> >
>> >> > 4) With the cursor I select the entire definition and then copy it
>> with
>> >> a CTRL-C
>> >> >
>> >> > 5) I hit he enter key until I get the waiting for input cursor down
>> >> below everything
>> >> > 6) I paste in the modified definition with a CTRL-V and hit enter
>> >> > 7) I get a syntax error message.
>> >> > I can't believe that one must re-type the entire definition just to
>> make
>> >> a change. What am I doing wrong?
>> >> > Dan
>> >> >
>> >> >
>> >> > ----------------------------------------------------------------------
>> >> > 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
>>
>
>
>
> --
> Devon McCormick, CFA
> ----------------------------------------------------------------------
> 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