Use of symbols for "words" -- was Avoiding eval

From: George Orwell (Use-Author-Supplied-Address-Header_at_[127.1)
Date: 03/06/04


Date: Sat,  6 Mar 2004 13:50:42 +0100 (CET)


>Thomas A. Russ, USC/Information Sciences Institute
>Although not related to the question you asked, I wonder why you are
>using strings for your various categories rather than symbols.

I get into lots of trouble using "Symbols" for two main reasons.
reading from a file may produce a list of tokens like
'(cat003.jpg 98E75432 212000 siamese may 1989 7.800)

1, the lisp I am using decides if a token is a symbol, number or potential number
depending on its constituents. For instance '2e34 is treated as a number.
Some innocent looking tokens represent numbers so large lispworks 4.2 could
not swallow them with a read-base/print-base of 10.

What I think I need is a mechanism to cause lisp to interpret all tokens in context as
symbols. ie wrap the token in #\| 's and I have not figured out how.
 I have experimented with set-syntax-from-char to give digits alphabetic traits -
(did not work for me)
I also tried setting an illegal read-base but that did not work either.
I have not found the place which lisp uses to decide if a token is a number or a
symbol.

2, Interning everything in sight safely probably requires a knowledge of packages I do
not yet possess.

I have good control of the tokens being used in the current task, so I interpreted
 your question as a suggestion and used tokens instead. My function does not quite
do what I want...
It is o.k. for now but,
essential, for more general use would be to have the number tokens reproduced
                   exactly as they appear in the token list,
nice, would be to preserve case.

(Defun cat-tok-list (list &optional (sep-char ""))
  (if (eql (cdr list) nil) (car list)
    (intern (apply #'concatenate 'string
                   (let* ((Toks (Map 'list 'write-to-string list))
;; 'write-to-string stops an error when a number is encountered
;;but the string returned is not what I want
;; using 'string causes an error when a number is encountered
;;but allows strings to be supplied as args
                          (Seps (fill (cdr (copy-list List)) (string sep-char)))
                          (stringarg (fill (copy-list List) 'string)))
                     (map-into toks #'concatenate stringarg toks seps))))))

(cat-tok-list '(aaa 2e45 bbb) #\-) ==>
AAA-2.0E45-BBB
NIL

desired result --> aaa-2e45-bbb

Do I perservere with the direction I am headed and perhaps use a
typecase function on each of the arguments then somehow arrange for the
any evaluation to return what I want, trailing decimal zero's and all?
or is it a readtable thing?
Do I have to use strings if I can not guarantee the tokens are number free?

---
Try Anything Twice


Relevant Pages

  • Re: Please, please, please Help !!!
    ... I have a set of 100,000 ascii strings, up to 255 chars each. ... Each string has 1 or more words (tokens), ... if I have strings in: mary poppins, brad pitt, yygr ...
    (microsoft.public.sqlserver.xml)
  • Re: Stupid Newbie Needs Help
    ... Without the loop the program works fine with the ... with 0-terminated strings, that way you can take advantage of C's ... hold up to 10 tokens, where each token may be up to 80 characters ... should give a clue of how the variable/constant/function/macro is ...
    (comp.lang.c)
  • Re: need an algo for string sorting
    ... I have to sort them. ... It really isn't a sorting problem, ... that, for example, "ax" is two tokens, but 'ai' is one token. ... you know the strings are unequal. ...
    (comp.programming)
  • (Heres how to do it) Re: Please help me with algorithms !!!
    ... FIRST PART (IDENTIFY YOUR ALGORITHM AND DATA STRUCTURE) ... You have 10,000 strings (you have to store them in something: ... Each string has 1 or more words (tokens), ... if I have strings in: mary poppins, brad pitt, yygr ...
    (comp.lang.c)
  • Re: SBCL is now faster than Java, as fast as Ocaml, and getting better
    ... (labels ((aux (lam normal scene) ... Note that the Lisp was written by Juho Snellman, one of the authors of SBCL, ... Your pattern match for the list case requires three tokens: ... Only if you ignore the superfluous parentheses that make up most of the Lisp ...
    (comp.lang.lisp)