all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Alan <wehmann@fnal.gov>
To: help-gnu-emacs@gnu.org
Subject: hypothetical question about macros
Date: Thu, 14 Apr 2011 16:33:15 -0700 (PDT)	[thread overview]
Message-ID: <27b70c81-5057-435e-8304-e400fa8e00d2@w9g2000prg.googlegroups.com> (raw)

Here is a hypothetical question about macros.  Since a macro can
result in code that gets interpreted, suppose one wanted to have a
macro insert the following code:

(insert "#1\n")
(insert "#2\n")
(insert "#3\n")
(insert "#4\n")

This is a silly example, since in real life one is rather unlikely to
do such a thing.  However, it is an exercise of interest for
understanding macros.

Reading the documentation and making some trials, I don't see how to
do this.  For example

(defmacro aw-test ()
  '(insert "#1\n")
  '(insert "#2\n")
  '(insert "#3\n")
  '(insert "#4\n"))

and then using "eval-print-last-sexp" in the scratch buffer on

(aw-test)

results in

#4
nil

Similarly:

(macroexpand '(aw-test))

results in

(insert "#4
")

The following is a possibility:

(defmacro aw-test ()
  '(progn (insert "#1\n")
  (insert "#2\n")
  (insert "#3\n")
  (insert "#4\n")))

In the scratch buffer, using "eval-print-last-sexp" on

(aw-test)

then gives

#1
#2
#3
#4
nil

and

(macroexpand '(aw-test))

results in:

(progn (insert "#1
") (insert "#2
") (insert "#3
") (insert "#4
"))

But I had to resort to using "progn" in this case.

If there were some reason not to have to resort to using "progn" I
don't see how to do so.


             reply	other threads:[~2011-04-14 23:33 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-04-14 23:33 Alan [this message]
2011-04-15  3:57 ` hypothetical question about macros Teemu Likonen
2011-04-15  4:24 ` Tim X

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

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=27b70c81-5057-435e-8304-e400fa8e00d2@w9g2000prg.googlegroups.com \
    --to=wehmann@fnal.gov \
    --cc=help-gnu-emacs@gnu.org \
    /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.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.