unofficial mirror of bug-guile@gnu.org 
 help / color / mirror / Atom feed
From: author@will.party
To: 58001@debbugs.gnu.org
Subject: bug#58001: Cannot use 'read' in imported library
Date: Thu, 22 Sep 2022 00:30:40 -0700	[thread overview]
Message-ID: <4VOLIR.1V2A6YW618L42@will.party> (raw)


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

                 reply	other threads:[~2022-09-22  7:30 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/guile/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4VOLIR.1V2A6YW618L42@will.party \
    --to=author@will.party \
    --cc=58001@debbugs.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).