unofficial mirror of guile-devel@gnu.org 
 help / color / mirror / Atom feed
* Problems with LOAD and latest build
@ 2009-08-29 15:49 Barry Fishman
  2009-08-30 14:17 ` Andy Wingo
  0 siblings, 1 reply; 6+ messages in thread
From: Barry Fishman @ 2009-08-29 15:49 UTC (permalink / raw)
  To: guile-devel

This concerns an August 28 build of guile master.

I have a simple syntax definition:

(define-syntax dotimes
  (syntax-rules ()
    ((dotimes (<var> <count>) <body> ...)
     (let ((count <count>))
       (let loop ((<var> 0))
	 (if (< <var> count)
	     (begin
	       <body> ...
	       (loop (+ <var> 1)))
	     #f))))
    ((dotimes (<var> <count> <return>) <body> ...)
     (let ((count <count>))
       (let loop ((<var> 0))
	 (if (< <var> count)
	     (begin
	       <body> ...
	       (loop (+ <var> 1)))
	     <return>))))))

If I store it in a file "dotimes.scm" and use the script "tryme"

#! /bin/sh
# -*- scheme -*-
exec guile -s "$0" $*
!#

(load "dotimes.scm")

(dotimes (indx 5)
  (display indx)
  (newline))

I get the following output:

$ ./tryme
;;; note: autocompilation is enabled, set GUILE_AUTO_COMPILE=0
;;;       or pass the --no-autocompile argument to disable.
;;; compiling ./tryme
;;; compiled /home2/barry/.cache/guile/ccache/1.9-0.D-LE-8/home2/barry/work/tryme.go
;;; compiling dotimes.scm
;;; compiled /home2/barry/.cache/guile/ccache/1.9-0.D-LE-8/home2/barry/work/dotimes.scm.go
ERROR: In procedure module-lookup:
ERROR: unbound variable: indx

Also (from a clean cache)

$ guile
;;; note: autocompilation is enabled, set GUILE_AUTO_COMPILE=0
;;;       or pass the --no-autocompile argument to disable.
;;; compiling /home/util64/guile/share/guile/1.9/ice-9/readline.scm
;;; compiled /home2/barry/.cache/guile/ccache/1.9-0.D-LE-8/home/util64/guile/share/guile/1.9/ice-9/readline.scm.go
Guile Scheme interpreter 0.5 on Guile 1.9.2
Copyright (C) 2001-2008 Free Software Foundation, Inc.

Enter `,help' for help.
scheme@(guile-user)> (load "tryme")
;;; compiling tryme
;;; compiled /home2/barry/.cache/guile/ccache/1.9-0.D-LE-8/home2/barry/work/tryme.go
;;; compiling dotimes.scm
;;; compiled /home2/barry/.cache/guile/ccache/1.9-0.D-LE-8/home2/barry/work/dotimes.scm.go
ERROR: In procedure module-lookup:
ERROR: unbound variable: indx
scheme@(guile-user)>

And from a clean cache:

$ guile
;;; note: autocompilation is enabled, set GUILE_AUTO_COMPILE=0
;;;       or pass the --no-autocompile argument to disable.
;;; compiling /home/util64/guile/share/guile/1.9/ice-9/readline.scm
;;; compiled /home2/barry/.cache/guile/ccache/1.9-0.D-LE-8/home/util64/guile/share/guile/1.9/ice-9/readline.scm.go
Guile Scheme interpreter 0.5 on Guile 1.9.2
Copyright (C) 2001-2008 Free Software Foundation, Inc.

Enter `,help' for help.
scheme@(guile-user)> (load "dotimes.scm")
;;; compiling dotimes.scm
;;; compiled /home2/barry/.cache/guile/ccache/1.9-0.D-LE-8/home2/barry/work/dotimes.scm.go
scheme@(guile-user)>
$ ./tryme
;;; note: autocompilation is enabled, set GUILE_AUTO_COMPILE=0
;;;       or pass the --no-autocompile argument to disable.
;;; compiling ./tryme
;;; compiled /home2/barry/.cache/guile/ccache/1.9-0.D-LE-8/home2/barry/work/tryme.go
ERROR: In procedure module-lookup:
ERROR: unbound variable: indx
$

But (also with a clean cache):

$ guile
;;; note: autocompilation is enabled, set GUILE_AUTO_COMPILE=0
;;;       or pass the --no-autocompile argument to disable.
;;; compiling /home/util64/guile/share/guile/1.9/ice-9/readline.scm
;;; compiled /home2/barry/.cache/guile/ccache/1.9-0.D-LE-8/home/util64/guile/share/guile/1.9/ice-9/readline.scm.go
Guile Scheme interpreter 0.5 on Guile 1.9.2
Copyright (C) 2001-2008 Free Software Foundation, Inc.

Enter `,help' for help.
scheme@(guile-user)> (load "dotimes.scm")
;;; compiling dotimes.scm
;;; compiled /home2/barry/.cache/guile/ccache/1.9-0.D-LE-8/home2/barry/work/dotimes.scm.go
scheme@(guile-user)> (load "tryme")
;;; compiling tryme
;;; compiled /home2/barry/.cache/guile/ccache/1.9-0.D-LE-8/home2/barry/work/tryme.go
0
1
2
3
4
#f
scheme@(guile-user)>
$ ./tryme
0
1
2
3
4
$

-- 
Barry Fishman





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

* Re: Problems with LOAD and latest build
  2009-08-29 15:49 Problems with LOAD and latest build Barry Fishman
@ 2009-08-30 14:17 ` Andy Wingo
  2009-08-30 15:54   ` Barry Fishman
  2009-08-31  8:46   ` Ludovic Courtès
  0 siblings, 2 replies; 6+ messages in thread
From: Andy Wingo @ 2009-08-30 14:17 UTC (permalink / raw)
  To: Barry Fishman; +Cc: guile-devel

Hi Barry,

Thank you for the bug report, it was quite interesting.

On Sat 29 Aug 2009 17:49, Barry Fishman <barry_fishman@acm.org> writes:

> #! /bin/sh
> # -*- scheme -*-
> exec guile -s "$0" $*
> !#
>
> (load "dotimes.scm")
>
> (dotimes (indx 5)
>   (display indx)
>   (newline))

When compiling tryme, what happens is that `(load "dotimes.scm")' gets
compiled into a load at runtime -- but the dotimes.scm isn't loaded at
compile time.

Normally this wouldn't be a problem, but really what you want in this
case is for dotimes.scm to be loaded at compile time as well -- so that
the `dotimes' syntactic definition is present, so that the `dotimes'
invocation in `tryme' expands out to the right thing, instead of a call
to the dotimes function with three arguments.

So, your solutions are to either:

  (eval-when (eval load compile)
    (load "dotimes.scm"))

Or to put dotimes in a module. (Loading modules happens at compile time
as well.)


Now, does this indicate a bug in Guile, or at least an undesirable
behavior? That I do not know. You need to be careful with `load', that
if it provides syntactic definitions, you should probably load it at
compile time as well. This part of R5RS Scheme is somewhat
underspecified. Other schemes provide various load-for-syntax forms, or
loading modules for syntax forms.

For now what I would suggest is that you put your macro in a module.
Otherwise, do the eval-when dance. Or, if you have a better idea about
how this should work, I'd be interested in that, too.

Cheers,

Andy
-- 
http://wingolog.org/




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

* Re: Problems with LOAD and latest build
  2009-08-30 14:17 ` Andy Wingo
@ 2009-08-30 15:54   ` Barry Fishman
  2009-08-31  8:46   ` Ludovic Courtès
  1 sibling, 0 replies; 6+ messages in thread
From: Barry Fishman @ 2009-08-30 15:54 UTC (permalink / raw)
  To: guile-devel


Andy Wingo <wingo@pobox.com> writes:
> Thank you for the bug report, it was quite interesting.

Thank you for your clear explanation, and your solutions are
simple to implement.

> When compiling tryme, what happens is that `(load "dotimes.scm")' gets
> compiled into a load at runtime -- but the dotimes.scm isn't loaded at
> compile time.
> ....
> Now, does this indicate a bug in Guile, or at least an undesirable
> behavior? That I do not know. You need to be careful with `load', that
> if it provides syntactic definitions, you should probably load it at
> compile time as well. This part of R5RS Scheme is somewhat
> underspecified. Other schemes provide various load-for-syntax forms, or
> loading modules for syntax forms.

The problem came up when I was testing some of my old code against the
git master branch.  With an addition of:

(use-syntax (ice-9 syncase))

to the main script the test case works fine with the 1.8 releases,
so I was surprised by the change of behavior.  I though it had worked
with 1.9.1 but I probably didn't try it.  It definitely did not work
in the last two 1.9 snapshots I made, where guile-lib is also broken.

The error message complained about "indx" but not "dotimes", and I
jumped to the (wrong) conclusion that it was a problem during macro
expansion, due to changes in the syntax expansion code.

Thanks again.
-- 
Barry Fishman





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

* Re: Problems with LOAD and latest build
  2009-08-30 14:17 ` Andy Wingo
  2009-08-30 15:54   ` Barry Fishman
@ 2009-08-31  8:46   ` Ludovic Courtès
  2009-09-03  8:43     ` Andy Wingo
  1 sibling, 1 reply; 6+ messages in thread
From: Ludovic Courtès @ 2009-08-31  8:46 UTC (permalink / raw)
  To: guile-devel

Hi,

Andy Wingo <wingo@pobox.com> writes:

> Now, does this indicate a bug in Guile, or at least an undesirable
> behavior?

Yes, I think so.

Programs that want to rely on bare R5RS (e.g., SILex) have nothing else
but `load' to have code in separate files.  So I think the compiler
should special-case top-level `load', `primitive-load', etc., calls.

What do you think?

Thanks,
Ludo'.





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

* Re: Problems with LOAD and latest build
  2009-08-31  8:46   ` Ludovic Courtès
@ 2009-09-03  8:43     ` Andy Wingo
  2009-09-03 16:14       ` Ludovic Courtès
  0 siblings, 1 reply; 6+ messages in thread
From: Andy Wingo @ 2009-09-03  8:43 UTC (permalink / raw)
  To: Ludovic Courtès; +Cc: guile-devel

On Mon 31 Aug 2009 10:46, ludo@gnu.org (Ludovic Courtès) writes:

> Hi,
>
> Andy Wingo <wingo@pobox.com> writes:
>
>> Now, does this indicate a bug in Guile, or at least an undesirable
>> behavior?
>
> Yes, I think so.
>
> Programs that want to rely on bare R5RS (e.g., SILex) have nothing else
> but `load' to have code in separate files.  So I think the compiler
> should special-case top-level `load', `primitive-load', etc., calls.

Programs that rely on bare R5RS still need some help in Guile 1.8 to
load up syntax-rules. If they don't load up syntax-rules, they can't
define macros (barring defmacro which is not R5RS), and without there's
no difference between load and load-for-syntax.

Also this runs into other issues:

    (define (my-load foo)
      (warn "something")
      (load foo))

Or

    (define (my-load2 foo)
      (load (frob foo)))

> What do you think?

If there is a sensible thing to do here, I'm happy to do it. But I don't
yet see what that thing is.

Andy
-- 
http://wingolog.org/




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

* Re: Problems with LOAD and latest build
  2009-09-03  8:43     ` Andy Wingo
@ 2009-09-03 16:14       ` Ludovic Courtès
  0 siblings, 0 replies; 6+ messages in thread
From: Ludovic Courtès @ 2009-09-03 16:14 UTC (permalink / raw)
  To: guile-devel

Andy Wingo <wingo@pobox.com> writes:

> On Mon 31 Aug 2009 10:46, ludo@gnu.org (Ludovic Courtès) writes:

[...]

>> Programs that want to rely on bare R5RS (e.g., SILex) have nothing else
>> but `load' to have code in separate files.  So I think the compiler
>> should special-case top-level `load', `primitive-load', etc., calls.
>
> Programs that rely on bare R5RS still need some help in Guile 1.8 to
> load up syntax-rules. If they don't load up syntax-rules, they can't
> define macros (barring defmacro which is not R5RS), and without there's
> no difference between load and load-for-syntax.

Actually, in the absence of macros (as is the case with SILex), it
doesn't matter whether `load' is done at expansion time or compile time,
after all.  So this kind of code should be fine either way.

You're probably right that there's no Right Thing when macros come into
play.

Thanks,
Ludo'.





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

end of thread, other threads:[~2009-09-03 16:14 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-08-29 15:49 Problems with LOAD and latest build Barry Fishman
2009-08-30 14:17 ` Andy Wingo
2009-08-30 15:54   ` Barry Fishman
2009-08-31  8:46   ` Ludovic Courtès
2009-09-03  8:43     ` Andy Wingo
2009-09-03 16:14       ` Ludovic Courtès

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