Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
name-to-symbol
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  5 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
joachim de beule  
View profile  
 More options May 26 1999, 3:00 am
Newsgroups: comp.lang.lisp
From: joachim de beule <joac...@inwpent3.rug.ac.be>
Date: 1999/05/26
Subject: name-to-symbol
Hello,

I was wondering if there is a way to get a bound symbol
from a given name-string (knowing in advance this symbol is
interned somewhere else.)  This would be like some
inverse 'symbol-name' function.

(setf test 5)
(symbol-name (name-to-symbol "test"))
        => "test"
(symbol-value (name-to-symbol "test"))
        =>5

(I realize one has problems when several symbols have the same name
but who ever needs that ?)
--
Joachim De Beule,
Institute for Nuclear Physics,
RUG - Belgium.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Kent M Pitman  
View profile  
 More options May 26 1999, 3:00 am
Newsgroups: comp.lang.lisp
From: Kent M Pitman <pit...@world.std.com>
Date: 1999/05/26
Subject: Re: name-to-symbol
joachim de beule <joac...@inwpent3.rug.ac.be> writes:

> I was wondering if there is a way to get a bound symbol

I don't think you mean "bound" here in the CLHS glossary sense of "bound".
Symbols are either bound or they are not, but that is an orthogonal property
to whether you can look them up by name.

> from a given name-string (knowing in advance this symbol is
> interned somewhere else.)  This would be like some
> inverse 'symbol-name' function.

Well, symbol-name is many-to-one, so of course you must specify a package.
Any reason INTERN doesn't work?

> (setf test 5)
> (symbol-name (name-to-symbol "test"))
>    => "test"
> (symbol-value (name-to-symbol "test"))
>    =>5

By the way, the symbol-name of the test symbol you have assigned above
is not "test" but "TEST".  You have to do
 (setf |test| 5)
to change the value of the symbol named "test".  By default, the reader
upcases symbol names before calling intern.
 (setf test 5)
is the same as
 (SETF TEST 5)
and the internal name of the symbols are "SETF" and "TEST".

> (I realize one has problems when several symbols have the same name
> but who ever needs that ?)

Most programmers need this most of the time.  However, INTERN will
default its second argument to the value of *PACKAGE*, leaving you
with it working on the current package, and correctly supporting the
illusion that you have the only package in the universe if that's
the illusion you want.

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
David A. Duff  
View profile  
 More options May 26 1999, 3:00 am
Newsgroups: comp.lang.lisp
From: d...@iet.com (David A. Duff)
Date: 1999/05/26
Subject: Re: name-to-symbol
In article <sfw3e0jdivo....@world.std.com>, Kent M Pitman

this is only true if we assume name-to-symbol calls #'read or some variant
(i.e., something which processes tokens according to the value of
*read-case*).   it is quite plausible to imagine a version of
name-to-symbol that would not do that.

> You have to do
>  (setf |test| 5)
> to change the value of the symbol named "test".  By default, the reader
> upcases symbol names before calling intern.
>  (setf test 5)
> is the same as
>  (SETF TEST 5)
> and the internal name of the symbols are "SETF" and "TEST".

what you say of course is true, but here you are talking about the lisp
reader, whereas above, some arbitrary function that processes strings was
being described and there's no reason whatsoever to think that such a
function would or should follow the conventions of the reader.

--
David Duff
IET
d...@iet.com


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Barry Margolin  
View profile  
 More options May 26 1999, 3:00 am
Newsgroups: comp.lang.lisp
From: Barry Margolin <bar...@bbnplanet.com>
Date: 1999/05/26
Subject: Re: name-to-symbol
In article <duff-2605991624400...@luperfoy.100.168.192.in-addr.arpa>,
David A. Duff <d...@iet.com> wrote:

>In article <sfw3e0jdivo....@world.std.com>, Kent M Pitman
><pit...@world.std.com> wrote:
>> > (setf test 5)
>> > (symbol-name (name-to-symbol "test"))
>> >       => "test"
>> > (symbol-value (name-to-symbol "test"))
>> >       =>5

>> By the way, the symbol-name of the test symbol you have assigned above
>> is not "test" but "TEST".  

>this is only true if we assume name-to-symbol calls #'read or some variant
>(i.e., something which processes tokens according to the value of
>*read-case*).   it is quite plausible to imagine a version of
>name-to-symbol that would not do that.

The symbol was not assigned in the call to name-to-symbol.  Kent was
referring to the symbol assigned in the (setf test 5) expression.  His
point was that you should use (name-to-symbol "TEST") to get that symbol,
since the Common Lisp reader uppercases symbols by default.

--
Barry Margolin, bar...@bbnplanet.com
GTE Internetworking, Powered by BBN, Burlington, MA
*** DON'T SEND TECHNICAL QUESTIONS DIRECTLY TO ME, post them to newsgroups.
Please DON'T copy followups to me -- I'll assume it wasn't posted to the group.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Erik Naggum  
View profile  
 More options May 27 1999, 3:00 am
Newsgroups: comp.lang.lisp
From: Erik Naggum <e...@naggum.no>
Date: 1999/05/27
Subject: Re: name-to-symbol
* Kent M Pitman
| By the way, the symbol-name of the test symbol you have assigned above is
| not "test" but "TEST".

* d...@iet.com (David A. Duff)
| this is only true if we assume name-to-symbol calls #'read or some
| variant (i.e., something which processes tokens according to the value of
| *read-case*).   it is quite plausible to imagine a version of
| name-to-symbol that would not do that.

  if you are talking about Common Lisp, I know Kent was, there is no such
  thing as a *READ-CASE* variable that controls the case.  there is a
  READTABLE-CASE accessor that takes a readtable, the current of which is
  the value of *READTABLE*.

| what you say of course is true, but here you are talking about the lisp
| reader, whereas above, some arbitrary function that processes strings was
| being described and there's no reason whatsoever to think that such a
| function would or should follow the conventions of the reader.

  there is no reason whatsoever that such a function should _not_ follow
  the conventions of reader.  there is an ample supply of reasons that it
  should, such as the principle of least surprise, or the stronger version
  of same: a prohibition against forcing the willfully confusing on users.

  unless people use a Lisp that is not a Common Lisp, the case of the name
  of symbols that read and print without special syntax is upper-case.
  programmers should be aware of this, should be able to expect this, and
  should not do anything special to cater to different conventions unless
  they want to be portable to a Lisp that is not a Common Lisp.

  however, it should come as no surprise that I prefer to read lowercase
  instead of uppercase in code.  (in prose, I prefer to let symbols stand
  out, and uppercase is very convenient for this purpose.)  this is where
  the variable *PRINT-CASE* comes in.  the only problem is that one needs
  to type in uppercase when dealing with names of symbols.  since that is a
  context worth noting in its own right, I use a special read macro to help
  me, and Allegro CL has a convenient internal function that returns the
  casified string.  I have bound it to #", so a symbol name reads #"foo",
  and the reader returns what the symbol-name of the symbol whose string
  representation were "foo" would have been, without interning the symbol
  -- or, in simpler terms, it returns the string that would be given to
  INTERN to return the symbol.  I want it to be pervasive, so I have the
  following code in the customization files when building new images:

#+franz-inc excl:
(loop
 with readtables = (get-objects 11)
 for i from 1 to (aref readtables 0)
 for *readtable* = (aref readtables i)
 when (readtable-dispatch-tables *readtable*) do
  ;; reader for symbol names that does case conversion according to the
  ;; rest of the symbol reader.  thanks to Sean Foderaro for the pointer.
  (set-dispatch-macro-character #\# #\"
    (named-function symbol-namestring-reader
      (lambda (stream character prefix)
        (declare (ignore prefix))
        (prog1 (read-extended-token stream)
          (unless (char= character (read-char stream))
            (internal-reader-error stream "invalid symbol-namestring syntax")))))))

  note that it also works with escaped characters: #"|foo|" => "foo"
  regardless of case conversion, so there is no limitation to its use,
  other than what makes sense stylistically.

  (I demand no more than to be credited if you use it and that you identify
  any changes you make as your own.)

#:Erik
--
@1999-07-22T00:37:33Z -- pi billion seconds since the turn of the century


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »