Web Images Videos Maps News Shopping Google Mail more »
Recently Visited Groups | Help | Sign in
Google Groups Home
a golden oldie challenge: Eliza
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  Messages 1 - 25 of 41 - Collapse all  -  Translate all to Translated (View all originals)   Newer >
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Follow-up To:
Add Cc | Add Follow-up to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers that you hear
 
Mark Tarver  
View profile   Translate to Translated (View Original)
 More options 22 Feb 2008, 11:49
Newsgroups: comp.lang.lisp, comp.lang.functional
From: Mark Tarver <dr.mtar...@ukonline.co.uk>
Date: Fri, 22 Feb 2008 03:49:44 -0800 (PST)
Local: Fri 22 Feb 2008 11:49
Subject: a golden oldie challenge: Eliza
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.

During the Harrop Wars on comp.lang.lisp a lot of stuff was thrown
around about the desirability of pattern matching.  The challenge is
interesting because it involves a style of pattern-matching called
'segment pattern matching' that is not hard-wired into most FPLs and
I'd like to see how well different FPLs cope with something outside
the standard.

Oh last thing; don't get too uptight about this.  It's only a bit of
fun.

Mark


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message, you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Mark Tarver  
View profile   Translate to Translated (View Original)
 More options 22 Feb 2008, 11:59
Newsgroups: comp.lang.lisp, comp.lang.functional
From: Mark Tarver <dr.mtar...@ukonline.co.uk>
Date: Fri, 22 Feb 2008 03:59:02 -0800 (PST)
Local: Fri 22 Feb 2008 11:59
Subject: Re: a golden oldie challenge: Eliza
On 22 Feb, 11:49, Mark Tarver <dr.mtar...@ukonline.co.uk> wrote:

Well here is my shot at it in Qi.  Total LOC excluding script is 70
LOC. You should run it under Qi 9.2 (latest release) because the
system function 'read-chars-as-stringlist' had a bug that was patched
in that release.  My script is very boring ;).

I looked for a Haskell/ML equivalent and found zilch.  Norvig's PAIP
contains a Lisp version in two files (eliza and eliza1) that is about
150 LOC excluding comments and script.

Mark
___________________________________________________________
(set *script* [
               [[X "like" Y] ["Why" "do" "you" "like" Y "?"]]
               [[X "father" Y] ["Tell me about your father."]]
               [[X] ["That's very interesting. Do go on."]]])

(define eliza
  -> (do (output "hi~%?- ") (eliza-loop (user) (value *script*))))

(define eliza-loop
  User Script -> (let Responses (map (/. S (pmatch User S)) Script)
                      Interesting (remove-if no-match? Responses)
                      ScriptError (if (empty? Interesting)
                                      (error "script failure!")
                                      _)
                      Choice (nth (+ (random (length Interesting)) 1)
Interesting)
                      Response (respond-with Choice)
                      Output (output "~{~A ~}~%~%?- " Response)
                      (eliza-loop (user) Script)))

(define respond-with
  [[] R] -> R
  [[[X V] | B] R] -> (respond-with [B (rep X R V)]))

(define no-match?
  [#\Escape _] -> true
  _ -> false)

(define user
  -> (read-chars-as-stringlist (user-loop (read-char _)) whitespace?))

(define whitespace?
  #\Space -> true
  #\Tab -> true
  #\, -> true
  #\. -> true
  _ -> false)

(define user-loop
  #\Newline -> []
  C -> [C | (user-loop (read-char _))])

(define remove-if
  _ [] -> []
  F [X | Y] -> (if (F X) (remove-if F Y) [X | (remove-if F Y)]))

(define pmatch
  User [I R] -> [(pmatch-help I User []) R])

(define pmatch-help
   X X B -> B
   [X | Y] [X | Z] B -> (pmatch-help Y Z B)
   [X | Y] Z B <- (let NilBind (nilbind X B)
                       ValX (value-in X NilBind)
                       (pmatch-help (rep X Y ValX) Z NilBind))
                       where (variable? X)
   [X | Y] [W | Z] B <- (pmatch-help [X | Y] Z (consbind X W B))
                         where (variable?
X)
   _ _ _ -> #\Escape)

(define nilbind
  X [] -> [[X []]]
  X [[X V] | B] -> [[X V] | B]
  X [Y | Z] -> [Y | (nilbind X Z)])

(define consbind
  X W [] -> [[X [W]]]
  X W [[X V] | B] -> [[X (append V [W])] | B]
  X W [Y | B] -> [Y | (consbind X W B)])

(define rep
  _ [] _ -> []
  X [X | Y] V -> (append V (rep X Y V))
  X [Y | Z] V -> [Y | (rep X Z V)])

(define value-in
  X B -> (head (tail (assoc X B))))


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message, you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
William James  
View profile   Translate to Translated (View Original)
 More options 22 Feb 2008, 22:09
Newsgroups: comp.lang.lisp, comp.lang.functional
From: William James <w_a_x_...@yahoo.com>
Date: Fri, 22 Feb 2008 14:09:58 -0800 (PST)
Local: Fri 22 Feb 2008 22:09
Subject: Re: a golden oldie challenge: Eliza
On Feb 22, 5:59 am, Mark Tarver <dr.mtar...@ukonline.co.uk> wrote:

I added some features and wrote it in Ruby.

Sample session:

? Hi. I'm going to be your worst nightmare.
Why are you going to be my worst nightmare?
? I think you're full of it.
Why do you think I am full of it?
? My mother told me so.
Tell me about your mother.
? No. You tell me about yours.
We're talking about you, not me.
? You're obviously retarded.
Please don't be so personal.
? Damn your eyes!
I'm not sure that I understand you fully.
? Understand a kick in the pants?
Can you elaborate on that?
? I always ignore idiots.
Why do you always ignore idiots?
? I am afraid of dinosaurs.
Have you always been afraid of dinosaurs?
? quit

Script =
  [[:x, ["father",'mother','brother','sister'], :y],
    ["Tell me about your ", :_, "."]],
  [[:x, ["am", "i'm"], :y], [["Why are you", :y, "?"],
                             ["Have you always been", :y, "?"]]],
  [[:x, "I", :y], ["Why do you", :y, "?"]],
  [[:x, 'you', :y], [["We're talking about you, not me."],
             ["Please don't be so personal."]]],
  [[:x], [["That's very interesting. Do go on."],
        ["Tell me more."],
        ["I'm not sure that I understand you fully."],
        ["Can you elaborate on that?"] ]]

def change_person s
  h = { 'I','you',  'my','your', 'myself','yourself',
    'you are','I am', "you're", 'I am' }
  tmp = s.scan(/you are|you're|\w+|\W+/).map{|s|
    h[s] or h.invert[s] or s }
  tmp[-1] = "me"  if "I" == tmp[-1]
  tmp.join
end

patterns, symbols, replies = [], [], []

Script.each{|ary|
  syms = []
  patterns <<  Regexp.new( "^" +
    ary[0].map{|x|
      case x
        when Symbol
          syms << x
          "(.*?)"
        when String
          "\\b#{ x }\\b"
        when Array
          syms << :_
          "\\b(#{ x.join('|') })\\b"
        else
          ".*?"
      end
    }.join + "$", true ) # Case-insensitive.
  symbols << syms
  ary[1] = ary[1].sort_by{ rand }  if ary[1][0].is_a? Array
  replies << ary[1]

}

while true
  print "? "
  resp = gets.strip.sub(/[.!?,;]+$/, "")
  break if 'quit' == resp
  patterns.each_with_index{|pat,i|
    if match_data = resp.match( pat )
      reply = replies[i]
      if reply[0].is_a? Array
        # Rotate replies for variety.
        reply.push( reply.shift )
        reply = reply[0]
      end
      captures = match_data.captures.map{|s| change_person s}
      # Create associative array mapping symbols to values.
      t = Hash[ *symbols[i].zip( captures ).flatten ]
      puts reply.map{|x| x.is_a?(Symbol) ? t[x] : x }.join
      break
    end
  }
end

    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message, you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Mark Tarver  
View profile   Translate to Translated (View Original)
 More options 23 Feb 2008, 01:12
Newsgroups: comp.lang.lisp, comp.lang.functional
From: Mark Tarver <dr.mtar...@ukonline.co.uk>
Date: Fri, 22 Feb 2008 17:12:49 -0800 (PST)
Local: Sat 23 Feb 2008 01:12
Subject: Re: a golden oldie challenge: Eliza
On 22 Feb, 22:09, William James <w_a_x_...@yahoo.com> wrote:

First I've seen Ruby used.  Don't understand a damn thing of
course :),
but 55 LOC puts it top.

Mark


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message, you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
William James  
View profile   Translate to Translated (View Original)
 More options 23 Feb 2008, 03:19
Newsgroups: comp.lang.lisp, comp.lang.functional
From: William James <w_a_x_...@yahoo.com>
Date: Fri, 22 Feb 2008 19:19:31 -0800 (PST)
Local: Sat 23 Feb 2008 03:19
Subject: Re: a golden oldie challenge: Eliza
On Feb 22, 7:12 pm, Mark Tarver <dr.mtar...@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

The array method ".join" is almost self-explanatory:
  ['tip', '-', 'top'].join
      ==>"tip-top"
  ['tip', '-', 'top'].join( '***' )
      ==>"tip***-***top"

Anonymous code blocks are enclosed in {..} or do ... end.

The parameters of the code block are enclosed in |...|.
In this example, the parameter is "n":
  [6,7,8].map{|n|  n * 2 }
      ==>[12, 14, 16]

In a different context {...} indicates a hash (associative
array):
  h = {'foo',44,  'bar',55, 'boo',66}
      ==>{"boo"=>66, "foo"=>44, "bar"=>55}
It's clearer but more tedious to separate key-value pairs
with "=>":
  h = {'foo'=>44,  'bar'=>55, 'boo'=>66}
      ==>{"boo"=>66, "foo"=>44, "bar"=>55}

Let's consider two lines:
  tmp = s.scan(/you are|you're|\w+|\W+/).map{|s|
    h[s] or h.invert[s] or s }

".scan" operates on the string s, producing a list of
substrings that are matched by the regular expression
"/you are|you're|\w+|\W+/".  The pipe symbol "|" functions
as OR; "\w" matches a word character; "\W" matches a
non-word character.  Example:
  "you are willy-nilly, yes?".scan( /you are|you're|\w+|\W+/ )
      ==>["you are", " ", "willy", "-", "nilly", ", ", "yes", "?"]
Next, ".map" attempts to perform substitutions using the
key-value pairs of the hash "h".  It makes good use of the
method ".invert", which swaps each key with its value:
  {'foo',22, 'bar',33}
      ==>{"foo"=>22, "bar"=>33}
  {'foo',22, 'bar',33}.invert
      ==>{33=>"bar", 22=>"foo"}


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message, you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
John Thingstad  
View profile   Translate to Translated (View Original)
 More options 23 Feb 2008, 12:00
Newsgroups: comp.lang.lisp, comp.lang.functional
From: "John Thingstad" <jpth...@online.no>
Date: Sat, 23 Feb 2008 13:00:30 +0100
Local: Sat 23 Feb 2008 12:00
Subject: Re: a golden oldie challenge: Eliza
På Fri, 22 Feb 2008 23:09:58 +0100, skrev William James  
<w_a_x_...@yahoo.com>:

Have you tried ALICE?

--------------
John Thingstad


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message, you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Stevan Apter  
View profile   Translate to Translated (View Original)
 More options 23 Feb 2008, 18:21
Newsgroups: comp.lang.lisp, comp.lang.functional
From: "Stevan Apter" <encryptednos...@nsl.com>
Date: Sat, 23 Feb 2008 13:21:00 -0500
Subject: Re: a golden oldie challenge: Eliza
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

in k it's about half the size, but i'll spare you.


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message, you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Ken Tilton  
View profile   Translate to Translated (View Original)
 More options 23 Feb 2008, 20:24
Newsgroups: comp.lang.lisp, comp.lang.functional
From: Ken Tilton <kennytil...@optonline.net>
Date: Sat, 23 Feb 2008 15:24:42 -0500
Local: Sat 23 Feb 2008 20:24
Subject: Re: a golden oldie challenge: Eliza

I'd love to see it, or a link to any other sample K code. I recall
seeing a one page implementation of a spreadsheet, that was wild.

kenny


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message, you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Stevan Apter  
View profile   Translate to Translated (View Original)
 More options 23 Feb 2008, 21:42
Newsgroups: comp.lang.lisp, comp.lang.functional
From: "Stevan Apter" <encryptednos...@nsl.com>
Date: Sat, 23 Feb 2008 16:42:31 -0500
Local: Sat 23 Feb 2008 21:42
Subject: Re: a golden oldie challenge: Eliza
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


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message, you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Szabolcs  
View profile   Translate to Translated (View Original)
 More options 23 Feb 2008, 22:12
Newsgroups: comp.lang.lisp, comp.lang.functional
From: Szabolcs <szhor...@gmail.com>
Date: Sat, 23 Feb 2008 14:12:17 -0800 (PST)
Local: Sat 23 Feb 2008 22:12
Subject: Re: a golden oldie challenge: Eliza

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}];

stripPunct[s_String] :=
 FixedPoint[
  If[MatchQ[StringTake[#, -1], "!" | "?" | "." | ";" | " "],
     StringDrop[#, -1], #] &,
  s]

processSegment[s_] :=
 StringJoin@Riffle[
   s /. {"I" -> "you", "my" -> "your", "your" -> "my", "myself" ->
"yourself",
         "you are" -> "I am", "you're" -> "I am", "you" -> "me"},
   " "]

While[StringLength[str = InputString[]] > 0,
 With[{ss = StringSplit@stripPunct@ToLowerCase@str},
  Print@RandomChoice@RandomChoice[ ss /. List /@ Select[script,
MatchQ[ss, First[#]] &] ]
 ]]

Note: It is recommended to run this from the command line instead of
the Front End, otherwise input will be read through an ugly popup
window.


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message, you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Szabolcs  
View profile   Translate to Translated (View Original)
 More options 23 Feb 2008, 22:26
Newsgroups: comp.lang.lisp, comp.lang.functional
From: Szabolcs <szhor...@gmail.com>
Date: Sat, 23 Feb 2008 14:26:03 -0800 (PST)
Local: Sat 23 Feb 2008 22:26
Subject: Re: a golden oldie challenge: Eliza
On Feb 23, 11:12 pm, Szabolcs <szhor...@gmail.com> wrote:

> so I tried to write a Mathematica version

I found a very old (from '92) implementation here:
http://140.177.205.65/infocenter/MathSource/1818/

    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message, you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Ben Bacarisse  
View profile   Translate to Translated (View Original)
 More options 24 Feb 2008, 00:01
Newsgroups: comp.lang.lisp, comp.lang.functional
From: Ben Bacarisse <ben.use...@bsb.me.uk>
Date: Sun, 24 Feb 2008 00:01:08 +0000
Local: Sun 24 Feb 2008 00:01
Subject: Re: a golden oldie challenge: Eliza

Szabolcs <szhor...@gmail.com> writes:
> On Feb 23, 11:12 pm, Szabolcs <szhor...@gmail.com> wrote:
>> so I tried to write a Mathematica version

> I found a very old (from '92) implementation here:

I find it slightly sad that a program from '92 is considered very old!
Especially in this context since Eliza dates from about '66, I think.

--
Ben.


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message, you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Ken Tilton  
View profile   Translate to Translated (View Original)
 More options 24 Feb 2008, 01:55
Newsgroups: comp.lang.lisp, comp.lang.functional
From: Ken Tilton <kennytil...@optonline.net>
Date: Sat, 23 Feb 2008 20:55:56 -0500
Local: Sun 24 Feb 2008 01:55
Subject: Re: a golden oldie challenge: Eliza

Stevan Apter wrote:
> 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]]}

Wonderful. I will post this over on the Arc forum, I think they are
headed your way.

So how big a chunk can a K guru toss off without taking a breath, if you
will? I suppose it is like any language, developing bits and pieces
before connecting it all. My suspicion is one can get off more
functionality simply from the lower character count, once they are all
known fluently.

kenny

--
http://smuglispweeny.blogspot.com/
http://www.theoryyalgebra.com/

"In the morning, hear the Way;
  in the evening, die content!"
                     -- Confucius


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message, you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
William James  
View profile   Translate to Translated (View Original)
 More options 24 Feb 2008, 04:14
Newsgroups: comp.lang.lisp, comp.lang.functional
From: William James <w_a_x_...@yahoo.com>
Date: Sat, 23 Feb 2008 20:14:36 -0800 (PST)
Local: Sun 24 Feb 2008 04:14
Subject: Re: a golden oldie challenge: Eliza
On Feb 22, 5:49 am, Mark Tarver <dr.mtar...@ukonline.co.uk> wrote:

Here's a shorter Ruby version.  Regular expressions are used
in the script.

Script =
  [ /father|mother|brother|sister/i, "Tell me about your 0."],
  [ /\b(am|i'm) (.*)/i, ["Why are you 2?","Have you always been 2?"]],
  [ /\bI was (.*)/i, ["Why were you 1?","I can't believe you were
1."]],
  [ /\bI will (.*)/i, "Do you think it's wise to 1?"],
  [ /\bI (.*)/i, "Why do you 1?" ],
  [ /\b(you|your|yours)\b/i, ["We're talking about you, not me.",
             "Please don't be so personal."]],
  [ /.*/, ["That's very interesting. Do go on.",
        "Tell me more.",
        "I'm not sure that I understand you fully.",
        "Can you elaborate on that?" ]]

def change_person s
  h = { 'I','you',  'my','your', 'myself','yourself',
    'you are','I am', "you're","I am" }
  s.scan(/you are|you're|\w+|\W+/).map{|s|
    h[s] or h.invert[s] or s }.join.sub( / I$/, " me" )
end

while true
  print "? "
  break if (resp = gets.strip.sub(/[.!?,;]+$/, "")) == 'quit'
  Script.each{|ary|
    if (md = resp.match( ary[0] ).to_a) != []
      t = Array( ary[1] )
      # Replies are rotated for variety.
      puts t.push(t.shift)[0].gsub(/\d/){change_person md[$&.to_i]}
      break
    end   }
end


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message, you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Szabolcs  
View profile   Translate to Translated (View Original)
 More options 24 Feb 2008, 09:51
Newsgroups: comp.lang.lisp, comp.lang.functional
From: Szabolcs <szhor...@gmail.com>
Date: Sun, 24 Feb 2008 01:51:00 -0800 (PST)
Subject: Re: a golden oldie challenge: Eliza
On Feb 24, 1:01 am, Ben Bacarisse <ben.use...@bsb.me.uk> wrote:

> Szabolcs <szhor...@gmail.com> writes:
> > On Feb 23, 11:12 pm, Szabolcs <szhor...@gmail.com> wrote:
> >> so I tried to write a Mathematica version

> > I found a very old (from '92) implementation here:

> I find it slightly sad that a program from '92 is considered very old!
> Especially in this context since Eliza dates from about '66, I think.

It depends on the language.  Mathematica came a long way since 1992.

    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message, you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Mark Tarver  
View profile   Translate to Translated (View Original)
 More options 24 Feb 2008, 11:59
Newsgroups: comp.lang.lisp, comp.lang.functional
From: Mark Tarver <dr.mtar...@ukonline.co.uk>
Date: Sun, 24 Feb 2008 03:59:56 -0800 (PST)
Local: Sun 24 Feb 2008 11:59
Subject: Re: a golden oldie challenge: Eliza

> 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]]}

Wow, looks like APL - also famous for inscrutable 1 liners.

Nothing from the big players Haskell, O'Caml & ML so far.

So far I've got

Lisp                       150 LOC  ................ Peter Norvig
Qi (slightly revised)  63 LOC   .................Mark Tarver
Ruby                      53 LOC   .................William James
Q                           10 LOC   ..................Steven Apter
K                             3 LOC  ...................Steven Apter

Mark


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message, you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Mark Tarver  
View profile   Translate to Translated (View Original)
 More options 24 Feb 2008, 12:06
Newsgroups: comp.lang.lisp, comp.lang.functional
From: Mark Tarver <dr.mtar...@ukonline.co.uk>
Date: Sun, 24 Feb 2008 04:06:09 -0800 (PST)
Local: Sun 24 Feb 2008 12:06
Subject: Re: a golden oldie challenge: Eliza
Sorry I missed a couple of later attempts

Lisp                       150 LOC  ................ Peter Norvig
Qi (slightly revised)  63 LOC   .................Mark Tarver
Ruby                      53 LOC   .................William James
Q                           10 LOC   ..................Steven Apter
K                             3 LOC  ...................Steven Apter
Ruby (again)            17 LOC ...................William James
Mathematica            20 LOC .................. Szabolcs

Mark


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message, you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Stevan Apter  
View profile   Translate to Translated (View Original)
 More options 24 Feb 2008, 12:44
Newsgroups: comp.lang.lisp, comp.lang.functional
From: "Stevan Apter" <encryptednos...@nsl.com>
Date: Sun, 24 Feb 2008 07:44:32 -0500
Local: Sun 24 Feb 2008 12:44
Subject: Re: a golden oldie challenge: Eliza

i now prefer developing in q, which is k without ambivalence (symbols denote
binary functions only, unary functions have keywords.)  

based on what i've seen, my guess is that this problem has a k solution
half the size of mine, given a better representation of the prompt-respond
script.  in general, that seems to be the key to good k (and as mark observed,
APL) programming:  tune your data to the primitives.  


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message, you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
William James  
View profile   Translate to Translated (View Original)
 More options 24 Feb 2008, 13:30
Newsgroups: comp.lang.lisp, comp.lang.functional
From: William James <w_a_x_...@yahoo.com>
Date: Sun, 24 Feb 2008 05:30:38 -0800 (PST)
Local: Sun 24 Feb 2008 13:30
Subject: Re: a golden oldie challenge: Eliza
On Feb 24, 6:06 am, Mark Tarver <dr.mtar...@ukonline.co.uk> wrote:

> Sorry I missed a couple of later attempts

> Lisp                       150 LOC  ................ Peter Norvig
> Qi (slightly revised)  63 LOC   .................Mark Tarver
> Ruby                      53 LOC   .................William James
> Q                           10 LOC   ..................Steven Apter
> K                             3 LOC  ...................Steven Apter
> Ruby (again)            17 LOC ...................William James
> Mathematica            20 LOC .................. Szabolcs

> Mark

The K version doesn't do everything that the Ruby
versions do.  It doesn't change "I" in the user's
response to "you" when throwing it back at the user,
for example.

When there are multiple possible replies to a user's
input, the Ruby program rotates those replies so that
not one will be repeated until all have been used.


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message, you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Stevan Apter  
View profile   Translate to Translated (View Original)
 More options 24 Feb 2008, 13:59
Newsgroups: comp.lang.lisp, comp.lang.functional
From: "Stevan Apter" <encryptednos...@nsl.com>
Date: Sun, 24 Feb 2008 08:59:51 -0500
Local: Sun 24 Feb 2008 13:59
Subject: Re: a golden oldie challenge: Eliza
yes it does.

prompts:

e"hi. i'm going to be your worst nightmare"
e"i think you're full of it."
e"my mother told me so."
e"no. you tell me about yours."
e"you're obviously retarded."
e"damn your eyes!"
e"understand a kick in the pants?"
e"i always ignore idiots."
e"i am afraid of dinosaurs"

responses:

"have you always been going to be my worst nightmare?
"why do you think i am full of it?"
"tell me about your mother."
"please don't be so personal."
"can you elaborate on that?"
"can you elaborate on that?"
"that's very interesting.  do go on."
"why do you always ignore idiots?"
"have you always been afraid of dinosaurs?"

a few observations:

the 'i' function gives you prompt-and-respond in the console by
call 'e' until the user gives no prompt:

i:{while[count r:read0 0;-1"? ",e r;]}

the 'P' function maps first- and second-person:

P:{(y,x,z)(x,y)?z}.`$(("you";"your";"yourself";"i'm";"i am");("i";"my";"myself";"you are";"you're"))

instead of rotating multiple-responses, the k version picks a
response randomly from the set.  this is less predictable than
rotation.

but i'm not surprised that the ruby version is so small.  it's
a nice language, and i like the enthusiasm of its practitioners.


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message, you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
William James  
View profile   Translate to Translated (View Original)
 More options 24 Feb 2008, 14:22
Newsgroups: comp.lang.lisp, comp.lang.functional
From: William James <w_a_x_...@yahoo.com>
Date: Sun, 24 Feb 2008 06:22:31 -0800 (PST)
Local: Sun 24 Feb 2008 14:22
Subject: Re: a golden oldie challenge: Eliza

Stevan Apter wrote:
> 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

This does so little that it should be no more than 2 lines.
In Ruby:

S =
  [ /father|mother|brother|sister/i, "Tell me about your 0."],
  [ /\b(am|i'm) (.*)/i, ["Why are you 2?","Have you always been 2?"]],
  [ /\bI was (.*)/i, ["Why were you 1?","I can't believe you were
1."]],
  [ /\bI will (.*)/i, "Do you think it's wise to 1?"],
  [ /\bI (.*)/i, "Why do you 1?" ],
  [ /\b(you|your|yours)\b/i, ["We're talking about you, not me.",
             "Please don't be so personal."]],
  [ /.*/, ["That's very interesting. Do go on.",
        "Tell me more.",
        "I'm not sure that I understand you fully.",
        "Can you elaborate on that?" ]]

(gets;sub(/[.!?,; ]+$/,"");x=Array(S.find{|a|$m=$_.match(a[0])}[1])
puts x[rand(x.size)].gsub(/\d/){$m.to_a[$&.to_i]}) while 9

Although cryptic, it should make more sense to most programmers
than the K code.


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message, you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Stevan Apter  
View profile   Translate to Translated (View Original)
 More options 24 Feb 2008, 14:37
Newsgroups: comp.lang.lisp, comp.lang.functional
From: "Stevan Apter" <encryptednos...@nsl.com>
Date: Sun, 24 Feb 2008 09:37:17 -0500
Local: Sun 24 Feb 2008 14:37
Subject: Re: a golden oldie challenge: Eliza
the use of regular expressions can certainly make the code smaller,
as your example demonstrates.  i wonder though whether it is entirely
in keeping with the spirit of the exercise, which requires that:

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.

not that it would help make the k code shorter, since regexp isn't
built into k.


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message, you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
William James  
View profile   Translate to Translated (View Original)
 More options 24 Feb 2008, 14:42
Newsgroups: comp.lang.lisp, comp.lang.functional
From: William James <w_a_x_...@yahoo.com>
Date: Sun, 24 Feb 2008 06:42:47 -0800 (PST)
Local: Sun 24 Feb 2008 14:42
Subject: Re: a golden oldie challenge: Eliza

Stevan Apter wrote:
> yes it does.

What does what?  Please don't top-post.

The K (not the Q) program was:

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]]}

I don't see "you", "your", "my", "myself", "yourself", etc.
So how can it change "your" to "my"?
I was talking about the K program; you're talking about the Q program.

> a few observations:

> the 'i' function gives you prompt-and-respond in the console by
> call 'e' until the user gives no prompt:

> i:{while[count r:read0 0;-1"? ",e r;]}

I was talking about the K program; you're talking about the Q program.

> the 'P' function maps first- and second-person:

> P:{(y,x,z)(x,y)?z}.`$(("you";"your";"yourself";"i'm";"i am");("i";"my";"myself";"you are";"you're"))

So this will change "your" to "my".  Will it, like the Ruby program,
change "my" to "your"?

> instead of rotating multiple-responses, the k version picks a
> response randomly from the set.  this is less predictable than
> rotation.

That has the defect of possibly repeating the same response
immediately instead of cycling through all of the responses
before repeating.


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message, you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
William James  
View profile   Translate to Translated (View Original)
 More options 24 Feb 2008, 14:57
Newsgroups: comp.lang.lisp, comp.lang.functional
From: William James <w_a_x_...@yahoo.com>
Date: Sun, 24 Feb 2008 06:57:22 -0800 (PST)
Local: Sun 24 Feb 2008 14:57
Subject: Re: a golden oldie challenge: Eliza
On Feb 24, 8:37 am, "Stevan Apter" <encryptednos...@nsl.com> wrote:

> the use of regular expressions can certainly make the code smaller,
> as your example demonstrates.  i wonder though whether it is entirely
> in keeping with the spirit of the exercise, which requires that:

> 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.

I understand your misgivings, and I considered that myself.
Regular expressions are used in many programming languages and
Unix utilities (awk, Perl, grep, sed, etc.).  All good text
editors support them, so anyone who is serious about using
computers should familiarize himself with them.  For example,
say he's editing a large file and wants to find a line that
has "foo" followed later in the line by "bar"; he'd simply
search for "foo.*bar".  How would that be done without
regular expressions?  I don't think that learning about
regular expressions means learning "deep programming skills".
But yes, using my shorter program would be harder for
a novice.


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message, you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Dimitre Liotev  
View profile   Translate to Translated (View Original)
 More options 24 Feb 2008, 15:00
Newsgroups: comp.lang.lisp, comp.lang.functional
From: Dimitre Liotev <no...@email.com>
Date: Sun, 24 Feb 2008 10:00:29 -0500
Local: Sun 24 Feb 2008 15:00
Subject: Re: a golden oldie challenge: Eliza

Mark Tarver <dr.mtar...@ukonline.co.uk> writes:
> Sorry I missed a couple of later attempts

> Lisp                       150 LOC  ................ Peter Norvig
> Qi (slightly revised)  63 LOC   .................Mark Tarver
> Ruby                      53 LOC   .................William James
> Q                           10 LOC   ..................Steven Apter
> K                             3 LOC  ...................Steven Apter
> Ruby (again)            17 LOC ...................William James
> Mathematica            20 LOC .................. Szabolcs

> Mark

So K wins the competition in brevity, but does the ability to squeeze
code into illegible character blobs say anything about the suitability
of a programming language for writing readable and understandable
programs? I'd rather follow the principle that "Programs must be written
for people to read, and only incidentally for machines to execute."...

--
Dimitre Liotev
(format t "~{~a~}" (reverse '("et" "n" "in." "a" "zn" "@" "l" "d")))


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message, you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Messages 1 - 25 of 41   Newer >
« Back to Discussions « Newer topic     Older topic »

Google Groups - Google Home - Terms of Service - Privacy Policy
©2009 Google