[Bese-devel] string to list riddle

Pascal Bourguignon pjb at informatimago.com
Tue Jan 10 01:04:44 UTC 2006


Ties Stuij writes:
> I've got an absurd problem on my hands here that keeps me banging my
> head against the wall. I was just wondering if i am coping here with
> an obvious ucw environment misconception or that i am utterly
> clueless.
> 
> The problem is this: i'm trying to tie norvig's elisa code to a
> web-interface. I feed the output of a form into the eliza internals.
> The minor problem here is that the form output is a string and eliza
> expects a list of symbols. Norvig himself supplies a string-to-list
> convertor and everything works fine in the repl. HOWEVER, when i try
> this setup in a ucw page, the response is not recognized. I can play
> with the list created with string-to-list all i want: making a list
> out of the individual elements for example. it doens't matter, eliza
> won't recognize the sequence. On the other hand, if i play with a list
> a bit which was a list from the start, when i put it back together
> again it WILL be recognized. So there is something inheritly different
> about the string-to-list list. Mind you: only in the ucw environment.
> I loosened every pattern-match comparison in eliza to equalp: no
> change in the situation.
> 
> facts:
> - if i feed the eliza accessor a list in the page it returns the 
>   expected result
> - in the page the string is converted correctly to a list of symbols
> - everything works fine in the repl
> - but when on a page the list is converted by string-to-list and then
> is being fed to eliza, it is not recognized by the patternmatcher
> inside eliza
> - i tried a couple of string-to-list convertors, all working
> satisfactionally in the repl, on the page, but not recognized by eliza
> on the page
> 
> The situation is utterly absurd. Can someone make me sane again?
> Ties
>
> ps: for reference, one of the string-to-list functions
> 
> (defun read-line-no-punct (input)
>   (read-from-string (concatenate 'string "(" input ")" )))

You should post more code.

Check that you're receiving a correctly decoded data flow, with some
strategically placed PRINT calls. (Remember that PRINT returns its
argument, so you can easily enclose any subexpression in a PRINT).


(defun read-line-no-punct (input)
  (let ((*read-eval* nil)) ; IS A MINIMUM.
    (read-from-string (concatenate 'string "(" 
         (substitute #\/ #\: input) ; To avoid problems with packages.
          ")" ))))

but this gives awful results:

(mapcar
 (lambda (input) (handler-case (read-line-no-punct input)
                          (error (err) (terpri) (princ err) (print err))))
 '("An inocent line."
   "Let's start the fun, with a inocent looking sentence."
   "I say: Try this!" 
   "Try: #.(mapcar (function delete-file) (directory \"**;*.*\"))"
   "A 1/0 relation between you and me!"
   "Have a nice day (-:"
   ))

prints:

READ: comma is illegal outside of backquote
#<SYSTEM::SIMPLE-READER-ERROR #x2050619E> 
READ from #<INPUT STRING-INPUT-STREAM>: *READ-EVAL* = NIL does not allow the evaluation of (MAPCAR
 #'DELETE-FILE (DIRECTORY "**;*.*"))

#<SYSTEM::SIMPLE-READER-ERROR #x20508B96> 
division by zero

#<SYSTEM::SIMPLE-READER-ERROR #x2050AF0E> 
READ: input stream #<INPUT STRING-INPUT-STREAM> ends within an object

#<SYSTEM::SIMPLE-END-OF-FILE #x2050C7DE> 

returns:

((AN INOCENT LINE.)
 #<SYSTEM::SIMPLE-READER-ERROR #x204FABA6> 
 (I SAY/ TRY THIS!)
 #<SYSTEM::SIMPLE-READER-ERROR #x204FD59E>
 #<SYSTEM::SIMPLE-READER-ERROR #x204FF916>
 #<SYSTEM::SIMPLE-END-OF-FILE #x205011E6>)


You'd need to hack a readtable to read correctly most of the macro
characters including #\# and #\,, but really you should scan the
natural language text yourself.  This READ-FROM-STRING Q&D hack works
when you control the input, for a AI research prototype, but not for a
program available on the web!


-- 
__Pascal Bourguignon__                     http://www.informatimago.com/

HEALTH WARNING: Care should be taken when lifting this product,
since its mass, and thus its weight, is dependent on its velocity
relative to the user.



More information about the bese-devel mailing list