unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
* Problem with cond macro.
@ 2002-04-15 22:41 Panagiotis Vossos
  2002-04-16  8:49 ` Julian v. Bock
  0 siblings, 1 reply; 15+ messages in thread
From: Panagiotis Vossos @ 2002-04-15 22:41 UTC (permalink / raw)


Ok, I just started studying macros, so I might be missing something
obvious, but the following example from r5rs doesn't work correctly
with guile:

guile> (version)
"1.5.6"
guile> (let ((=> #f))
	 (cond (#t => 'ok)))
standard input:3:10: In expression (cond (#t => #)):
standard input:3:10: Wrong type to apply: ok
ABORT: (misc-error)

Type "(backtrace)" to get more information or "(debug)" to enter the debugger.
guile> 

SCM and s48 correctly return 'ok.  I wondered if something was wrong
with the built-in 'cond', so I defined 'my-cond' using the definition
from the last section of r5rs.  Unfortunately, the above example still
didn't work.  Any ideas?

panagiotis

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


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

* Re: Problem with cond macro.
  2002-04-15 22:41 Problem with cond macro Panagiotis Vossos
@ 2002-04-16  8:49 ` Julian v. Bock
  2002-04-16  9:45   ` Panagiotis Vossos
  2002-04-17  5:34   ` Keith Wright
  0 siblings, 2 replies; 15+ messages in thread
From: Julian v. Bock @ 2002-04-16  8:49 UTC (permalink / raw)
  Cc: guile-user

Hi

>>>>> "PV" == Panagiotis Vossos <jacbre@internet.gr> writes:

PV> Ok, I just started studying macros, so I might be missing
PV> something obvious, but the following example from r5rs doesn't
PV> work correctly with guile:

guile> (version)
PV> "1.5.6"
guile> (let ((=> #f))
PV> 	 (cond (#t => 'ok))) standard input:3:10: In expression (cond
PV> (#t => #)): standard input:3:10: Wrong type to apply: ok ABORT:
PV> (misc-error)

This works only if cond is implemented as a R5RS macro. This is not
guaranteed by the standard though.

Julian

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


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

* Re: Problem with cond macro.
  2002-04-16  8:49 ` Julian v. Bock
@ 2002-04-16  9:45   ` Panagiotis Vossos
  2002-04-16 11:10     ` Julian v. Bock
  2002-04-16 15:38     ` Joshua Judson Rosen
  2002-04-17  5:34   ` Keith Wright
  1 sibling, 2 replies; 15+ messages in thread
From: Panagiotis Vossos @ 2002-04-16  9:45 UTC (permalink / raw)


julian@openit.de (Julian v. Bock) writes:

> >>>>> "PV" == Panagiotis Vossos <jacbre@internet.gr> writes:
> 
> PV> Ok, I just started studying macros, so I might be missing
> PV> something obvious, but the following example from r5rs doesn't
> PV> work correctly with guile:
> 
> guile> (version)
> PV> "1.5.6"
> guile> (let ((=> #f))
> PV> 	 (cond (#t => 'ok))) standard input:3:10: In expression (cond
> PV> (#t => #)): standard input:3:10: Wrong type to apply: ok ABORT:
> PV> (misc-error)
> 
> This works only if cond is implemented as a R5RS macro. This is not
> guaranteed by the standard though.

Maybe, but I used a r5rs macro to implement 'my-cond' and it still
didn't work correctly.  Here's a simpler case:

(define-syntax foo
  (syntax-rules (=>)
    ((_ a => b) b)
    ((_ a b c) (+ a b c))))

(foo 10 => 20)
(let ((=> 10))
  (foo 10 => 20))

As I understand it, the first use of the macro should return 20 and
the second 40 (SCM and s48 indeed return these values).  But guile
fails on the second one and returns 20.  Here's the exact session:

guile> (use-modules (ice-9 syncase))
guile> (version)
"1.5.6"
guile> (define-syntax foo
	 (syntax-rules (=>)
	   ((_ a => b) b)
	   ((_ a b c) (+ a b c))))

(foo 10 => 20)
(let ((=> 10))
  (foo 10 => 20))
guile> 20
guile> 20

What am I doing wrong ?

panagiotis

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


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

* Re: Problem with cond macro.
  2002-04-16  9:45   ` Panagiotis Vossos
@ 2002-04-16 11:10     ` Julian v. Bock
  2002-04-16 15:38     ` Joshua Judson Rosen
  1 sibling, 0 replies; 15+ messages in thread
From: Julian v. Bock @ 2002-04-16 11:10 UTC (permalink / raw)
  Cc: guile-user

Hi

>>>>> "PV" == Panagiotis Vossos <jacbre@internet.gr> writes:

PV> (define-syntax foo (syntax-rules (=>) ((_ a => b) b) ((_ a b c) (+
PV> a b c))))

PV> (foo 10 => 20) (let ((=> 10)) (foo 10 => 20))

PV> As I understand it, the first use of the macro should return 20
PV> and the second 40 (SCM and s48 indeed return these values).

I agree.

PV> (foo 10 => 20) (let ((=> 10)) (foo 10 => 20))
guile> 20 20

Sounds like a bug in guile.

Julian

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


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

* Re: Problem with cond macro.
  2002-04-16  9:45   ` Panagiotis Vossos
  2002-04-16 11:10     ` Julian v. Bock
@ 2002-04-16 15:38     ` Joshua Judson Rosen
  2002-04-17  0:30       ` Panagiotis Vossos
  1 sibling, 1 reply; 15+ messages in thread
From: Joshua Judson Rosen @ 2002-04-16 15:38 UTC (permalink / raw)
  Cc: guile-user

On Tue, Apr 16, 2002 at 12:45:40PM +0300, Panagiotis Vossos wrote:
> guile> (use-modules (ice-9 syncase))
> guile> (version)
> "1.5.6"
> guile> (define-syntax foo
> 	 (syntax-rules (=>)
> 	   ((_ a => b) b)
> 	   ((_ a b c) (+ a b c))))
> 
> (foo 10 => 20)
> (let ((=> 10))
>   (foo 10 => 20))
> guile> 20
> guile> 20
> 
> What am I doing wrong ?

Try using:
        (use-syntax (ice-9 syncase))
... rather than:
        (use-modules (ice-9 syncase))

Doing so gets me proper results for not only your example from above, but
also for the canonical example from r5rs.

It looks like this is because (use-syntax ...) imports the specified
module and then does:

       (set-module-transformer! (current-module) (car (last-pair spec)))

... where spec is, in this case, (ice-9 syncase), so it sets syncase
(which is defined in the file, psyntax.ss, as sc-expand) as the syntax
transformer for the current module, and this procedure, sc-expand,
does some necessary transformations that aren't done by guile's
default (null?) transformer.

Someone else would have to explain why guile's default macro-expanding
behaviour is what it is.

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


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

* Re: Problem with cond macro.
  2002-04-16 15:38     ` Joshua Judson Rosen
@ 2002-04-17  0:30       ` Panagiotis Vossos
  2002-04-17 20:58         ` Neil Jerram
  0 siblings, 1 reply; 15+ messages in thread
From: Panagiotis Vossos @ 2002-04-17  0:30 UTC (permalink / raw)


Joshua Judson Rosen <rozzin@geekspace.com> writes:

> Try using:
>         (use-syntax (ice-9 syncase))
> ... rather than:
>         (use-modules (ice-9 syncase))
> 
> Doing so gets me proper results for not only your example from above, but
> also for the canonical example from r5rs.

Thanks, now I get the expected results.  However, the manual says:

   In Guile, the `syntax-rules' system is provided by the `(ice-9
   syncase)' module.  To make these facilities available in your code,
   include the expression `(use-modules (ice-9 syncase))' or
   `(use-syntax (ice-9 syncase))' (*note Using Guile Modules::) before
   the first usage of `define-syntax' etc.

,so I guess it is a bug with the manual.

panagiotis

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


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

* Re: Problem with cond macro.
  2002-04-16  8:49 ` Julian v. Bock
  2002-04-16  9:45   ` Panagiotis Vossos
@ 2002-04-17  5:34   ` Keith Wright
  2002-04-25 21:59     ` Dirk Herrmann
  1 sibling, 1 reply; 15+ messages in thread
From: Keith Wright @ 2002-04-17  5:34 UTC (permalink / raw)


> From: julian@openit.de (Julian v. Bock)
> 
> >>>>> "PV" == Panagiotis Vossos <jacbre@internet.gr> writes:
> 
> PV> Ok, I just started studying macros, so I might be missing
> PV> something obvious, but the following example from r5rs doesn't
> PV> work correctly with guile:
> 
> guile> (let ((=> #f))
> guile> 	 (cond (#t => 'ok)))
> guile> In expression (cond (#t => #)): 
> guile> Wrong type to apply: ok ABORT:

I see no macro here.  Aren't you using the Guile built-in version
of COND?

> This works only if cond is implemented as a R5RS macro. This is not
> guaranteed by the standard though.

That's not the way I read it.  R5RS 4.3.2 (near the end) says:

R5RS> As an example. if LET and COND are defined as in section 7.3
R5RS> then they are hygenic (as required) and the following is
R5RS> not an error.
R5RS>         <above example>

I take this to mean that the behaviour shown is required, and
that furthermore the hygenic macro system exhibits the required
behaviour.  Thus the built-in COND should work in the same
way as the example implementation given in the R5 Report,
even though it may be implemented more (or less) efficiently.

-- 
     -- Keith Wright  <kwright@free-comp-shop.com>

Programmer in Chief, Free Computer Shop <http://www.free-comp-shop.com>
         ---  Food, Shelter, Source code.  ---

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


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

* Re: Problem with cond macro.
  2002-04-17  0:30       ` Panagiotis Vossos
@ 2002-04-17 20:58         ` Neil Jerram
  2002-04-20 12:21           ` Neil Jerram
  0 siblings, 1 reply; 15+ messages in thread
From: Neil Jerram @ 2002-04-17 20:58 UTC (permalink / raw)
  Cc: guile-user

>>>>> "Panagiotis" == Panagiotis Vossos <jacbre@internet.gr> writes:

    Panagiotis> Thanks, now I get the expected results.  However, the manual says:

    Panagiotis>    In Guile, the `syntax-rules' system is provided by the `(ice-9
    Panagiotis>    syncase)' module.  To make these facilities available in your code,
    Panagiotis>    include the expression `(use-modules (ice-9 syncase))' or
    Panagiotis>    `(use-syntax (ice-9 syncase))' (*note Using Guile Modules::) before
    Panagiotis>    the first usage of `define-syntax' etc.

    Panagiotis> ,so I guess it is a bug with the manual.

Thanks for checking - I'll fix this in CVS soon.

        Neil


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


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

* Re: Problem with cond macro.
  2002-04-17 20:58         ` Neil Jerram
@ 2002-04-20 12:21           ` Neil Jerram
  2002-04-20 12:27             ` Neil Jerram
  0 siblings, 1 reply; 15+ messages in thread
From: Neil Jerram @ 2002-04-20 12:21 UTC (permalink / raw)
  Cc: guile-user

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

>>>>> "Panagiotis" == Panagiotis Vossos <jacbre@internet.gr> writes:
    Panagiotis> Thanks, now I get the expected results.  However, the manual says:

    Panagiotis> In Guile, the `syntax-rules' system is provided by the `(ice-9
    Panagiotis> syncase)' module.  To make these facilities available in your code,
    Panagiotis> include the expression `(use-modules (ice-9 syncase))' or
    Panagiotis> `(use-syntax (ice-9 syncase))' (*note Using Guile Modules::) before
    Panagiotis> the first usage of `define-syntax' etc.

    Panagiotis> ,so I guess it is a bug with the manual.

    Neil> Thanks for checking - I'll fix this in CVS soon.

Now done.

        Neil


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


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

* Re: Problem with cond macro.
  2002-04-20 12:21           ` Neil Jerram
@ 2002-04-20 12:27             ` Neil Jerram
  0 siblings, 0 replies; 15+ messages in thread
From: Neil Jerram @ 2002-04-20 12:27 UTC (permalink / raw)
  Cc: guile-user

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

    Panagiotis> ,so I guess it is a bug with the manual.

    Neil> Thanks for checking - I'll fix this in CVS soon.

    Neil> Now done.

Actually, not quite; there seems to be a problem with the CVS server:

[neil@laruns ~/Guile/cvs/guile-core]$ cvs update -d -P
cvs server: cannot open /cvsroot/guile/CVSROOT/config: Permission denied
Cannot access /cvsroot/guile/CVSROOT
Permission denied

Fix is ready, anyway.

        Neil


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


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

* Re: Problem with cond macro.
  2002-04-17  5:34   ` Keith Wright
@ 2002-04-25 21:59     ` Dirk Herrmann
  2002-04-26  6:58       ` Keith Wright
  2002-04-26 17:05       ` Marius Vollmer
  0 siblings, 2 replies; 15+ messages in thread
From: Dirk Herrmann @ 2002-04-25 21:59 UTC (permalink / raw)
  Cc: Guile User Mailing List

On Wed, 17 Apr 2002, Keith Wright wrote:

> > From: julian@openit.de (Julian v. Bock)
> > 
> > >>>>> "PV" == Panagiotis Vossos <jacbre@internet.gr> writes:
> > 
> > PV> Ok, I just started studying macros, so I might be missing
> > PV> something obvious, but the following example from r5rs doesn't
> > PV> work correctly with guile:
> > 
> > guile> (let ((=> #f))
> > guile> 	 (cond (#t => 'ok)))
> > guile> In expression (cond (#t => #)): 
> > guile> Wrong type to apply: ok ABORT:
[...]
> R5RS> As an example. if LET and COND are defined as in section 7.3
> R5RS> then they are hygenic (as required) and the following is
> R5RS> not an error.
> R5RS>         <above example>
> 
> I take this to mean that the behaviour shown is required, and
> that furthermore the hygenic macro system exhibits the required
> behaviour.  Thus the built-in COND should work in the same
> way as the example implementation given in the R5 Report,
> even though it may be implemented more (or less) efficiently.

Well, I'm not sure I understand all of this:  What about the following:

(define => #f)
(cond (#t => 'ok))

Should this also deliver 'ok ?  It doesn't seem to with the current
implementation of syncase.

Best regards,
Dirk Herrmann


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


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

* Re: Problem with cond macro.
  2002-04-25 21:59     ` Dirk Herrmann
@ 2002-04-26  6:58       ` Keith Wright
  2002-04-26 17:05       ` Marius Vollmer
  1 sibling, 0 replies; 15+ messages in thread
From: Keith Wright @ 2002-04-26  6:58 UTC (permalink / raw)
  Cc: guile-user

> From: Dirk Herrmann <dirk@ida.ing.tu-bs.de>
> Well, I'm not sure I understand all of this:  What about the following:
> 
> (define => #f)
> (cond (#t => 'ok))
> 
> Should this also deliver 'ok ?  It doesn't seem to with the current
> implementation of syncase.

A tricky question to be sure.  I would say "Yes", but would
listen quietly if Guy Steele had anything to say about it.
It doesn't surprise me that syncase does not get it right, it
was grafted on rather late in the game and still doesn't fit
quite right.  The => syntax in COND is a strange wart in
Scheme and there is a strong temptation to handle it
with special case code deep in the interpreter, rather
than write code for the general case which has only one
instance.

Among the several bugs, misfeatures, and holes in Guile,
I don't think this is one of the more important.

-- 
     -- Keith Wright  <kwright@free-comp-shop.com>

Programmer in Chief, Free Computer Shop <http://www.free-comp-shop.com>
         ---  Food, Shelter, Source code.  ---

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


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

* Re: Problem with cond macro.
  2002-04-25 21:59     ` Dirk Herrmann
  2002-04-26  6:58       ` Keith Wright
@ 2002-04-26 17:05       ` Marius Vollmer
  2002-04-28 19:46         ` Dirk Herrmann
  1 sibling, 1 reply; 15+ messages in thread
From: Marius Vollmer @ 2002-04-26 17:05 UTC (permalink / raw)
  Cc: Keith Wright, Guile User Mailing List

Dirk Herrmann <dirk@ida.ing.tu-bs.de> writes:

> Well, I'm not sure I understand all of this:  What about the following:
> 
> (define => #f)
> (cond (#t => 'ok))
> 
> Should this also deliver 'ok ?  It doesn't seem to with the current
> implementation of syncase.

Syncase is not really totally integrated with the module system yet, I
think.  That's why it can be confused by top-level bindings.

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


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

* Re: Problem with cond macro.
  2002-04-26 17:05       ` Marius Vollmer
@ 2002-04-28 19:46         ` Dirk Herrmann
  2002-05-07 18:41           ` Marius Vollmer
  0 siblings, 1 reply; 15+ messages in thread
From: Dirk Herrmann @ 2002-04-28 19:46 UTC (permalink / raw)
  Cc: Keith Wright, Guile User Mailing List

On 26 Apr 2002, Marius Vollmer wrote:

> Dirk Herrmann <dirk@ida.ing.tu-bs.de> writes:
> 
> > Well, I'm not sure I understand all of this:  What about the following:
> > 
> > (define => #f)
> > (cond (#t => 'ok))
> > 
> > Should this also deliver 'ok ?  It doesn't seem to with the current
> > implementation of syncase.
> 
> Syncase is not really totally integrated with the module system yet, I
> think.  That's why it can be confused by top-level bindings.

OK, but can you definitely say "Yes, it should deliver 'ok" or not?  I am
not sure it is said explicitly in R5RS.  If a macro introduces a bound
identifier, it is renamed in the subforms.  I am not sure if and how this
applies for 'define.

Best regards
Dirk Herrmann


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


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

* Re: Problem with cond macro.
  2002-04-28 19:46         ` Dirk Herrmann
@ 2002-05-07 18:41           ` Marius Vollmer
  0 siblings, 0 replies; 15+ messages in thread
From: Marius Vollmer @ 2002-05-07 18:41 UTC (permalink / raw)
  Cc: Keith Wright, Guile User Mailing List

Dirk Herrmann <dirk@ida.ing.tu-bs.de> writes:

> On 26 Apr 2002, Marius Vollmer wrote:
> 
> > Dirk Herrmann <dirk@ida.ing.tu-bs.de> writes:
> > 
> > > Well, I'm not sure I understand all of this:  What about the following:
> > > 
> > > (define => #f)
> > > (cond (#t => 'ok))
> > > 
> > > Should this also deliver 'ok ?  It doesn't seem to with the current
> > > implementation of syncase.
> > 
> > Syncase is not really totally integrated with the module system yet, I
> > think.  That's why it can be confused by top-level bindings.
> 
> OK, but can you definitely say "Yes, it should deliver 'ok" or not?

I can't say that definitely.

> I am not sure it is said explicitly in R5RS.  If a macro introduces
> a bound identifier, it is renamed in the subforms.  I am not sure if
> and how this applies for 'define.

I'd say that define also binds identifiers, but I'm no expert on
syntax-case, by far.

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


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

end of thread, other threads:[~2002-05-07 18:41 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2002-04-15 22:41 Problem with cond macro Panagiotis Vossos
2002-04-16  8:49 ` Julian v. Bock
2002-04-16  9:45   ` Panagiotis Vossos
2002-04-16 11:10     ` Julian v. Bock
2002-04-16 15:38     ` Joshua Judson Rosen
2002-04-17  0:30       ` Panagiotis Vossos
2002-04-17 20:58         ` Neil Jerram
2002-04-20 12:21           ` Neil Jerram
2002-04-20 12:27             ` Neil Jerram
2002-04-17  5:34   ` Keith Wright
2002-04-25 21:59     ` Dirk Herrmann
2002-04-26  6:58       ` Keith Wright
2002-04-26 17:05       ` Marius Vollmer
2002-04-28 19:46         ` Dirk Herrmann
2002-05-07 18:41           ` 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).