From: Didier Verna
Subject: [Q] conditional compilation ala CPP
Date: 
Message-ID: <mux64mh6j58.fsf@uzeb.lrde.epita.fr>
        Hi !

How would you guys mimic CPP's #ifdef in Common Lisp ? I'd like to do
conditional compilation of different versions of functions, for instance. 
Something like:

;; #ifdef *var*
(defun foo ...)
(defun bar ...)
;; #else
(defun foo ...)
(defun bar ...)
;; #endif

Thanks

-- 
Didier Verna, ······@lrde.epita.fr, http://www.lrde.epita.fr/~didier

EPITA / LRDE, 14-16 rue Voltaire   Tel.+33 (1) 44 08 01 85
94276 Le Kremlin-Bic�tre, France   Fax.+33 (1) 53 14 59 22   ······@xemacs.org

From: Eric Lavigne
Subject: Re: conditional compilation ala CPP
Date: 
Message-ID: <1142357442.296527.224530@z34g2000cwc.googlegroups.com>
> How would you guys mimic CPP's #ifdef in Common Lisp ? I'd like to do
> conditional compilation of different versions of functions, for instance.
> Something like:
>
> ;; #ifdef *var*
> (defun foo ...)
> (defun bar ...)
> ;; #else
> (defun foo ...)
> (defun bar ...)
> ;; #endif
>

In C++, #ifdef is most often used to make a code portable across
different implementations, doing things in different ways depending on
what libraries are available, the features of the compiler, etc...

For that purpose, what you want are #+ and #-, which allow code
evaluation to be dependent upon whether a certain symbol is present in
the *features* list.

http://www.lisp.org/HyperSpec/Body/sec_24-1-2-1.html

Does this meet your need?
From: Didier Verna
Subject: Re: conditional compilation ala CPP
Date: 
Message-ID: <muxzmjs6h3g.fsf@uzeb.lrde.epita.fr>
"Eric Lavigne" <············@gmail.com> wrote:

> For that purpose, what you want are #+ and #-, which allow code evaluation
> to be dependent upon whether a certain symbol is present in the *features*
> list.
>
> http://www.lisp.org/HyperSpec/Body/sec_24-1-2-1.html
>
> Does this meet your need?

        Precisely, thanks !

-- 
Didier Verna, ······@lrde.epita.fr, http://www.lrde.epita.fr/~didier

EPITA / LRDE, 14-16 rue Voltaire   Tel.+33 (1) 44 08 01 85
94276 Le Kremlin-Bic�tre, France   Fax.+33 (1) 53 14 59 22   ······@xemacs.org
From: Pascal Bourguignon
Subject: Re: [Q] conditional compilation ala CPP
Date: 
Message-ID: <87irqhgc7s.fsf@thalassa.informatimago.com>
Didier Verna <······@lrde.epita.fr> writes:
> How would you guys mimic CPP's #ifdef in Common Lisp ? I'd like to do
> conditional compilation of different versions of functions, for instance. 
> Something like:
>
> ;; #ifdef *var*
> (defun foo ...)
> (defun bar ...)
> ;; #else
> (defun foo ...)
> (defun bar ...)
> ;; #endif

1- remove the comment!

#ifdef *var*
 (defun foo ...)
 (defun bar ...)
#else
 (defun foo ...)
 (defun bar ...)
#endif

2- implement a reader macro: #i with set-dispatch-macro-character

3- Don't be silly, write it as:

  (pushnew :var *features*)
  ;; or: (setf *features* (delete :var *features*))

  #+var (progn (defun foo ...) 
               (defun bar ...))
  #-var (progn (defun foo ...) 
               (defun bar ...))

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

NOTE: The most fundamental particles in this product are held
together by a "gluing" force about which little is currently known
and whose adhesive power can therefore not be permanently
guaranteed.