5

I was surprised to find that if I use M-x ielm, I get a literal backquote:

ELISP> (read "`foo")
`foo

However, if I use M-: (read "`foo") then *Messages* and the minibuffer show (\` foo).

Are these two equivalent? Why doesn't (equal (read "`foo") `foo) return t?

Drew
  • 75,699
  • 9
  • 109
  • 225
Wilfred Hughes
  • 6,890
  • 2
  • 29
  • 59
  • 1
    `ielm` is pretty printing, similarly, ``M-x pp-eval-expression RET (read "`foo") RET`` will show `\`foo` – npostavs Aug 08 '16 at 03:24

1 Answers1

5

The value returned by the sexp (read "`foo") is `foo.

You are confused by the form of the printing of the read value by the command you are using (eval-expression, bound to M-: by default). What it prints is a Lisp representation of the value. If you instead use pp-eval-expression then you see `foo, which is the (same) value printed for humans. (This is one of several reasons that I prefer to bind M-: to pp-eval-expression.)

As for the Lisp representation - in library backquote.el you see this Commentary (notice the first line):

;; When the Lisp reader sees `(...), it generates (\` (...)).
;; When it sees ,... inside such a backquote form, it generates (\, ...).
;; For ,@... it generates (\,@ ...).

That first line could have said that when it sees `... it generates (\` ...). In other words, what is says is not just for a backquoted list. In your case, when it sees `foo it generates (\` foo).

And (equal (read "`foo") '`foo) does return t. (You forgot to quote the second argument to equal. You used `foo as the second argument, but that gets evaluated - to foo, not to `foo, which is what you wanted to compare with the value of (read "`foo").)

theldoria
  • 1,825
  • 1
  • 13
  • 25
Drew
  • 75,699
  • 9
  • 109
  • 225