From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Alan Newsgroups: gmane.emacs.help Subject: hypothetical question about macros Date: Thu, 14 Apr 2011 16:33:15 -0700 (PDT) Organization: http://groups.google.com Message-ID: <27b70c81-5057-435e-8304-e400fa8e00d2@w9g2000prg.googlegroups.com> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 X-Trace: dough.gmane.org 1306267714 11864 80.91.229.12 (24 May 2011 20:08:34 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Tue, 24 May 2011 20:08:34 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Tue May 24 22:08:30 2011 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([140.186.70.17]) by lo.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1QOxu2-00061B-CC for geh-help-gnu-emacs@m.gmane.org; Tue, 24 May 2011 22:08:30 +0200 Original-Received: from localhost ([::1]:49758 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QOxu1-0001N3-RR for geh-help-gnu-emacs@m.gmane.org; Tue, 24 May 2011 16:08:29 -0400 Original-Path: usenet.stanford.edu!postnews.google.com!w9g2000prg.googlegroups.com!not-for-mail Original-Newsgroups: gnu.emacs.help Original-Lines: 76 Original-NNTP-Posting-Host: 75.57.143.176 Original-X-Trace: posting.google.com 1302823995 26725 127.0.0.1 (14 Apr 2011 23:33:15 GMT) Original-X-Complaints-To: groups-abuse@google.com Original-NNTP-Posting-Date: Thu, 14 Apr 2011 23:33:15 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: w9g2000prg.googlegroups.com; posting-host=75.57.143.176; posting-account=czAMxQoAAAAUEojshw4CrIvcwSdulymE User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2.16) Gecko/20110319 Firefox/3.6.16 ( .NET CLR 3.5.30729), gzip(gfe) Original-Xref: usenet.stanford.edu gnu.emacs.help:186677 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:81052 Archived-At: 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.