[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Can't define in (if...) after (use-syntax (ice-9 syncase)) ?

From: Keith Wright
Subject: Re: Can't define in (if...) after (use-syntax (ice-9 syncase)) ?
Date: Thu, 2 Sep 2010 00:39:41 -0400

> From: Andy Wingo <address@hidden>
> 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

Otherwise, maybe you want a macro.

  -- Keith

> On Wed 01 Sep 2010 00:12, Cedric Cellier <address@hidden> 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))

reply via email to

[Prev in Thread] Current Thread [Next in Thread]