help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: What is the best way to navigate #ifdef and #endif in C program


From: Pascal J. Bourguignon
Subject: Re: What is the best way to navigate #ifdef and #endif in C program
Date: Wed, 08 Dec 2010 15:23:19 -0000
User-agent: Gnus/5.101 (Gnus v5.10.10) Emacs/23.2 (gnu/linux)

Peter Keller <psilord@cs.wisc.edu> writes:

> In comp.lang.lisp Elena <egarrulo@gmail.com> wrote:
>> On 4 Ago, 17:09, Peter Keller <psil...@cs.wisc.edu> wrote:
>>> Specifically:http://letoverlambda.com/index.cl/guest/chap5.html#sec_4
>>>
>>> Would show you how to write a macro such that it adds Scheme's tail call
>>> optimized "named let" into Common Lisp. ?This goes beyond the concept
>>> of syntactic sugar and enters the domain of pure code transformation.
>> 
>> Indeed, code transformation is what sets CL's macros apart. However,
>> TCO is much more than that. Read here:
>> 
>> http://stackoverflow.com/questions/2181852/tail-call-elimination-in-clojure
>
> After reading that, I assert that I don't know how to take base CL
> and make it tail recursive since redefining things like defun and
> whatnot lead to package lock errors. Even things like define-compiler-macro
> can't redefine any of the CL macros or functions.
>
> One probably could have success if they created forms like defun-tco,
> labels-tco, flet-tco, etc which kept track of their code expansions
> and rewrote them to be tco. But at that point you've implemented a
> tco enforced lisp dialect on top of CL.

It is almost trivial to provide a package (possibly even named
"COMMON-LISP") which is like the "COMMON-LISP" package, but that is
not the implementation's "COMMON-LISP" package.

See for example:
http://www.informatimago.com/develop/lisp/small-cl-pgms/ibcl/

The trick is in defining a defpackage form such as:

(defmacro defpackage (name &rest options)
  `(cl:defpackage ,name
     ,@(mapcar
        (lambda (option)
          (if (listp option)
              (case (first option)
                ((:use) 
                 (substitute "IBCL" "COMMON-LISP"
                             (substitute "IBCL" "CL" option)))
                ((:shadowing-import-from :import-from)
                 (if (member (string (second option))
                             '("CL" "COMMON-LISP")
                             :test (function string=))
                     (list* (first option)
                            "IBCL"
                            (cddr option))
                     option))
                (otherwise option))))
        options)))

where you substitute the "COMMON-LISP" package for your own.  (You
also need to define your own reader and loader, but these components
are available too).


-- 
__Pascal Bourguignon__                     http://www.informatimago.com/


reply via email to

[Prev in Thread] Current Thread [Next in Thread]