Hi,
I'm in my first few days of Lisp programming. In a little sandbox
program I'm working on, I wanted to decide if a list of symbols contains any
with names similar to some user input.
With the symbol-name function, I can get the names of my symbols and
manipulate them like strings. But when I want to turn these strings back
into symbols, all I found to do that is read-from-string. This works, but
surely there is something more specific. I've figured out a way to
restructure my program to avoid the question entirely, but I'm still
curious.
Thanks,
matt
---
The real problem is entropy.
"matt mcConnell" <····@m-centric.com> writes:
> I'm in my first few days of Lisp programming. In a little sandbox
> program I'm working on, I wanted to decide if a list of symbols contains any
> with names similar to some user input.
> With the symbol-name function, I can get the names of my symbols and
> manipulate them like strings. But when I want to turn these strings back
> into symbols, all I found to do that is read-from-string. This works, but
> surely there is something more specific. I've figured out a way to
> restructure my program to avoid the question entirely, but I'm still
> curious.
INTERN will create or find a symbol whose name is the same as the
string argument, in either the current package or that specified by
the second argument.
MAKE-SYMBOL will create a new symbol with whose name is the same as
the string argument and which is not interned in any package.
--tim
"matt mcConnell" <····@m-centric.com> writes:
> Hi,
> I'm in my first few days of Lisp programming. In a little sandbox
> program I'm working on, I wanted to decide if a list of symbols contains any
> with names similar to some user input.
> With the symbol-name function, I can get the names of my symbols and
> manipulate them like strings. But when I want to turn these strings back
> into symbols, all I found to do that is read-from-string. This works, but
> surely there is something more specific. I've figured out a way to
> restructure my program to avoid the question entirely, but I'm still
> curious.
make-symbol or intern may be what you're looking for.
--
Raymond Wiker
·············@fast.no
>>>>> On Thu, 23 Aug 2001 16:42:43 +0200, matt mcConnell ("matt") writes:
matt> Hi, I'm in my first few days of Lisp programming.
matt> In a little sandbox program I'm working on, I wanted to decide if a
matt> list of symbols contains any with names similar to some user input.
matt> With the symbol-name function, I can get the names of my symbols
matt> and manipulate them like strings.
I guess in your program you have a list of symbols that represent
abstractions of some kind -- the symbol has a property list,
or is a key for an alist or hash-table.
So you could do something like this:
(find "bird" '(bear fox bird dog cat) :key #'symbol-name :test #'string-equal)
==> BIRD
matt> But when I want to turn these strings back into symbols, all I
matt> found to do that is read-from-string. This works, but surely there
matt> is something more specific. I've figured out a way to restructure
matt> my program to avoid the question entirely, but I'm still curious.
Once you have found the symbol, you don't need to turn the input
string "bird" into a symbol: you already have BIRD in your hand.
If the user entered a new concept, like "fox", then you might want to
construct a symbol FOX and add that to your database. To do that,
intern the symbol into the appropriate package, using INTERN:
(intern (string-upcase "fox")) ==> FOX
If you are using property lists, you should either put these symbols
in their own package, or make sure the property indicators are in
your own package.