Reputation: 1576
In Common Lisp
, when I want to use different pieces of code depending on Common Lisp
implementations, I can use *features*
and the provided notation of #+
and #-
to check the availability of a given feature and proceed accordingly. So for example (taken from Peter Seibel's PCL):
(defun foo ()
#+allegro (do-one-thing)
#+sbcl (do-another-thing)
#+clisp (something-else)
#+cmu (yet-another-version)
#-(or allegro sbcl clisp cmu) (error "Not implemented"))
Is anyone aware of a similar mechanism for Scheme? There are sometimes subtle differences between different implementations of Scheme, which, when you're trying to be portable, would be nice to abstract away. One such case that comes to my mind is Racket
not providing mutable pairs by default. Instead of writing e.g. (set-cdr! lst '(1 2 3))
you would have to use set-mcdr!
and only after you ran (require racket/mpair)
. Of course, such things could be abstracted by functions and/or macros, but I think the Common Lisp
approach is neat in this aspect.
Upvotes: 3
Views: 195
Reputation: 2671
The closest thing there is, is cond-expand
(aka SRFI 0), which is available on some Schemes but not others (Racket, for example, doesn't have it, and your code won't compile if you try to use it). For those Schemes that do have it, it looks like a cond
form, except you test for booleans that tell you things about the compiler/interpreter. On some Schemes you can detect which Scheme you're running on, while on others you can only check for SRFIs:
(cond-expand (chicken
'bok-bok-bok!)
((and guile srfi-3432)
'this-guile-is-full-of-SRFI!)
(else
'(might be MIT Scheme, whose cond-expand only tests for SRFIs)))
Upvotes: 3