From: ········@alumail.uji.es
Subject: How transform a string to symbol
Date:
Message-ID: <4oq689$avl@marti.uji.es>
I want change the name of symbol.
If the name is: rule1, i want rule1-1.
With symbol-name hi have the string qith the name, Is there any
function to do the inverse.
Thank yoy to help me
From: Donald H. Mitchell
Subject: Re: How transform a string to symbol
Date:
Message-ID: <31B25B42.6550@pgh.net>
········@alumail.uji.es wrote:
>
> I want change the name of symbol.
>
If you literally want to change the name of the symbol, it is not
possible. Symbol names cannot be changed. If, as Marty surmised, you
merely want to create a new symbol with a derivative name, then use what
Marty said. If you just need the string, of course, don't bother
interning the string after deriving the new name.
(defun variant-name (string-or-symbol)
(unless (symbolp string-or-symbol)
(setf string-or-symbol (intern string-or-symbol :my-package)))
;;return string w/ variant # appended
(format nil "~A-~D" string-or-symbol
(incf (get string-or-symbol 'variant 0))))
variant-name
> (variant-name 'foo)
"foo-1"
> (variant-name "foo")
"foo-2"
> (variant-name "bar")
"bar-1"
> (variant-name "BAR")
"bar-2"
>
If you really want to have symbols rather than strings, merely surround
the (format ...) w/ (intern (format ...) :my-package).
If you want the numbering to start w/ zero, then use -1 as the default on
the get.
--
Donald H. Mitchell ···@pgh.net
Proactive Solutions, Inc. 412.835.2410
5858 Horseshoe Dr. 412.835.2411 (fax)
Bethel Park, PA 15102
In article <··········@marti.uji.es> ········@alumail.uji.es writes:
>
>With symbol-name hi have the string qith the name, Is there any
>function to do the inverse.
Mire a los funciones INTERN y READ-FROM-STRING. La specificacion de
ANSI y el libro de Steele estan on-line; visite a
<http://www.apl.jhu.edu/~hall/lisp.html>.
Saludos-
- Marti'n
From: Ken Tilton
Subject: Re: How transform a string to symbol
Date:
Message-ID: <31B2F7B7.6BC4@bway.net>
>
> With symbol-name hi have the string qith the name, Is there any
> function to do the inverse.
d work:
This will create a symbol from a string:
(intern (string-upcase "rule1-1") :cl-user)
By the way, you also described your intent as wanting to change the name
of a symbol. I do not know how precisely you were speaking, but the
above 'intern' of course does not change the name of 'RULE1, it makes a
new symbol 'RULE1-1. ie, (symbol-name 'RULE1) will still be "RULE1".
Cheers,
Ken