I'm trying to turn a string containing a question mark into the corresponding symbol but:

(intern "foobar?") returns 'foobar\?

How can i do the same thing without the backslash?

Also i'm interested about why foobarp is prefered to foobar? in elisp code

  • 1
    The p (or -p with multi-word-names) suffix for predicates is simply a convention; and when there's a convention, it's preferable that people stick to it for the sake of consistency. The ? suffix is a Scheme convention, I believe. – phils Feb 5 at 9:40
  • See also C-h i g (elisp)Coding Conventions – phils Feb 5 at 10:01

See C-hig (elisp)Symbol Type

In contrast to its use in strings, however, a backslash in the name of a symbol simply quotes the single character that follows the backslash. For example, in a string, ‘\t’ represents a tab character; in the name of a symbol, however, ‘\t’ merely quotes the letter ‘t’.

So the symbol foobar\? is in fact exactly what you asked for.

If you evaluate 'foobar? you will see the same thing.

Note that, as always, what you're seeing is the printed representation of the returned value.

The slightly curious thing is that, as detailed in that info node (and indeed demonstrated by evaluating 'foobar?), ? does not need to be escaped in symbol names. Evidentially Emacs is choosing to print it that way, but I couldn't tell you why that is.

(symbol-name (intern "foobar?"))
=> "foobar?"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.