unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
* Can't define in (if...) after (use-syntax (ice-9 syncase)) ?
@ 2010-08-27 12:49 Cedric Cellier
  2010-08-27 14:04 ` Andreas Rottmann
  0 siblings, 1 reply; 6+ messages in thread
From: Cedric Cellier @ 2010-08-27 12:49 UTC (permalink / raw)
  To: guile-user

guile> (use-syntax (ice-9 syncase))
guile> (if #t (define foo "bar"))
ERROR: invalid context for definition of foo
ABORT: (misc-error)
guile> (version)
$1 = "1.8.7"

apparently syncase module is altering the if or define behavior somehow ?



^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Can't define in (if...) after (use-syntax (ice-9 syncase)) ?
  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
  0 siblings, 1 reply; 6+ messages in thread
From: Andreas Rottmann @ 2010-08-27 14:04 UTC (permalink / raw)
  To: Cedric Cellier; +Cc: guile-user

Cedric Cellier <rixed@happyleptic.org> writes:

> guile> (use-syntax (ice-9 syncase))
> guile> (if #t (define foo "bar"))
> ERROR: invalid context for definition of foo
> ABORT: (misc-error)
> guile> (version)
> $1 = "1.8.7"
>
> apparently syncase module is altering the if or define behavior somehow ?
>
I think it's establishing stricter rules for `define' placement.  Note
that your code is not legal (R5RS) Scheme -- the define is misplaced;
it's neither a top-level nor an internal define.  Also note that Guile
1.9.x has syntax-case always loaded, and rejects your example code as
well:

scheme@(guile-user)> (if #t (define foo "bar"))
While compiling expression:
ERROR: In procedure macroexpand:
ERROR: definition in expression context in subform `foo' of `"bar"'

What do you want to achieve in your code?

Regards, Rotty
-- 
Andreas Rottmann -- <http://rotty.yi.org/>



^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Can't define in (if...) after (use-syntax (ice-9 syncase)) ?
  2010-08-27 14:04 ` Andreas Rottmann
@ 2010-09-01  7:12   ` Cedric Cellier
  2010-09-01 15:23     ` Andy Wingo
  0 siblings, 1 reply; 6+ messages in thread
From: Cedric Cellier @ 2010-09-01  7:12 UTC (permalink / raw)
  To: guile-user

-[ Fri, Aug 27, 2010 at 04:04:25PM +0200, Andreas Rottmann ]----
> > guile> (use-syntax (ice-9 syncase))
> > guile> (if #t (define foo "bar"))
> > ERROR: invalid context for definition of foo
> > (...)
> >
> I think it's establishing stricter rules for `define' placement.  Note
> that your code is not legal (R5RS) Scheme -- the define is misplaced;
> it's neither a top-level nor an internal define. 
> (...)
> What do you want to achieve in your code?

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 ?




^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Can't define in (if...) after (use-syntax (ice-9 syncase)) ?
  2010-09-01  7:12   ` Cedric Cellier
@ 2010-09-01 15:23     ` Andy Wingo
  2010-09-02  4:39       ` Keith Wright
  0 siblings, 1 reply; 6+ messages in thread
From: Andy Wingo @ 2010-09-01 15:23 UTC (permalink / raw)
  To: Cedric Cellier; +Cc: guile-user

Hi,

It's ugly, but a quick solution:

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))

Andy
-- 
http://wingolog.org/



^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Can't define in (if...) after (use-syntax (ice-9 syncase)) ?
  2010-09-01 15:23     ` Andy Wingo
@ 2010-09-02  4:39       ` Keith Wright
  2010-09-02 18:40         ` Andy Wingo
  0 siblings, 1 reply; 6+ messages in thread
From: Keith Wright @ 2010-09-02  4:39 UTC (permalink / raw)
  To: wingo; +Cc: guile-user

> 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))



^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Can't define in (if...) after (use-syntax (ice-9 syncase)) ?
  2010-09-02  4:39       ` Keith Wright
@ 2010-09-02 18:40         ` Andy Wingo
  0 siblings, 0 replies; 6+ messages in thread
From: Andy Wingo @ 2010-09-02 18:40 UTC (permalink / raw)
  To: Keith Wright; +Cc: guile-user

On Wed 01 Sep 2010 21:39, Keith Wright <kwright@keithdiane.us> writes:

>> 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.

A fair point, but usually this idiom is for dealing with changes to the
underlying environment, something that is out of the purview of Scheme
as a language spec.

Andy
-- 
http://wingolog.org/



^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2010-09-02 18:40 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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
2010-09-02 18:40         ` Andy Wingo

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).