unofficial mirror of bug-guile@gnu.org 
 help / color / mirror / Atom feed
* bug#58001: Cannot use 'read' in imported library
@ 2022-09-22  7:30 author
  0 siblings, 0 replies; only message in thread
From: author @ 2022-09-22  7:30 UTC (permalink / raw)
  To: 58001


[-- Attachment #1.1: Type: text/plain, Size: 1284 bytes --]

I'm using Guile version 3.0.5 from the Guix repository.

I've run into a strange issue with the read function from (scheme 
base). It cannot be used in an R7RS-style library. This only seems to 
apply to the read function. Other standard procedures work fine.

Let's say you have a library that uses read. Maybe it looks like this:

;; File: foo.scm
(define-library (foo)
  (import (scheme base))
  (export read-wrapped)
  (begin
    (define (read-wrapped port) (read port))))

Now, let's say you want to import that library somewhere else and use 
it's exported function read-wrapped:

;; File: main.scm
(import (scheme base))
(import (foo))
(display (read (current-input-port)))
(display (read-wrapped (current-input-port)))

If you try to run that main script (in the same directory as the foo 
library):

GUILE_LOAD_PATH=. guile --r7rs main.scm

You can enter get a datum for the first call to read, then you'll get 
an error for the second call:

foo.scm:1:0: In procedure read-wrapped:
Unbound variable: read

This only happens with read. If you replace read with a different 
standard procedure like boolean? then everything is fine (you'll see #f 
twice because the input port fails the predicate).

I'm pretty baffled. I've attached the dummy source files for 
convenience.


[-- Attachment #1.2: Type: text/html, Size: 2471 bytes --]

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2.1: foo.scm --]
[-- Type: text/x-scheme, Size: 127 bytes --]

(define-library (foo)
  (import (scheme base))
  (export read-wrapped)
  (begin
    (define (read-wrapped port) (read port))))

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2.2: main.scm --]
[-- Type: text/x-scheme, Size: 123 bytes --]

(import (scheme base))
(import (foo))

(display (read (current-input-port)))
(display (read-wrapped (current-input-port)))

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2022-09-22  7:30 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-09-22  7:30 bug#58001: Cannot use 'read' in imported library author

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