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
> 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?
"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
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.