Yeah - I combined Dan's two scripts into "interactive.ijs" and handled this
problem thusly, making the last definition:
3 : 0 ''
if. IFCONSOLE do.
echo 'Welcome to psychotherapy!'
query r_plx ''
else.
echo=: 0 0&$@(1!:2&2)
echo 'Welcome to psychotherapy!'
query r_pl ''
end.
)
Instead of giving it all piecemeal, here's the whole script as I've
assembled it in one, easy-to-load package that works under both jconsole and
session manager:
NB.* interactive.ijs: example of character-based user prompt and input.
NB. From Dan Bron.
require 'strings'
IFCONSOLE_z_ =. IFCONSOLE_z_"_ :: (0 -: (11!:0) :: 0:) ''
IFUNIX_z_ =. 5 -: 9!:12''
9!:7^:IFCONSOLE '+++++++++|-'
init =. _&;
failsafe =. :: err =. [: (13!:11 ,&:< 13!:12) ''"_
Read =. 1!:1@:1:
StdOrErr =. 2: + IFUNIX * 5 - e.&0 _ NB. Windows: always use 2. Unix: 4 if
standard, 5 if error.
Print =. [ (1!:2 StdOrErr)~&>/
Loop =. (^:(_ -: >@:{.)) (^:_) NB. Could replace _ with a: to accumulate all
input lines
ReadPrint =. Read :. Print
R_PL =: failsafe (&.: ReadPrint) Loop failsafe (@:init)
R_PL =: 'R_PL' f.
NB. R_PL =: ( :: err) (&.: (1!:1@:1: :. ([(1!:2 (IFCONSOLE =: 0 -: (11!:0)
:: 0: '') { 2, 5: - e.&0 _)~&>/))) (^:(_ -: >@:{.)) (^:_) ( :: err =. [:
(13!:11 ,&:< 13!:12) ''"_) (@: (_&;) )
r_pl =: 1 : '3 : (''9!:29[1[9!:27 ''''('', (5!:5{.;:''u'') , '')R_PL
'''',5!:5{.;:''''y'''''')'
r_plx =: 1 : '3 : (''9!:29[1[9!:27 ''''2!:55 > {. ('', (5!:5{.;:''u'') ,
'')R_PL '''',5!:5{.;:''''y'''''')'
NB. r_plx is like r_pl but exits J at the end.
query =: verb define
y =. deb tolower y
if. 'quit' -: deb tolower y do.
0 ; 'bye!'
else.
_ ; 'Why do you say "', y , '"?'
end.
)
3 : 0 ''
if. IFCONSOLE do.
echo 'Welcome to psychotherapy!'
query r_plx ''
else.
echo=: 0 0&$@(1!:2&2) NB. Only defined IFCONSOLE.
echo 'Welcome to psychotherapy!'
query r_pl ''
end.
)
Regards,
Devon
On 4/12/07, Murray Eisenberg <[EMAIL PROTECTED]> wrote:
The suggested verb "query" won't work, even after r_pl.ijs is loaded,
because "echo" gives a value error!
P.S. How in an e-mail message can I easily quote a message from this
mailing list that I receive in digest form?
--
Murray Eisenberg [EMAIL PROTECTED]
Mathematics & Statistics Dept.
Lederle Graduate Research Tower phone 413 549-1020 (H)
University of Massachusetts 413 545-2859 (W)
710 North Pleasant Street fax 413 545-1801
Amherst, MA 01003-9305
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm
--
Devon McCormick, CFA
^me^ at acm.
org is my
preferred e-mail
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm