Newsgroups: comp.lang.apl
Path: watmath!watserv2.uwaterloo.ca!torn!cs.utexas.edu!zaphod.mps.ohio-state.edu!uunet.ca!unixbox!telly!moore!torsqnt!jtsv16!itcyyz!yrloc!hui
From: hui@yrloc.ipsa.reuter.COM (Roger Hui)
Subject: Re: a useful (?) example of J
Message-ID: <1992Oct24.191654.1987@yrloc.ipsa.reuter.COM>
Organization: Iverson Software Inc.
References: <qmdbms.719175826@gsusgi1.gsu.edu>
Date: Sat, 24 Oct 92 19:16:54 GMT
Lines: 38

Brian Schott writes:
 
> Within an explicitly defined function (variable) I would like to
> either continue with the next line of the function or exit from
> the function, depending on the user's numerical keyboard input.
> The function uses 1!:1 to read the keyboard.  Suite ($.) must be
> set to empty in order to exit or it is unchanged if an exit is
> not needed (except that by the time suite is accessed it needs
> to be beheaded (}.). See the example dummy function below.
>    kb =. 1
>    read =. 1!:1
>    t =. 0 0$''
>    t =. t, 'in =. ". read kb'
>    t =. t, 'cont =. >'''' ; ": }. $.'
>    t =. t, '$. =. ". (0 <: in){cont'
>    t =. t, 'y. + in'
 
>    ( t : '') 7
> NB. at this point I enter either a positive or negative number at kb.
 
If I understand the question, the problem can be solved more simply by
$.=.(0<:in)#$. .  Thus:
 
   t=.i.0 0
   t=.t, 'in =. ". read kb'
   t=.t, '$.=.(0<:in)#$.'
   t=.t, 'y.+in'
   f0 =. x : ''
 
In fact, to compute exactly the function presented in the msg,
there is no need to use $. at all.  For example:
 
   f1 =. 'y.+(0<:in)#in=.".read 1' : ''
   f2 =. + (0&<: # ])@".@read@1:

------------------------------------
Roger Hui, Iverson Software Inc., 33 Major Street, Toronto, Ontario  M5S 2K9
Phone: (416) 925 6096;  Fax: (416) 488 7559
