문제

I am following the elisp introduction. Very first chapters. Here is two exemples I've copied/pasted from the html book. I've evaluated both forms, and here I copie/paste the returned value and the output as a side effect from the *Messages* buffer (I don't know how to copy the mini-buffer content).

First form

(let ((zebra 'stripes)
      (tiger 'fierce))
  (message "One kind of animal has %s and another is %s."
           zebra tiger))

Output from *Messages*

One kind of animal has stripes and another is fierce.
#("One kind of animal has stripes and another is fierce." 23 30 (fontified t))

Second form

(let ((birch 3)
      pine
      fir
      (oak 'some))
  (message "Here are %d variables with %s, %s and %s value."
           birch pine fir oak))

Output from *Messages* is:

Here are 3 variables with nil, nil and some value.
"Here are 3 variables with nil, nil and some value."

Why is the first form returning a lambda value please? What make the first form so special that the returned value won't be a character string?

도움이 되었습니까?

해결책

The message return type is merely a string. In the *Messages* buffer you see both the return value of message (displayed in quotes in the echo area by the evaluating command), and the unquoted string displayed in the echo area by message itself. The first result was not a lambda, but a string with text properties.

In Emacs, the printable representation of string objects is normally their contents in double quotes, as in your second example. However, strings with text properties attached are printed in a more complex manner, as #("...string contents..." start end (property value...) ...). This extended syntax is for the Lisp reader to be able to recreate the properties when the string is read back from its textual representation. You can test this by evaluating M-: (insert #("foo" 0 3 (face (:foreground "yellow")))) in a fresh buffer - the text will come up yellow because the string itself contained instructions to paint it yellow. (To see this, you need to be in a fresh buffer obtained with, say, C-x b randomname RET — it won't work in syntax-highlighted buffers such as *scratch*, because they colorize the text themselves.)

So, the first string you printed came with properties attached, possibly as an artifact of copying and pasting, which is why it was printed as #("..." ...). The second string had no properties, and could be printed as a simple string.

The Emacs Lisp manual contains much more info on text properties.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top