bug#52218: Unable to define more than one R7RS library per file

2021-12-01 Thread Bug reports for GUILE, GNU's Ubiquitous Extension Language
On 2021-12-01 11:00 +0100, Linus Björnstam wrote:
> This is in line with the limitations of guile's R6RS implementation. I
> think this is a long standing, low priority bug. It has to do with the
> expansion of library (or define-library in this case) not properly
> resetting the current module.
>
> In the manual there is a section called "R6RS incompatibilities" that
> mentions this. Maybe an "R7RS incompatibilities" should be added.

Hi Linus,

There already exist a page in the manual about "Incompatibilities with
the R7RS" [1]. Perhaps a paragraph similar to that found in the R6RS
incompatibilities page should be added to the R7RS incompatibilities
page. Something like this:

"Multiple @code{define-library} forms in one file are not yet supported.
This is because the expansion of @code{define-library} sets the current
module, but does not restore it.  This is a bug."

[1]: 
https://www.gnu.org/software/guile/manual/html_node/R7RS-Incompatibilities.html





bug#52230: Variable not visible to compiler causes compilation failure when importing module

2021-12-01 Thread Jean Abou Samra

In experiments with using guild for byte compilation
in LilyPond, I am hitting what seems like a bug. When
a variable is not defined declaratively in a way that
makes the compiler aware of it, the module it is
defined in can compile, but modules using it cannot.
Here is an example. fail.scm contains:

(define-module (fail))

variable-coming-from-somewhere-but-not-known-at-compile-time


import.scm is just:

(use-modules (fail))


Compiling fail.scm works:

$ guild compile fail.scm
fail.scm:3:0: warning: possibly unbound variable 
`variable-coming-from-somewhere-but-not-known-at-compile-time'

wrote `/home/jean/.cache/guile/ccache/3.0-LE-8-4.4/.../fail.scm.go'

Compiling import.scm gives this traceback:

$ guild compile -L . import.scm
Backtrace:
In system/base/compile.scm:
   327:39 19 (read-and-compile # #:from _ #:to …)
   261:27 18 (_ _ _)
In ice-9/boot-9.scm:
   2835:4 17 (save-module-excursion #)
In language/scheme/compile-tree-il.scm:
    31:15 16 (_)
In ice-9/psyntax.scm:
  1230:36 15 (expand-top-sequence (#) …)
  1222:19 14 (parse _ (("placeholder" placeholder)) ((top) #(# # …)) …)
   259:10 13 (parse _ (("placeholder" placeholder)) (()) _ c (# #) #)
In ice-9/boot-9.scm:
  3927:20 12 (process-use-modules _)
   222:17 11 (map1 (((fail
  3928:31 10 (_ ((fail)))
  3326:17  9 (resolve-interface (fail) #:select _ #:hide _ #:prefix _ …)
In ice-9/threads.scm:
    390:8  8 (_ _)
In ice-9/boot-9.scm:
  3252:13  7 (_)
In ice-9/threads.scm:
    390:8  6 (_ _)
In ice-9/boot-9.scm:
  3536:20  5 (_)
   2835:4  4 (save-module-excursion #)
  3556:26  3 (_)
In unknown file:
   2 (primitive-load-path "fail" #)
In fail.scm:
  3:0  1 (_)
In ice-9/boot-9.scm:
  1685:16  0 (raise-exception _ #:continuable? _)

ice-9/boot-9.scm:1685:16: In procedure raise-exception:
Unbound variable: 
variable-coming-from-somewhere-but-not-known-at-compile-time



I would appreciate any workarounds.





bug#52218: Unable to define more than one R7RS library per file

2021-12-01 Thread Linus Björnstam
Hi Sam!

I am not a maintainer , nor a very proficient guile hacker, but I do have some 
input.

This is in line with the limitations of guile's R6RS implementation. I think 
this is a long standing, low priority bug. It has to do with the expansion of 
library (or define-library in this case) not properly resetting the current 
module. 

In the manual there is a section called "R6RS incompatibilities" that mentions 
this. Maybe an "R7RS incompatibilities" should be added.


Best regards
  Linus Björnstam

On Wed, 1 Dec 2021, at 08:45, Sam Lee via Bug reports for GUILE, GNU's 
Ubiquitous Extension Language wrote:
> Guile is unable to handle more than one define-library per file. For
> example, this is "mylibs.sld", which contains two define-library:
>
> (define-library (example mylib)
>   (import (scheme base))
>   (export f)
>   (begin
> (define (f x)
>   (+ x 1
>
> (define-library (example main)
>   (import (scheme base)
>   (scheme write)
>   (example mylib))
>   (export main)
>   (begin
> (define (main)
>   (display "The answer is: ")
>   (display (f 1))
>   (newline
>
>
> When loading this file into Guile using "guile -l mylibs.sld", or by
> using (load "mylibs.sld"), Guile will show this error:
>
> ;;; note: auto-compilation is enabled, set GUILE_AUTO_COMPILE=0
> ;;;   or pass the --no-auto-compile argument to disable.
> ;;; compiling /home/user/mylibs.sld
> ;;; WARNING: compilation of /home/user/mylibs.sld failed:
> ;;; Syntax error:
> ;;; unknown location: definition in expression context, where 
> definitions are not allowed, in form (define (main) (display "The 
> answer is: ") (display (f 1)) (newline))
> ice-9/psyntax.scm:2794:12: In procedure syntax-violation:
> Syntax error:
> /home/user/mylibs.sld:14:4: definition in expression context, where 
> definitions are not allowed, in form (define (main) (display "The 
> answer is: ") (display (f 1)) (newline))
>
>
> The error is always caused by the second define-library. Apparently,
> Guile no longer understands that define-library is a special form by the
> time the second define-library is evaluated. Is it not possible to
> define two R7RS libraries in the same file?
>
> Guile version: 3.0.7





bug#52218: Unable to define more than one R7RS library per file

2021-12-01 Thread Bug reports for GUILE, GNU's Ubiquitous Extension Language
Guile is unable to handle more than one define-library per file. For
example, this is "mylibs.sld", which contains two define-library:

(define-library (example mylib)
  (import (scheme base))
  (export f)
  (begin
(define (f x)
  (+ x 1

(define-library (example main)
  (import (scheme base)
  (scheme write)
  (example mylib))
  (export main)
  (begin
(define (main)
  (display "The answer is: ")
  (display (f 1))
  (newline


When loading this file into Guile using "guile -l mylibs.sld", or by
using (load "mylibs.sld"), Guile will show this error:

;;; note: auto-compilation is enabled, set GUILE_AUTO_COMPILE=0
;;;   or pass the --no-auto-compile argument to disable.
;;; compiling /home/user/mylibs.sld
;;; WARNING: compilation of /home/user/mylibs.sld failed:
;;; Syntax error:
;;; unknown location: definition in expression context, where definitions are 
not allowed, in form (define (main) (display "The answer is: ") (display (f 1)) 
(newline))
ice-9/psyntax.scm:2794:12: In procedure syntax-violation:
Syntax error:
/home/user/mylibs.sld:14:4: definition in expression context, where definitions 
are not allowed, in form (define (main) (display "The answer is: ") (display (f 
1)) (newline))


The error is always caused by the second define-library. Apparently,
Guile no longer understands that define-library is a special form by the
time the second define-library is evaluated. Is it not possible to
define two R7RS libraries in the same file?

Guile version: 3.0.7