[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
- To: Luke Hohmann <firstname.lastname@example.org>
- Subject: Silly question...
- From: Steve Strassmann <email@example.com>
- Date: Tue, 4 Aug 1992 14:36:00 -0500
- Cc: info-mcl
>Date: Tue, 4 Aug 92 13:06:13 -0400
>From: Luke Hohmann <firstname.lastname@example.org>
>Subject: Silly question...
>How do I convert a string to a symbol? i.e., how to I:
>(setf foo "window")
>and then call a function to convert foo to a symbol so I can use it in
>a call to make-instance?
> --> Won't work. How do I transform foo?
> -- Luke
The INTERN command will do the trick - in general, converting
the string to uppercase first is a good idea.
? (setq foo "window")
? (make-instance (intern (string-upcase foo)))
#<WINDOW "Untitled" #xB6ECE9>
However, I think it's important to point out that using INTERN
in your code is usually a warning sign that you're doing something
wrong. In other words, Common Lisp gives you enough rope to hang
yourself, but that doesn't mean you have to use it.
For example, if you use (setq foo 'window) instead of
(setq foo "window"), you wouldn't have to use INTERN at all.
(make-instance foo) is a heck of a lot more elegant.
Remember, Lisp is really good at manipulating symbols; there's
no need to shy away from using them! Try 'em, you'll like 'em!