Newsgroups: comp.lang.clos
Path: cantaloupe.srv.cs.cmu.edu!nntp.club.cc.cmu.edu!hudson.lm.com!news.pop.psu.edu!news.cac.psu.edu!newsserver.jvnc.net!adl33cc!sbloch
From: sbloch@adl15.adelphi.edu (Stephen Bloch)
Subject: interning puzzle
Message-ID: <D49GI1.LCv@adl33cc.adelphi.edu>
Sender: news@adl33cc.adelphi.edu (USENET News System)
Nntp-Posting-Host: adl15.adelphi.edu
Organization: Adelphi University, Garden City, NY
Date: Sun, 19 Feb 1995 18:54:01 GMT
Lines: 38

I'm trying to set up a map between commands the user might type into an
interactive program and internal symbols.  I'm not really concerned about
case, nor about lots of error-checking, end-of-line detection, etc. -- I
just wanted something quick and dirty.  There are in fact fewer than ten
commands, each of which has a one-word name, so I thought "I'll just
read them with (read), then compare them with a particular symbol."
My first attempt looked like
(defconstant *command-map* '((start . start-cmd) (delete_file . del-cmd) ...)
...
(let ((matching (assoc (read) *command-map*)))
     (if matching
         (do-something-with (cdr matching))
         (error "Unrecognized command")))

This worked fine until I put it all inside a package, because the "START"
and "DELETE_FILE" and so on are interned in that package, so they're not
eql to the "START" and "DELETE_FILE" that (read) returned (which have no
package mentioned in their printnames).

The same problem arose when I rewrote things with eql-specialized
methods:
(defmethod internal-form ((name (eql 'start))) 'start-cmd)
(defmethod internal-form ((name (eql 'delete_file))) 'del-cmd)
...
(do-something-with (internal-form (read)))

Is there any way to do this without either (a) dropping the package or
(b) doing my own string-parsing from (read-line)?  Not that the latter
would be so horrible, but I don't think it should be necessary.  I'd
particularly like an easy-to-explain solution (dare I ask, one that
allows me to avoid the whole issue of interning?) so I can show it to
my beginning Lisp students.

--
                                                 Stephen Bloch
                                           sbloch@boethius.adelphi.edu
                                          (or sbloch@adl15.adelphi.edu)
                                        Math/CS Dept, Adelphi University
