From ... Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!newsfeed.icl.net!newsfeed.fjserv.net!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!feed.news.nacamar.de!uninett.no!news-feed.ifi.uio.no!ifi.uio.no!not-for-mail From: Erik Naggum Newsgroups: comp.lang.lisp,comp.lang.scheme,comp.lang.functional Subject: Re: Macros in Common Lisp, Scheme, and other languages Date: 07 Sep 2002 04:29:29 +0000 Organization: Naggum Software, Oslo, Norway Lines: 35 Message-ID: <3240361769031272@naggum.no> References: <7ed8f64d.0209050301.66c34a92@posting.google.com> <3D783A89.C886BF0F@his.com> <3240318776815077@naggum.no> <6db3f637.0209061838.47bb9d0b@posting.google.com> Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit X-Trace: maud.ifi.uio.no 1031372976 11883 129.240.64.16 (7 Sep 2002 04:29:36 GMT) X-Complaints-To: abuse@ifi.uio.no NNTP-Posting-Date: 7 Sep 2002 04:29:36 GMT Mail-Copies-To: never User-Agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.2 Xref: archiver1.google.com comp.lang.lisp:39945 comp.lang.scheme:14057 comp.lang.functional:12853 * pcm@cpugrid.net (P.M.) | Can you explain what compiler-macros are and how they differ from | ordinary macros? There are two important differences. The first is that they are defined in addition to the function, which remains available for normal calls. The second is that they /may/ rewrite a function call at compile-time to redirect the call to a different (such as a more type-specific) function or to inline the operation with system- or implementation-specific forms. The significance of the /may/ is that a compiler macro may decline to rewrite the form, in which case the original function call remains. An ordinary macro is, as you may know, always expanded and it is impossible to call it indirectly. The compiler-macro combines the power of rewriting with an actual function. A compiler-macro is more useful in the presence of environment information, such that it can know the declared or inferred type of variable bindings and act on such knowledge. One particularly nice way to use compiler macros is in combination with keyword arguments; because they can be expensive to use in functions that need only a subset of the full functionality, a compiler macro can detect the actual keywords used and call the applicable specialized function. E.g., the general function `member´ may have specialized functions according as the `:key´ or `:test´ arguments reflect common usages, like `:key #'car´ or `:test #'string=´. | Compile-time computation sounds a bit like template metaprogramming in C++. Template meta-programming is compile-time computation, but I am not quite sure how templates work. I have not programmed in C++ for about a decade, and it was much less involved then. -- Erik Naggum, Oslo, Norway Act from reason, and failure makes you rethink and study harder. Act from faith, and failure makes you blame someone and push harder.