unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
* Is this a bug?
@ 2011-08-16 12:36 rixed
  2011-08-22 22:47 ` Mark H Weaver
  0 siblings, 1 reply; 6+ messages in thread
From: rixed @ 2011-08-16 12:36 UTC (permalink / raw)
  To: guile-user

Here are two simple files :

---[ woe.scm ]---

(define-syntax without-exception
  (syntax-rules ()
                  ((without-exception key thunk ...)
				                   (catch key (lambda () thunk ...)
								   (lambda (a . r) #f)))))

---[ test.scm ]---

(load "woe.scm")
(without-exception #t (display "toto\n"))

---[ EOF ]---

Now let's run it. Notice I clean my guile cache.

% sudo rm -rf ~/.cache/guile 
% guile --version
guile (GNU Guile) 2.0.2.39-335c8
(...)
% guile -l test.scm 
;;; note: auto-compilation is enabled, set GUILE_AUTO_COMPILE=0
;;;       or pass the --no-auto-compile argument to disable.
;;; compiling /home/rixed/src/sact.junkie/test.scm
;;; /home/rixed/src/sact.junkie/test.scm:2:0: warning: possibly unbound variable `without-exception'
;;; compiled /home/rixed/.cache/guile/ccache/2.0-LE-8-2.0/home/rixed/src/sact.junkie/test.scm.go
;;; compiling /home/rixed/src/sact.junkie/woe.scm
;;; compiled /home/rixed/.cache/guile/ccache/2.0-LE-8-2.0/home/rixed/src/sact.junkie/woe.scm.go
toto
Backtrace:
In ice-9/boot-9.scm:
 170: 7 [catch #t #<catch-closure 155bd60> ...]
In unknown file:
   ?: 6 [catch-closure]
In ice-9/boot-9.scm:
  62: 5 [call-with-prompt prompt0 ...]
In ice-9/eval.scm:
 389: 4 [eval # #]
In ice-9/boot-9.scm:
2103: 3 [save-module-excursion #<procedure 181b280 at ice-9/boot-9.scm:3547:3 ()>]
3554: 2 [#<procedure 181b280 at ice-9/boot-9.scm:3547:3 ()>]
In unknown file:
   ?: 1 [load-compiled/vm "/home/rixed/.cache/guile/ccache/2.0-LE-8-2.0/home/rixed/src/sact.junkie/test.scm.go"]
In /home/rixed/src/sact.junkie/test.scm:
   2: 0 [#<procedure 19cc700 ()>]

/home/rixed/src/sact.junkie/test.scm:2:0: In procedure #<procedure 19cc700 ()>:
/home/rixed/src/sact.junkie/test.scm:2:0: Wrong type to apply: #<syntax-transformer without-exception>

This code used to work on guile 1.8, so what's wrong with it?
Also, setting GUILE_AUTO_COMPILE to 0 don't change anything, but incidentaly I discovered this:
Let's change the file permissions so that guile can no more write into it's cache, and lets touch
test.scm so that he'd like to recompile it:

% sudo chown root: -R ~/.cache/guile 
% touch test.scm
% guile -l test.scm
;;; note: source file /home/rixed/src/sact.junkie/test.scm
;;;       newer than compiled /home/rixed/.cache/guile/ccache/2.0-LE-8-2.0/home/rixed/src/sact.junkie/test.scm.go
;;; note: auto-compilation is enabled, set GUILE_AUTO_COMPILE=0
;;;       or pass the --no-auto-compile argument to disable.
;;; compiling /home/rixed/src/sact.junkie/test.scm
;;; WARNING: compilation of /home/rixed/src/sact.junkie/test.scm failed:
;;; ERROR: failed to create path for auto-compiled file "/home/rixed/src/sact.junkie/test.scm"
toto
GNU Guile 2.0.2.39-335c8
Copyright (C) 1995-2011 Free Software Foundation, Inc.

Guile comes with ABSOLUTELY NO WARRANTY; for details type `,show w'.
This program is free software, and you are welcome to redistribute it
under certain conditions; type `,show c' for details.

Enter `,help' for help.
scheme@(guile-user)>


No more backtrace!

What's taking place?
Any idea of a workaround (apart from playing with file permissions in my cache) ?




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

* Re: Is this a bug?
  2011-08-16 12:36 Is this a bug? rixed
@ 2011-08-22 22:47 ` Mark H Weaver
  2011-08-29 11:27   ` rixed
  0 siblings, 1 reply; 6+ messages in thread
From: Mark H Weaver @ 2011-08-22 22:47 UTC (permalink / raw)
  To: rixed; +Cc: guile-user

rixed@happyleptic.org wrote:
> ---[ woe.scm ]---
>
> (define-syntax without-exception
>   (syntax-rules ()
>                   ((without-exception key thunk ...)
> 				                   (catch key (lambda () thunk ...)
> 								   (lambda (a . r) #f)))))
>
> ---[ test.scm ]---
>
> (load "woe.scm")
> (without-exception #t (display "toto\n"))
>
> ---[ EOF ]---
[...]
> /home/rixed/src/sact.junkie/test.scm:2:0: In procedure #<procedure 19cc700 ()>:
> /home/rixed/src/sact.junkie/test.scm:2:0: Wrong type to apply: #<syntax-transformer without-exception>
>
> This code used to work on guile 1.8, so what's wrong with it?

The problem is that the compiler, while compiling test.scm, sees no
syntax declaration of `without-exception', and therefore assumes that
`without-exception' is simply a top-level variable.

A simple workaround is to use `(include "woe.scm")'.  I don't know the
full details, but my understanding is that unlike `load', `include'
causes the compiler to look for syntax declarations in the included
file.

Another solution (though guile-specific) is to make woe.scm a guile
module, and to use `use-modules' to import it.

    Best,
     Mark



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

* Re: Is this a bug?
  2011-08-22 22:47 ` Mark H Weaver
@ 2011-08-29 11:27   ` rixed
  2011-08-30 16:45     ` Mark H Weaver
  0 siblings, 1 reply; 6+ messages in thread
From: rixed @ 2011-08-29 11:27 UTC (permalink / raw)
  To: guile-user

> The problem is that the compiler, while compiling test.scm, sees no
> syntax declaration of `without-exception', and therefore assumes that
> `without-exception' is simply a top-level variable.

So, according to you, should I fill a bug report or I am overusing the
load directive ?




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

* Re: Is this a bug?
  2011-08-29 11:27   ` rixed
@ 2011-08-30 16:45     ` Mark H Weaver
  2011-08-30 17:21       ` rixed
  2011-08-30 17:24       ` Ian Price
  0 siblings, 2 replies; 6+ messages in thread
From: Mark H Weaver @ 2011-08-30 16:45 UTC (permalink / raw)
  To: rixed; +Cc: guile-user

rixed@happyleptic.org writes:
>> The problem is that the compiler, while compiling test.scm, sees no
>> syntax declaration of `without-exception', and therefore assumes that
>> `without-exception' is simply a top-level variable.
>
> So, according to you, should I fill a bug report or I am overusing the
> load directive ?

Andy would probably be a better person to answer this question, but I'll
take a stab at it.

I think you are overusing `load'.  In its most general form, `load'
interacts badly with ahead-of-time compilation, because it prevents the
compiler from being able to distinguish top-level procedure calls from
macro uses.  Without knowing the syntax of the program, a compiler is
practically useless.

`load' is optional in the R5RS, and it has been removed entirely from
the R6RS, which was designed with compilers in mind.  Guile allows the
use of `load', but its compiler assumes that undeclared identifiers are
top-level _variables_, not syntax.  This seems a reasonable compromise.

I can sympathize with the desire to use `load' for the sake of
portability, but if you try your `woe.scm' example with other
ahead-of-time Scheme compilers, I think you'll find that it's not
portable in practice.

     Best,
      Mark



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

* Re: Is this a bug?
  2011-08-30 16:45     ` Mark H Weaver
@ 2011-08-30 17:21       ` rixed
  2011-08-30 17:24       ` Ian Price
  1 sibling, 0 replies; 6+ messages in thread
From: rixed @ 2011-08-30 17:21 UTC (permalink / raw)
  To: guile-user

Your arguments are very convincing, sir.




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

* Re: Is this a bug?
  2011-08-30 16:45     ` Mark H Weaver
  2011-08-30 17:21       ` rixed
@ 2011-08-30 17:24       ` Ian Price
  1 sibling, 0 replies; 6+ messages in thread
From: Ian Price @ 2011-08-30 17:24 UTC (permalink / raw)
  To: guile-user

Mark H Weaver <mhw@netris.org> writes:
> `load' is optional in the R5RS, and it has been removed entirely from
> the R6RS, which was designed with compilers in mind.  Guile allows the
> use of `load', but its compiler assumes that undeclared identifiers are
> top-level _variables_, not syntax.  This seems a reasonable compromise.

While I more than agree with the compromise, perhaps a note could be
added to the documentation given 'load' has a different behaviour at the
REPL and in modules. In a module, we expect the above; at the REPL, we
want the syntax-definitions available. Perhaps something like

"Since 'load' happens at run-time, syntax definitions will have no
effect on existing procedures, although they will be available at the
REPL."

-- 
Ian Price

"Programming is like pinball. The reward for doing it well is
the opportunity to do it again" - from "The Wizardy Compiled"




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

end of thread, other threads:[~2011-08-30 17:24 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-08-16 12:36 Is this a bug? rixed
2011-08-22 22:47 ` Mark H Weaver
2011-08-29 11:27   ` rixed
2011-08-30 16:45     ` Mark H Weaver
2011-08-30 17:21       ` rixed
2011-08-30 17:24       ` Ian Price

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