unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
* case syntax and symbols
@ 2005-03-21 22:57 Aaron VanDevender
  2005-03-22  0:53 ` Marius Vollmer
  0 siblings, 1 reply; 17+ messages in thread
From: Aaron VanDevender @ 2005-03-21 22:57 UTC (permalink / raw)


Hello,

I have noticed that guile evaluates the following to #t

(case 'x
  ('x #t)
  (else #f))

even though R5RS section 4.2.1 seems to say that all of the statements
(besides else) must be of the form ((datum ...) ...). Clearly the symbol
'x is not a list. What is going on here? Is this an agreed upon, but not
specified syntax? Scheme48 also evaluates this to #t.

--

sig@netdot.net
Plead the First.


_______________________________________________
Guile-user mailing list
Guile-user@gnu.org
http://lists.gnu.org/mailman/listinfo/guile-user


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

* Re: case syntax and symbols
  2005-03-21 22:57 case syntax and symbols Aaron VanDevender
@ 2005-03-22  0:53 ` Marius Vollmer
  2005-03-22  7:21   ` Neil Jerram
  2005-03-22  9:17   ` Ludovic Courtès
  0 siblings, 2 replies; 17+ messages in thread
From: Marius Vollmer @ 2005-03-22  0:53 UTC (permalink / raw)
  Cc: guile-user

Aaron VanDevender <sig@netdot.net> writes:

> Hello,
>
> I have noticed that guile evaluates the following to #t
>
> (case 'x
>   ('x #t)
>   (else #f))
>
> even though R5RS section 4.2.1 seems to say that all of the statements
> (besides else) must be of the form ((datum ...) ...). Clearly the symbol
> 'x is not a list. What is going on here?

It is a bit tricky.  The syntax 'x is short for (quote x).  This
expansion is done by the reader without looking at the context.  So,
what the evaluator really sees is

  (case 'x
    ((quote x) #t)
    (else #f))

This is indeed in the form required by R5RS, although probably only by
accident.  As expected, the following also evaluates to true:

  (case 'quote
    ('x #t)
    (else #f))
  => #t

Also (and don't try this at home kids):

  (define 'x (* x x))
  '2
  => 4

-- 
GPG: D5D4E405 - 2F9B BCCC 8527 692A 04E3  331E FAF8 226A D5D4 E405


_______________________________________________
Guile-user mailing list
Guile-user@gnu.org
http://lists.gnu.org/mailman/listinfo/guile-user


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

* Re: case syntax and symbols
  2005-03-22  0:53 ` Marius Vollmer
@ 2005-03-22  7:21   ` Neil Jerram
  2005-05-22 17:41     ` Marius Vollmer
  2005-03-22  9:17   ` Ludovic Courtès
  1 sibling, 1 reply; 17+ messages in thread
From: Neil Jerram @ 2005-03-22  7:21 UTC (permalink / raw)
  Cc: guile-user

Marius Vollmer wrote:
> 
> It is a bit tricky.  The syntax 'x is short for (quote x).  This
> expansion is done by the reader without looking at the context.  So,
> what the evaluator really sees is
> 
>   (case 'x
>     ((quote x) #t)
>     (else #f))
> 
> This is indeed in the form required by R5RS, although probably only by
> accident.  As expected, the following also evaluates to true:
> 
>   (case 'quote
>     ('x #t)
>     (else #f))
>   => #t
> 
> Also (and don't try this at home kids):
> 
>   (define 'x (* x x))
>   '2
>   => 4

And presumably (or in my view) this is all fine, except for the last 
example, where Guile should signal an error or at least give a warning. 
  Right?

	Neil


_______________________________________________
Guile-user mailing list
Guile-user@gnu.org
http://lists.gnu.org/mailman/listinfo/guile-user


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

* Re: case syntax and symbols
  2005-03-22  0:53 ` Marius Vollmer
  2005-03-22  7:21   ` Neil Jerram
@ 2005-03-22  9:17   ` Ludovic Courtès
  2005-03-22 13:23     ` Marius Vollmer
  1 sibling, 1 reply; 17+ messages in thread
From: Ludovic Courtès @ 2005-03-22  9:17 UTC (permalink / raw)
  Cc: guile-user

Marius Vollmer <mvo@zagadka.de> writes:

> Also (and don't try this at home kids):
>
>   (define 'x (* x x))
>   '2
>   => 4

Obviously, I did try this at home.  :-)  Actually, you meant something
like:

  guile> (define x 2)
  guile> (define 'x 3)
  guile> x
  2
  guile> 'x
  3

Right?  The example you gave doesn't produce anything funny unless `x'
was previously defined.

Thanks,
Ludovic.


_______________________________________________
Guile-user mailing list
Guile-user@gnu.org
http://lists.gnu.org/mailman/listinfo/guile-user


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

* Re: case syntax and symbols
  2005-03-22  9:17   ` Ludovic Courtès
@ 2005-03-22 13:23     ` Marius Vollmer
  2005-03-22 15:28       ` Ludovic Courtès
  0 siblings, 1 reply; 17+ messages in thread
From: Marius Vollmer @ 2005-03-22 13:23 UTC (permalink / raw)
  Cc: guile-user

ludovic.courtes@laas.fr (Ludovic Courtès) writes:

> Actually, you meant something like:
>
>   guile> (define x 2)
>   guile> (define 'x 3)
>   guile> x
>   2
>   guile> 'x
>   3
>
> Right?  The example you gave doesn't produce anything funny unless `x'
> was previously defined.

Hmm, no, I meant (define 'x (* x x)).  I think '2 => 4 is pretty
funny, no?  :-)


_______________________________________________
Guile-user mailing list
Guile-user@gnu.org
http://lists.gnu.org/mailman/listinfo/guile-user


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

* Re: case syntax and symbols
  2005-03-22 13:23     ` Marius Vollmer
@ 2005-03-22 15:28       ` Ludovic Courtès
  2005-03-22 16:28         ` Marius Vollmer
  0 siblings, 1 reply; 17+ messages in thread
From: Ludovic Courtès @ 2005-03-22 15:28 UTC (permalink / raw)
  Cc: guile-user

Marius Vollmer <marius.vollmer@uni-dortmund.de> writes:

> Hmm, no, I meant (define 'x (* x x)).  I think '2 => 4 is pretty
> funny, no?  :-)

Sure it is, but I can't reproduce it with either 1.6.7 or 1.7.2, hence
my sadness.  ;-)

Ludovic.


_______________________________________________
Guile-user mailing list
Guile-user@gnu.org
http://lists.gnu.org/mailman/listinfo/guile-user


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

* Re: case syntax and symbols
  2005-03-22 15:28       ` Ludovic Courtès
@ 2005-03-22 16:28         ` Marius Vollmer
  0 siblings, 0 replies; 17+ messages in thread
From: Marius Vollmer @ 2005-03-22 16:28 UTC (permalink / raw)
  Cc: guile-user

ludovic.courtes@laas.fr (Ludovic Courtès) writes:

> Sure it is, but I can't reproduce it with either 1.6.7 or 1.7.2, hence
> my sadness.  ;-)

What happens?  This should work in all version of Guile...


_______________________________________________
Guile-user mailing list
Guile-user@gnu.org
http://lists.gnu.org/mailman/listinfo/guile-user


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

* Re: case syntax and symbols
  2005-03-22  7:21   ` Neil Jerram
@ 2005-05-22 17:41     ` Marius Vollmer
  2005-05-23  1:58       ` Kevin Ryde
  2005-05-23 18:39       ` Neil Jerram
  0 siblings, 2 replies; 17+ messages in thread
From: Marius Vollmer @ 2005-05-22 17:41 UTC (permalink / raw)
  Cc: guile-user

Neil Jerram <neil@ossau.uklinux.net> writes:

>> Also (and don't try this at home kids):
>>   (define 'x (* x x))
>>   '2
>>   => 4
>
> And presumably (or in my view) this is all fine, except for the last
> example, where Guile should signal an error or at least give a
> warning. Right?

Hmm.  There are two things here that might want a warning: redefining
something that was a macro as a variable; and shadowing a core
definition.

We we already warn when importing something that shadows a core
definition, so we could as well warn when redefining one.

Opinions?

-- 
GPG: D5D4E405 - 2F9B BCCC 8527 692A 04E3  331E FAF8 226A D5D4 E405


_______________________________________________
Guile-user mailing list
Guile-user@gnu.org
http://lists.gnu.org/mailman/listinfo/guile-user


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

* Re: case syntax and symbols
  2005-05-22 17:41     ` Marius Vollmer
@ 2005-05-23  1:58       ` Kevin Ryde
  2005-06-06 19:21         ` Marius Vollmer
  2005-05-23 18:39       ` Neil Jerram
  1 sibling, 1 reply; 17+ messages in thread
From: Kevin Ryde @ 2005-05-23  1:58 UTC (permalink / raw)
  Cc: guile-user

Marius Vollmer <mvo@zagadka.de> writes:
>
> We we already warn when importing something that shadows a core
> definition, so we could as well warn when redefining one.

I thought about that for my lint program and decided it'd be too
annoying to report local bindings that shadow, but I did set up for
top-level shadows of core or imported stuff to be warned.

An example annoyance for me would be "symbol" which is an undocumented
core binding but I regularly use as the name of a local variable.  (A
variable which, not surprisingly, contains a symbol :).


_______________________________________________
Guile-user mailing list
Guile-user@gnu.org
http://lists.gnu.org/mailman/listinfo/guile-user


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

* Re: case syntax and symbols
  2005-05-22 17:41     ` Marius Vollmer
  2005-05-23  1:58       ` Kevin Ryde
@ 2005-05-23 18:39       ` Neil Jerram
  2005-05-24 11:39         ` Ludovic Courtès
  2005-06-06 19:23         ` Marius Vollmer
  1 sibling, 2 replies; 17+ messages in thread
From: Neil Jerram @ 2005-05-23 18:39 UTC (permalink / raw)
  Cc: guile-user

Marius Vollmer wrote:
> 
> Hmm.  There are two things here that might want a warning: redefining
> something that was a macro as a variable;

Sounds good; and vice versa?  By the way, has your idea about having 
"identifier -> macro" instead of "identifier -> variable -> macro" been 
implemented yet?

> and shadowing a core definition.

I'm not sure I like the implication of "core", as it suggests different 
behaviour for privileged Guile code, vs. different layers of user code.

Isn't the rule we want "whenever a new definition shadows an existing 
definition in a module, and the existing definition did not originate in 
the current module"?  This rule would also avoid giving unwanted 
warnings when an edited module is reloaded.

	Neil


_______________________________________________
Guile-user mailing list
Guile-user@gnu.org
http://lists.gnu.org/mailman/listinfo/guile-user


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

* Re: case syntax and symbols
  2005-05-23 18:39       ` Neil Jerram
@ 2005-05-24 11:39         ` Ludovic Courtès
  2005-05-24 18:01           ` Neil Jerram
  2005-06-06 19:26           ` Marius Vollmer
  2005-06-06 19:23         ` Marius Vollmer
  1 sibling, 2 replies; 17+ messages in thread
From: Ludovic Courtès @ 2005-05-24 11:39 UTC (permalink / raw)
  Cc: guile-user, Marius Vollmer

Hi,

Neil Jerram <neil@ossau.uklinux.net> writes:

> Isn't the rule we want "whenever a new definition shadows an existing
> definition in a module, and the existing definition did not originate
> in the current module"?  This rule would also avoid giving unwanted
> warnings when an edited module is reloaded.

There is probably code that relies on redefinitions being silently
interpreted as a `set!', I'm afraid.  So I don't think Guile should
start issuing warnings for redefinitions by default.  Maybe this could
be an option modifiable via `eval-enable'?

For comparison, Bigloo's interpreter issues warnings for redefinitions,
while STkLos doesn't.

Thanks,
Ludovic.


_______________________________________________
Guile-user mailing list
Guile-user@gnu.org
http://lists.gnu.org/mailman/listinfo/guile-user


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

* Re: case syntax and symbols
  2005-05-24 11:39         ` Ludovic Courtès
@ 2005-05-24 18:01           ` Neil Jerram
  2005-05-26 10:53             ` Ludovic Courtès
  2005-06-06 19:26           ` Marius Vollmer
  1 sibling, 1 reply; 17+ messages in thread
From: Neil Jerram @ 2005-05-24 18:01 UTC (permalink / raw)
  Cc: guile-user, Marius Vollmer

Ludovic Courtès wrote:
> Hi,
> 
> Neil Jerram <neil@ossau.uklinux.net> writes:
> 
> 
>>Isn't the rule we want "whenever a new definition shadows an existing
>>definition in a module, and the existing definition did not originate
>>in the current module"?  This rule would also avoid giving unwanted
>>warnings when an edited module is reloaded.
> 
> 
> There is probably code that relies on redefinitions being silently
> interpreted as a `set!', I'm afraid.  So I don't think Guile should
> start issuing warnings for redefinitions by default.

Yes, exactly - that's what my rule avoids doing, isn't it?

Or are you thinking of a "redefinition" as something different to what 
I'm thinking?  The case I'm thinking of is where a file contains a 
definition, and you load that file twice (perhaps via use-modules, but 
that's not important).

	Neil


_______________________________________________
Guile-user mailing list
Guile-user@gnu.org
http://lists.gnu.org/mailman/listinfo/guile-user


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

* Re: case syntax and symbols
  2005-05-24 18:01           ` Neil Jerram
@ 2005-05-26 10:53             ` Ludovic Courtès
  2005-05-26 18:30               ` Neil Jerram
  0 siblings, 1 reply; 17+ messages in thread
From: Ludovic Courtès @ 2005-05-26 10:53 UTC (permalink / raw)
  Cc: guile-user, Marius Vollmer

Hi,

Neil Jerram <neil@ossau.uklinux.net> writes:

> Or are you thinking of a "redefinition" as something different to what
> I'm thinking?  The case I'm thinking of is where a file contains a
> definition, and you load that file twice (perhaps via use-modules, but
> that's not important).

What I'm thinking of is something as simple as:

  (define x 2)
  (define x "hello")

This is also what happens when a file is loaded twice.

What about an `eval-enable' option?

Ludovic.


_______________________________________________
Guile-user mailing list
Guile-user@gnu.org
http://lists.gnu.org/mailman/listinfo/guile-user


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

* Re: case syntax and symbols
  2005-05-26 10:53             ` Ludovic Courtès
@ 2005-05-26 18:30               ` Neil Jerram
  0 siblings, 0 replies; 17+ messages in thread
From: Neil Jerram @ 2005-05-26 18:30 UTC (permalink / raw)
  Cc: guile-user, Marius Vollmer

Ludovic Courtès wrote:
> Hi,
> 
> Neil Jerram <neil@ossau.uklinux.net> writes:
> 
> 
>>Or are you thinking of a "redefinition" as something different to what
>>I'm thinking?  The case I'm thinking of is where a file contains a
>>definition, and you load that file twice (perhaps via use-modules, but
>>that's not important).
> 
> 
> What I'm thinking of is something as simple as:
> 
>   (define x 2)
>   (define x "hello")
> 
> This is also what happens when a file is loaded twice.
> 
> What about an `eval-enable' option?

Sorry, but either you're not reading my emails properly, or I am 
misunderstanding you (or else my own rule).

What I have proposed is a rule that means that Guile would NOT give a 
warning in such cases.  Isn't that what you want?

	Neil


_______________________________________________
Guile-user mailing list
Guile-user@gnu.org
http://lists.gnu.org/mailman/listinfo/guile-user


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

* Re: case syntax and symbols
  2005-05-23  1:58       ` Kevin Ryde
@ 2005-06-06 19:21         ` Marius Vollmer
  0 siblings, 0 replies; 17+ messages in thread
From: Marius Vollmer @ 2005-06-06 19:21 UTC (permalink / raw)
  Cc: guile-user

Kevin Ryde <user42@zip.com.au> writes:

> Marius Vollmer <mvo@zagadka.de> writes:
>>
>> We we already warn when importing something that shadows a core
>> definition, so we could as well warn when redefining one.
>
> I thought about that for my lint program and decided it'd be too
> annoying to report local bindings that shadow, but I did set up for
> top-level shadows of core or imported stuff to be warned.

Yes, I was only thinking about top-level definitions here.  Warning
about local ones should not be done by default.

-- 
GPG: D5D4E405 - 2F9B BCCC 8527 692A 04E3  331E FAF8 226A D5D4 E405


_______________________________________________
Guile-user mailing list
Guile-user@gnu.org
http://lists.gnu.org/mailman/listinfo/guile-user


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

* Re: case syntax and symbols
  2005-05-23 18:39       ` Neil Jerram
  2005-05-24 11:39         ` Ludovic Courtès
@ 2005-06-06 19:23         ` Marius Vollmer
  1 sibling, 0 replies; 17+ messages in thread
From: Marius Vollmer @ 2005-06-06 19:23 UTC (permalink / raw)
  Cc: guile-user

Neil Jerram <neil@ossau.uklinux.net> writes:

> Marius Vollmer wrote:
>> Hmm.  There are two things here that might want a warning:
>> redefining
>> something that was a macro as a variable;
>
> Sounds good; and vice versa?

Yes, and vice versa.

> By the way, has your idea about having "identifier -> macro" instead
> of "identifier -> variable -> macro" been implemented yet?

No, and I have no plans to do it before 1.8.

> Isn't the rule we want "whenever a new definition shadows an existing
> definition in a module, and the existing definition did not originate
> in the current module"?  This rule would also avoid giving unwanted
> warnings when an edited module is reloaded.

Yes, that sounds like a better rule to me.

-- 
GPG: D5D4E405 - 2F9B BCCC 8527 692A 04E3  331E FAF8 226A D5D4 E405


_______________________________________________
Guile-user mailing list
Guile-user@gnu.org
http://lists.gnu.org/mailman/listinfo/guile-user


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

* Re: case syntax and symbols
  2005-05-24 11:39         ` Ludovic Courtès
  2005-05-24 18:01           ` Neil Jerram
@ 2005-06-06 19:26           ` Marius Vollmer
  1 sibling, 0 replies; 17+ messages in thread
From: Marius Vollmer @ 2005-06-06 19:26 UTC (permalink / raw)
  Cc: guile-user, Neil Jerram

ludovic.courtes@laas.fr (Ludovic Courtès) writes:

> There is probably code that relies on redefinitions being silently
> interpreted as a `set!', I'm afraid.  So I don't think Guile should
> start issuing warnings for redefinitions by default.

The warnings would be about redefinitions that would not have the same
effect as a 'set!': there would be a warning when a new variable is
created and an existing variable would become invisible.

-- 
GPG: D5D4E405 - 2F9B BCCC 8527 692A 04E3  331E FAF8 226A D5D4 E405


_______________________________________________
Guile-user mailing list
Guile-user@gnu.org
http://lists.gnu.org/mailman/listinfo/guile-user


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

end of thread, other threads:[~2005-06-06 19:26 UTC | newest]

Thread overview: 17+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-03-21 22:57 case syntax and symbols Aaron VanDevender
2005-03-22  0:53 ` Marius Vollmer
2005-03-22  7:21   ` Neil Jerram
2005-05-22 17:41     ` Marius Vollmer
2005-05-23  1:58       ` Kevin Ryde
2005-06-06 19:21         ` Marius Vollmer
2005-05-23 18:39       ` Neil Jerram
2005-05-24 11:39         ` Ludovic Courtès
2005-05-24 18:01           ` Neil Jerram
2005-05-26 10:53             ` Ludovic Courtès
2005-05-26 18:30               ` Neil Jerram
2005-06-06 19:26           ` Marius Vollmer
2005-06-06 19:23         ` Marius Vollmer
2005-03-22  9:17   ` Ludovic Courtès
2005-03-22 13:23     ` Marius Vollmer
2005-03-22 15:28       ` Ludovic Courtès
2005-03-22 16:28         ` Marius Vollmer

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