all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* hypothetical question about macros
@ 2011-04-14 23:33 Alan
  2011-04-15  3:57 ` Teemu Likonen
  2011-04-15  4:24 ` Tim X
  0 siblings, 2 replies; 3+ messages in thread
From: Alan @ 2011-04-14 23:33 UTC (permalink / raw
  To: help-gnu-emacs

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.


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2011-04-15  4:24 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-04-14 23:33 hypothetical question about macros Alan
2011-04-15  3:57 ` Teemu Likonen
2011-04-15  4:24 ` Tim X

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.