From: Keith Wright <kwright@keithdiane.us>
To: wingo@pobox.com
Cc: guile-user@gnu.org
Subject: Re: Can't define in (if...) after (use-syntax (ice-9 syncase)) ?
Date: Thu, 2 Sep 2010 00:39:41 -0400 [thread overview]
Message-ID: <201009020439.o824dfWj004099@fcs13.keithdiane.us> (raw)
In-Reply-To: <m3occhv666.fsf@unquote.localdomain> (message from Andy Wingo on Wed, 01 Sep 2010 08:23:45 -0700)
> From: Andy Wingo <wingo@pobox.com>
>
> 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 <rixed@happyleptic.org> 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))
next prev parent reply other threads:[~2010-09-02 4:39 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-08-27 12:49 Can't define in (if...) after (use-syntax (ice-9 syncase)) ? Cedric Cellier
2010-08-27 14:04 ` Andreas Rottmann
2010-09-01 7:12 ` Cedric Cellier
2010-09-01 15:23 ` Andy Wingo
2010-09-02 4:39 ` Keith Wright [this message]
2010-09-02 18:40 ` Andy Wingo
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/guile/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=201009020439.o824dfWj004099@fcs13.keithdiane.us \
--to=kwright@keithdiane.us \
--cc=guile-user@gnu.org \
--cc=wingo@pobox.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).