Use of symbols for "words" -- was Avoiding eval
From: George Orwell (Use-Author-Supplied-Address-Header_at_[127.1)
Date: 03/06/04
- Next message: Rahul Jain: "Re: off-topic: Why is lisp so weird?"
- Previous message: Frank Goenninger DG1SBG: "Re: libclisp.a"
- Next in thread: Alan Crowe: "Re: Use of symbols for "words" -- was Avoiding eval"
- Reply: Alan Crowe: "Re: Use of symbols for "words" -- was Avoiding eval"
- Reply: An Metet: "RE: Use of symbols for "words" -- was Avoiding eval"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
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
- Next message: Rahul Jain: "Re: off-topic: Why is lisp so weird?"
- Previous message: Frank Goenninger DG1SBG: "Re: libclisp.a"
- Next in thread: Alan Crowe: "Re: Use of symbols for "words" -- was Avoiding eval"
- Reply: Alan Crowe: "Re: Use of symbols for "words" -- was Avoiding eval"
- Reply: An Metet: "RE: Use of symbols for "words" -- was Avoiding eval"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|