a golden oldie challenge: Eliza
  Home FAQ Contact Sign in
comp.lang.functional only
 
Advanced search
POPULAR GROUPS

more...

comp.lang.functional Profile…
 Up
a golden oldie challenge: Eliza         


Author: Mark Tarver
Date: Feb 22, 2008 03:49

Having got 3936 LOC through a 4000 LOC implementation, I thought I'd
do some recreational
hacking and do an old old program I've not looked at for some time -
Eliza. You all know Eliza well enough for me not to have to spell it
out. The challenge is to implement or dig up an Eliza program (you
don't have to write it yourself) in your favourite FPL. Note that the
script that drives Eliza's responses should not be counted towards the
LOC count. Some constraints.

1. The script itself should be changeable by any novice. That is to
say that it should not
be a pile of hard-wired code written in the native language of
the program or require
deep programming skills.

2. The program should receive keyboard input from the user -
including the usual punctuation
and any characters he wants to enter without crashing.
Show full article (1.27Kb)
39 Comments
Re: a golden oldie challenge: Eliza         


Author: Mark Tarver
Date: Feb 22, 2008 03:59

On 22 Feb, 11:49, Mark Tarver ukonline.co.uk> wrote:
> Having got 3936 LOC through a 4000 LOC implementation, I thought I'd
> do some recreational
> hacking and do an old old program I've not looked at for some time -
> Eliza.   You all know Eliza well enough for me not to have to spell it
> out.  The challenge is to implement or dig up an Eliza program (you
> don't have to write it yourself) in your favourite FPL.  Note that the
> script that drives Eliza's responses should not be counted towards the
> LOC count.  Some constraints.
>
> 1.  The script itself should be changeable by any novice.  That is to
> say that it should not
>      be a pile of hard-wired code written in the native language of
> the program or require
>      deep programming skills.
>
> 2.  The program should receive keyboard input from the user -
> including the usual punctuation
>      and any characters he wants to enter without crashing.
> ...
Show full article (4.15Kb)
no comments
Re: a golden oldie challenge: Eliza         


Author: William James
Date: Feb 22, 2008 14:09

On Feb 22, 5:59 am, Mark Tarver ukonline.co.uk> wrote:
> On 22 Feb, 11:49, Mark Tarver ukonline.co.uk> wrote:
>
>> Having got 3936 LOC through a 4000 LOC implementation, I thought I'd
>> do some recreational
>> hacking and do an old old program I've not looked at for some time -
>> Eliza. You all know Eliza well enough for me not to have to spell it
>> out. The challenge is to implement or dig up an Eliza program (you
>> don't have to write it yourself) in your favourite FPL. Note that the
>> script that drives Eliza's responses should not be counted towards the
>> LOC count. Some constraints.
>
>> 1. The script itself should be changeable by any novice. That is to
>> say that it should not
>> be a pile of hard-wired code written in the native language of
>> the program or require
>> deep programming skills.
>
>> 2. The program should receive keyboard input from the user -
>> including the usual punctuation ...
Show full article (4.15Kb)
no comments
Re: a golden oldie challenge: Eliza         


Author: Mark Tarver
Date: Feb 22, 2008 17:12

On 22 Feb, 22:09, William James yahoo.com> wrote:
> On Feb 22, 5:59 am, Mark Tarver ukonline.co.uk> wrote:
>
>
>
>
>
>> On 22 Feb, 11:49, Mark Tarver ukonline.co.uk> wrote:
>
>>> Having got 3936 LOC through a 4000 LOC implementation, I thought I'd
>>> do some recreational
>>> hacking and do an old old program I've not looked at for some time -
>>> Eliza.   You all know Eliza well enough for me not to have to spell it
>>> out.  The challenge is to implement or dig up an Eliza program (you
>>> don't have to write it yourself) in your favourite FPL.  Note that the
>>> script that drives Eliza's responses should not be counted towards the
>>> LOC count.  Some constraints.
>
>>> 1.  The script itself should be changeable by any novice.  That is to
>>> say that it should not ...
Show full article (4.78Kb)
no comments
Re: a golden oldie challenge: Eliza         


Author: William James
Date: Feb 22, 2008 19:19

On Feb 22, 7:12 pm, Mark Tarver ukonline.co.uk> wrote:
> First I've seen Ruby used. Don't understand a damn thing of
> course :),
> but 55 LOC puts it top.
>
> Mark

Symbols begin with ":".

Lists (arrays to Rubyists) are enclosed in [], but they
can be omitted sometimes, e.g.:
a = 22,33,44

"<<" appends to a list:
[6,7,8] << 9
==>[6, 7, 8, 9]

The index of the first element in a list is 0:
[6,7,8][0]
==>6
Show full article (1.90Kb)
no comments
Re: a golden oldie challenge: Eliza         


Author: John Thingstad
Date: Feb 23, 2008 04:00

På Fri, 22 Feb 2008 23:09:58 +0100, skrev William James
yahoo.com>:
> On Feb 22, 5:59 am, Mark Tarver ukonline.co.uk> wrote:
>> On 22 Feb, 11:49, Mark Tarver ukonline.co.uk> wrote:
>>
>>> Having got 3936 LOC through a 4000 LOC implementation, I...
Show full article (4.50Kb)
no comments
Re: a golden oldie challenge: Eliza         


Author: Stevan Apter
Date: Feb 23, 2008 10:21

in q:

D:(("1 father|mother|brother|sister 2";"tell me about your 0.");
("1 am|i'm 2";"why are you 2|have you always been 2?");
("1 i 2";"why do you 2?");
("1 you 2";"we're talking about you, not me.|please don't be so personal"))

E:"|"vs"that's very interesting. do go on.|
tell me more|
i'm not sure i understand you fully|
can you elaborate on that?"

S:{(`$"|"vs first w where not b;raze w where b:(first each w:" "vs x)in"0123456789")}each D[;0]
R:"|"vs'D[;1]
P:{(y,x,z)(x,y)?z}[`$("you";"your";"yourself";"i'm";"i am");`$("i";"my";"myself";"you are";"you're")]

e:{w:(`$" "vs x except".?")except`; / words except punctuation, blanks
b:w in\:/:S[;0]; / boolean mask: words X rules
if[count[b]=i:(any each b)?1b;:E first 1?count E]; / if no key match on a rule, early exit
p:1_'(0,1+k:b[i]?1b)_`,w; / split input on key
r:{x first 1?count x}R i; / pick a rule
n:r first raze r ss/:"0123456789"; / which part of input to replace
ssr[r;n;" "sv string(),P each(w[k],p)"I"$n]} / construct reply
Show full article (5.70Kb)
no comments
Re: a golden oldie challenge: Eliza         


Author: Ken Tilton
Date: Feb 23, 2008 12:24

Stevan Apter wrote:
> in q:
>
> D:(("1 father|mother|brother|sister 2";"tell me about your 0.");
> ("1 am|i'm 2";"why are you 2|have you always been 2?");
> ("1 i 2";"why do you 2?");
> ("1 you 2";"we're talking about you, not me.|please don't be so
> personal"))
>
> E:"|"vs"that's very interesting. do go on.|
> tell me more|
> i'm not sure i understand you fully|
> can you elaborate on that?"
>
> S:{(`$"|"vs first w where not b;raze w where b:(first each w:" "vs
> x)in"0123456789")}each D[;0]
> R:"|"vs'D[;1]
> P:{(y,x,z)(x,y)?z}[`$("you";"your";"yourself";"i'm";"i
> am");`$("i";"my";"myself";"you are";"you're")]
> ...
Show full article (1.48Kb)
no comments
Re: a golden oldie challenge: Eliza         


Author: Stevan Apter
Date: Feb 23, 2008 13:42

thanks for asking ken.

e:{$[(#b)=i:(|/'b:(w@:&~(w:(`$" "\:x@&~x in".?"))in`)in\:/:A)?1b;E@*1?#E
" "~n:c@*,/(c:{x@*1?#x}C i)ss/:N;c
.q.ssr[c;n;" "/:$(),P'(w[k],p:1_'(0,1+k:b[i]?1b)_`,w)"I"$n]]}

it's just a single eye-watering case statement:

if no keyword match in A, then return a default response from E
else if no substitution in the response c picked from C, return c
else substitute and return

it's easier to break the q code into smaller chunks. a revised version
here: http://www.nsl.com/k/eliza.q

"Ken Tilton" optonline.net> wrote in message news:47c0813e$0$8080$607ed4bc@cv.net...
>
>
> Stevan Apter wrote:
>> in q:
>>
>> D:(("1 father|mother|brother|sister 2";"tell me about your...
Show full article (2.17Kb)
no comments
Re: a golden oldie challenge: Eliza         


Author: Szabolcs
Date: Feb 23, 2008 14:12

I'm not a programmer. I just wanted to have some fun, so I tried to
write a Mathematica version based on the Ruby version (the only one I
actually understood). I'm sure that this can be improved and written
in a nicer way, but here it goes: :-)

script = {
{__, u : "father" | "mother" | "brother" | "sister", ___} :> {"Tell
me about your " <> v <> "."},
{___, "am" | "i'm", u__} :> {"Why are you " <> v <> "?", "Have you
always been " <> v <> "?"},
{___, "i", u__} :> {"Why do you " <> v <> "?"},
{___, "you", ___} :> {"We're talking about you, not me", "Please
don't be so personal."},
{u___} :> {"That's very interesting. Do go on.", "Tell me more.",
"I'm not sure that I understand you fully.",
"Can you elaborate on that?",
"Why do you think that " <> v <> "?"}
};

script = script /. v :> processSegment[{u}];
Show full article (1.52Kb)
no comments
1 2 3 4