[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
RE: message in minibuffer
From: |
Drew Adams |
Subject: |
RE: message in minibuffer |
Date: |
Sat, 19 Nov 2005 22:58:52 -0800 |
Here is a sample piece of code
(defun foo () (let ((arg "abc")) (message "Here is arg: %s" arg)))
I evaluate this in the minibuffer
Eval: (foo)
and get "Here is arg: abc"
in the [echo area]. However if I evaluate it with
M-x foo
I get the output Here is arg: abc
It seems that the quotation marks show up depending on how the function
is invoked. Why?
Like many "functions" in Lisp, `message' does two things:
1. It displays a message in the minibuffer.
2. It returns a value: the message that it displayed - a string.
#1 is a side effect. #2 is the normal behavior of a true function.
But this is more than a question just of `message'...
When you evaluate `(foo)' using, for example, `M-:' (command
`eval-expression'), you see only the result of the evaluation - that's the
behavior of `eval-expression' (it's own side effect): print the result of
evaluation in the echo area. When the string value of `message' is printed,
it is enclosed in double-quotes, so you can see that the value is a string.
In fact, the process of evaluating `M-: (foo)' first calls (message...),
which prints your message (without quotes), but then the result of `M-:
(foo)' is printed (as a string - showing the quotes), so you never see the
first message. If you check buffer *Messages*, you will see your message,
without the quotes.
When you evaluate `(message...)' using `M-x foo', the result of the
evaluation (of `(foo)') is not echoed in the echo area, because function
`execute-extended-command' (which is bound to `M-x') does not have such a
side effect.
IOW, this is all about 1) keeping straight the difference between side
effect and resulting value, and 2) knowing the behavior of the given
functions (`eval-expression' vs `execute-extended-command').
"Are we having fun yet?", asks Zippy, tossing his "Elementary Haskell"
manual into the dryer and turning the dial to "Delicates". "We'll see if
it's really Purely Functional and 100% Fully Lazy..."
HTH.