unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
From: "Drew Adams" <drew.adams@oracle.com>
Subject: RE: message in minibuffer
Date: Sat, 19 Nov 2005 22:58:52 -0800	[thread overview]
Message-ID: <DNEMKBNJBGPAOPIJOOICKEBCCPAA.drew.adams@oracle.com> (raw)
In-Reply-To: <1132465960.466513.6320@g49g2000cwa.googlegroups.com>

    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.

  reply	other threads:[~2005-11-20  6:58 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-11-19 23:52 message in minibuffer wkomornicki
2005-11-20  0:10 ` Drew Adams
     [not found] ` <mailman.15965.1132445463.20277.help-gnu-emacs@gnu.org>
2005-11-20  5:52   ` wkomornicki
2005-11-20  6:58     ` Drew Adams [this message]
     [not found]     ` <mailman.15984.1132469952.20277.help-gnu-emacs@gnu.org>
2005-11-20 20:15       ` wkomornicki

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=DNEMKBNJBGPAOPIJOOICKEBCCPAA.drew.adams@oracle.com \
    --to=drew.adams@oracle.com \
    /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).