Hi!
read uses intern to convert symbol names into symbols.
How exactly does it do this? I want to accumulate characters
using read-char and then turn a sequence into a symbol.
Note: (intern "my-string") isn't what I want -
this produces |my-string|. What I want and need is
(equal (holy-grail "my-string") 'my-string) => t
where holy-grail is the transformation function.
Thanks!
P.S. This isn't for homework although it is for a project
I'm working on. As in a previous msg., I don't see this
addressed in any of the books I have (so maybe it's
reserved for the implementation to handle .... ).
Kirt Undercoffer
········@osf1.gmu.edu
Ahem .......
*WACK!* (<= sound of hand smacking forehead)
(intern (string-upcase "my-string")) does it ......
Thanks!
Kirt Undercoffer
Kirt Undercoffer <········@osf1.gmu.edu> schrieb im Beitrag
<··························@FSIS.USDA.GOV>...
> read uses intern to convert symbol names into symbols.
>
> How exactly does it do this? I want to accumulate characters
> using read-char and then turn a sequence into a symbol.
>
> Note: (intern "my-string") isn't what I want -
> this produces |my-string|. What I want and need is
> (equal (holy-grail "my-string") 'my-string) => t
> where holy-grail is the transformation function.
In article <...> "Kirt Undercoffer" <········@osf1.gmu.edu> writes:
> Hi!
>
> read uses intern to convert symbol names into symbols.
>
> How exactly does it do this? I want to accumulate characters
> using read-char and then turn a sequence into a symbol.
>
> Note: (intern "my-string") isn't what I want -
> this produces |my-string|. What I want and need is
> (equal (holy-grail "my-string") 'my-string) => t
> where holy-grail is the transformation function.
[Kirt later adds that (intern (string-upcase "my-string"))
does what he wants.]
For completeness, I suppose you should examine the value of
(readtable-case *readtable*)
and do the appropriate transformation. The possibilities are:
:UPCASE
:DOWNCASE
:PRESERVE
:INVERT
Only invert is hard, because it will only switch upper to lower; or
lower to upper case if all letters that appear in the symbol name are
the same case.
Of course one could always cheat and do
(read-from-string "my-symbol")
--
Thomas A. Russ, USC/Information Sciences Institute ···@isi.edu
In article <··························@FSIS.USDA.GOV>, "Kirt Undercoffer"
<········@osf1.gmu.edu> wrote:
> How exactly does it do this? I want to accumulate characters
> using read-char and then turn a sequence into a symbol.
>
> Note: (intern "my-string") isn't what I want -
> this produces |my-string|. What I want and need is
> (equal (holy-grail "my-string") 'my-string) => t
> where holy-grail is the transformation function.
Symbol names are stored in uppercase.
? (symbol-name 'my-symbol)
"MY-SYMBOL"
The comparison works if you intern an uppercase string.
? (eq 'my-symbol (intern "MY-SYMBOL"))
T
? (eq 'my-symbol (intern (string-upcase "my-symbol")))
T
Using vertical bars makes it possible to write symbols with
lower case characters and spaces.
? '|My Symbol 2|
|My Symbol 2|
--
http://www.lavielle.com/~joswig/