I have these two R7RS libraries, which I enter into the Guile REPL one by one:
(define-library (example one)
(import (scheme base))
(export f)
(begin
(define (f x)
(+ x 1))))
(define-library (example two)
(import (scheme base))
(export g)
(begin
(define (g x)
(* x 2))))
When I enter the second library definition in the Guile REPL, I get this error:
While compiling expression:
Syntax error:
unknown file:13:4: definition in expression context, where definitions are not allowed, in form (define (g x) (* x 2))
I tried to put the two libraries into the same file (mylibs.sld) and ran guile mylibs.sld, but I get exactly the same error.
From my understanding, I am getting this error because define-library somehow becomes undefined by the time Guile reads the second library definition. Guile no longer knows what define-library means. This is strange behavior. What is going on? How do I define two R7RS libraries in the REPL?
Guile version: 3.0.1
If you just want to define them at the repl, you can do this by setting the current module to
(guile-user). Like you have guessed, after the firstdefine-librarythe compiler is in a state where the symbols available by default in(guile-user)are unavailable.So if you do a
,m (guile-user)between defining the two libraries you will be fine.I am not sure about how to do get this to work from a single file(lib per file works fine). I tried to set the current module to
(guile-user)witheval-whenafter the first library but even the symboleval-whenwas unavailable. Must be a bug.