Subject: bug#38760: closed (Re: bug#38760: R7RS define-library form is not supported)

From: [email-masked] (GNU bug Tracking System)
Date: Sun, 12 Jan 2020 19:34:02 +0000

Your bug report

#38760: R7RS define-library form is not supported

which was filed against the guile package, has been closed.

The explanation is attached below, along with your original report.
If you require more details, please reply to [email-masked].

-- 
38760: http://debbugs.gnu.org/cgi/bugreport.cgi?bug=38760
GNU Bug Tracking System
Contact [email-masked] with problems

Subject: Re: bug#38760: R7RS define-library form is not supported
From: Andy Wingo <[email-masked]>
To: Amirouche <[email-masked]>
Cc: [email-masked]
Date: Sun, 12 Jan 2020 20:33:06 +0100
List-Id: <debbugs-submit.debbugs.gnu.org>

Thanks for the report; fixed!  Patches welcome if there are any bugs :)

Cheers,

Andy

Subject: R7RS define-library form is not supported
From: Amirouche <[email-masked]>
To: [email-masked]
Date: Fri, 27 Dec 2019 08:44:36 +0000
List-Id: <debbugs-submit.debbugs.gnu.org>

Using guile-2.9.7.

Here is the tests files:

```scheme
$ cat main.scm
(import (scheme base))
(import (mylib))

(func)
$ cat mylib.scm
(define-library (mylib)

   (export func)

   (import (scheme base))
   (import (scheme write))

   (begin

     (define (func)
       (display 42)(newline))))
```

When i run `main.scm` with the `--r7rs` switch I get:

```
$ guile --r7rs -L . main.scm
guile: warning: failed to install locale
;;; note: auto-compilation is enabled, set GUILE_AUTO_COMPILE=0
;;;       or pass the --no-auto-compile argument to disable.
;;; compiling /tmp/guile/r7rs/main.scm
;;; compiling ./mylib.scm
;;; WARNING: compilation of ./mylib.scm failed:
;;; Syntax error:
;;; mylib.scm:10:4: definition in expression context, where definitions 
are not allowed, in form (define (func) (display 42) (newline))
;;; WARNING: compilation of /tmp/guile/r7rs/main.scm failed:
;;; Syntax error:
;;; mylib.scm:10:4: definition in expression context, where definitions 
are not allowed, in form (define (func) (display 42) (newline))
;;; compiling ./mylib.scm
;;; WARNING: compilation of ./mylib.scm failed:
;;; Syntax error:
;;; mylib.scm:10:4: definition in expression context, where definitions 
are not allowed, in form (define (func) (display 42) (newline))
ice-9/psyntax.scm:2800:12: In procedure syntax-violation:
Syntax error:
mylib.scm:10:4: definition in expression context, where definitions are 
not allowed, in form (define (func) (display 42) (newline))
```

Removing the define-library's begin does not help.

Replacing define-library with library does lead to another error:

```scheme
$ guile --r7rs -L . main.scm
guile: warning: failed to install locale
;;; note: auto-compilation is enabled, set GUILE_AUTO_COMPILE=0
;;;       or pass the --no-auto-compile argument to disable.
;;; compiling /tmp/guile/r7rs/main.scm
;;; compiling ./mylib.scm
;;; mylib.scm:6:2: warning: possibly unbound variable `import'
;;; mylib.scm:6:2: warning: possibly unbound variable `scheme'
;;; mylib.scm:6:2: warning: possibly unbound variable `write'
;;; <unknown-location>: warning: possibly unbound variable `display'
;;; compiled 
/home/amirouche/.cache/guile/ccache/3.0-LE-8-4.1/tmp/guile/r7rs/mylib.scm.go
;;; WARNING: compilation of /tmp/guile/r7rs/main.scm failed:
;;; Unbound variable: import
Backtrace:
            3 (primitive-load "/tmp/guile/r7rs/main.scm")
In ice-9/eval.scm:
    187:27  2 (_ _)
    223:20  1 (proc #<directory (guile-user) 7fcabe1def00>)
In unknown file:
            0 (%resolve-variable (7 . func) #<directory (guile-user) ?>)

ERROR: In procedure %resolve-variable:
Unbound variable: func
```

It says unbound `import` variable.  Add (import (only (guile) import)) 
on top make it work:

```scheme
$ cat mylib.scm
(library (mylib)

   (export func)

   (import (only (guile) import))
   (import (scheme base))
   (import (scheme write))

   (begin
     (define (func)
       (display 42)(newline))))
$ guile --r7rs -L . main.scm
guile: warning: failed to install locale
42
```