unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
From: pjb@informatimago.com (Pascal J. Bourguignon)
To: help-gnu-emacs@gnu.org
Subject: Re: how to convert a string to a symbol?
Date: Sun, 14 Sep 2008 09:25:45 +0200	[thread overview]
Message-ID: <87od2r89za.fsf@hubble.informatimago.com> (raw)
In-Reply-To: mailman.19202.1221372658.18990.help-gnu-emacs@gnu.org

"Drew Adams" <drew.adams@oracle.com> writes:

>> > (setq str "(> 2 1)")
>> > I want something like: (eval (string-to-symbol str))
>> 
>> (intern str)
>
> And if you really want the value of the symbol (per your use of `eval' above):
>
> (symbol-value (intern str))
>
> But you might want to give it a value first ;-) -
>
> (set (intern "(> 2 1)") 42)
>
> (symbol-value '\(>\ 2\ 1\)) ; The answer is 42.
>
> However, as always with questions of this type, one wonders what you are
> _really_ trying to do (not to mention why)...

sunways, what Drew tries to hint at is that you don't want
string-to-symbol.

(By the way, there's another way to get a symbol from a string, it's
make-symbol, but it makes an uninterned symbol, which is even less
what you want).

So as you may have realized by now, what you want is to get the
symbolic expression, or s-exp (> 2 1) from "(> 2 1)", and this can be
done by "reading" the string, so, logically, with read-from-string.
(car (read-from-string "(> 2 1)")) -> (> 2 1)


Now the question would be where did you get this string from in the
first place?  You probably could have used read, or specified you
wanted a s-exp instead of a string at the source.

-- 
__Pascal Bourguignon__                     http://www.informatimago.com/
You never feed me.
Perhaps I'll sleep on your face.
That will sure show you.


  parent reply	other threads:[~2008-09-14  7:25 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-09-14  4:59 how to convert a string to a symbol? sunway
2008-09-14  5:54 ` Drew Adams
2008-09-14  6:10   ` Drew Adams
     [not found]   ` <mailman.19202.1221372658.18990.help-gnu-emacs@gnu.org>
2008-09-14  7:10     ` sunway
2008-09-14  7:27       ` Pascal J. Bourguignon
2008-09-14  8:06       ` Tim X
2008-09-14  8:34         ` sunway
2008-09-14  9:25           ` Joost Diepenmaat
2008-09-14 13:47           ` Pascal J. Bourguignon
2008-09-14  7:25     ` Pascal J. Bourguignon [this message]
2008-09-14 10:19     ` Richard G Riley
2008-09-14 13:43       ` Pascal J. Bourguignon
2008-09-15  9:34         ` David Kastrup

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87od2r89za.fsf@hubble.informatimago.com \
    --to=pjb@informatimago.com \
    --cc=help-gnu-emacs@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).