Newsgroups: comp.lang.apl Path: utzoo!utgpu!watserv1!watmath!ljdickey From: ljdickey@watmath.waterloo.edu (L.J.Dickey) Subject: Re: Eliza in J, revised Message-ID: <1991Feb19.023535.3612@watmath.waterloo.edu> Organization: University of Waterloo References: <1991Feb18.221411.21479@watmath.waterloo.edu> Date: Tue, 19 Feb 1991 02:35:35 GMT Lines: 117 This is a re-submission of a J program from Richard L.W. Brown of York University in Toronto. He wrote it as an exercise in learning to program in J and he has consented to its being posted to Usenet. You might find it instructive too. I saved the stuff below the line in a file called 'eliza' and gave the commands: J )script 'eliza' eliza '' The command )sscript 'eliza' may be used instead of )script 'eliza' for a less verbose startup. Lee Dickey o / _________ \/ ___________________ snip snip snip _____________________________ /\ o \ ''}:'Eliza the analyst.' ''}:'A simplified Eliza program similar to the one in the' ''}:'ABC PROGRAMMERS GUIDE by Guerts, Meertens, and Pemberton.' ''}:'Written in J by R.L.W. Brown. RLWBROWN at YORKVM1 (bitnet)' ''}:' ' ''}:'CONSTANTS AND UTILITY FUNCTIONS' end=.0$0 ALPH=. 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ?,!;.''"()/' LOWER=.'abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz? ' lowercase=.'(ALPH i. y.){LOWER'::'' say=.'y.(1!:2) 2'::'' listen=.';:lowercase(1!:1)1'::'' choose=.'say>(?$,y.){,y.'::'' has=.''::'($y.)>k=:<./y.i.x.' from=.'>k{y.'::'' if=.".> then=.{.< ''}:'ELIZA DIALOG FUNCTION' c=.0 1$'' c=.c,'say''Hello, I am Eliza. Tell me about yourself.''' c=.c,'say''"Bye" to finish.''' c=.c,'s=.listen ''''' c=.c,'if ((;:''bye'') e. s) then ''''''Bye, bye!''''}:$.=.end''' c=.c,'reply s}:$.=.2 3 4' eliza=.c ::'' ''}:'ELIZA REPLY FUNCTION' c=.0 1$' ' c=.c,'if (( where is any valid J expression.)'