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
```