[racket-dev] conditional code [was Re: Best way to handle duplicate identifiers]

From: Carl Eastlund (cce at ccs.neu.edu)
Date: Wed Jul 25 22:10:29 EDT 2012

On Wed, Jul 25, 2012 at 10:00 PM, D Herring <dherring at tentpost.com> wrote:
> On 07/25/2012 04:50 PM, Robby Findler wrote:
>> On Wednesday, July 25, 2012, Doug Williams wrote:
>>     Racket now includes nan? and infinite? in the core language, which
>>     were already defined and provided by the science collection in PLaneT.
>> I think you're best off to release a new version of the science
>> collection and make it require 5.3 as the minimum version (one that
>> differs from the currently released one only by sorting out this
>> conflict).
> Newbie question here:  Isn't there a way that Doug can write his code such
> that it provides nan? and infinite?, but only when running on an older
> version of Racket?  Some sort of reader conditional?
> Thanks,
> Daniel

I have used a macro I call "define-if-unbound" that uses
identifier-binding at phase 1 to detect if a name is already bound,
using the given definition if it is not and leaving it alone
otherwise.  It's fairly straightforward to write.  You can then just
provide the name normally, and you will either provide the definition
or re-provide the import from Racket as appropriate.

The code for it is here if anyone wants to duplicate it:


The cce/scheme planet package is deprecated, so I recommend against
requiring this directly.


Posted on the dev mailing list.