> From: Andy Wingo <[email protected]> > > It's ugly, but a quick solution:
Actually, I would not even take it as a solution at all. The quesion was how to do it in legal Scheme. The problem is not the position of the define, but that no Scheme report has any procedure called |defined?|. Scheme is intended to be compilable, and so the programmer is presumed to know what should be defined, and define it before running the program. Fortunately, there is a way to assign new values to variables that have already been defined. (define foo #f) . . . (if (not foo) (set! foo bar)) This conflates false with undefined, if these must be distinct, pick another value to represent not-yet-set, or use another variable. Otherwise, maybe you want a macro. -- Keith > On Wed 01 Sep 2010 00:12, Cedric Cellier <[email protected]> writes: > > > I'm doing this : > > > > (if (not defined? 'foo) (define foo bar)) > > > > without realizing it's not legal scheme. > > What would be the idiomatic way to write this ? > > (define foo > (if (defined? 'foo) > foo > bar))
