* Guile import issue
@ 2023-06-14 20:15 Zelphir Kaltstahl
2023-06-15 9:59 ` Unstable Horse via General Guile related discussions
2023-06-15 10:29 ` Jean Abou Samra
0 siblings, 2 replies; 6+ messages in thread
From: Zelphir Kaltstahl @ 2023-06-14 20:15 UTC (permalink / raw)
To: Guile User
Hello Guile Users!
I have now created a minimal example of the import bug or issue I am observing:
~~~~rectangular.scm~~~~
(library (rectangular)
(export real-part)
(import (except (rnrs base) error)
(only (guile)
lambda* λ))
(define real-part
(λ (num)
(car num))))
~~~~
~~~~solution.scm~~~~
(import (except (rnrs base) error)
(only (guile)
lambda* λ)
(prefix (rectangular) rect:))
(define real-part
(λ (datum)
(rect:real-part datum)))
(real-part '(1 . 2))
~~~~
~~~~shell~~~~
$ guile --version
guile (GNU Guile) 3.0.9
Copyright (C) 2023 Free Software Foundation, Inc.
License LGPLv3+: GNU LGPL 3 or later<http://gnu.org/licenses/lgpl.html>.
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
$ guile -L . solution.scm
Backtrace:
In ice-9/boot-9.scm:
1752:10 6 (with-exception-handler _ _ #:unwind? _ # _)
In unknown file:
5 (apply-smob/0 #<thunk 7fc30540b300>)
In ice-9/boot-9.scm:
724:2 4 (call-with-prompt ("prompt") #<procedure 7fc30541bf80 …> …)
In ice-9/eval.scm:
619:8 3 (_ #(#(#<directory (guile-user) 7fc30540ec80>)))
In ice-9/boot-9.scm:
2836:4 2 (save-module-excursion #<procedure 7fc3053ff210 at ice-…>)
4388:12 1 (_)
In unknown file:
0 (real-part (1 . 2))
ERROR: In procedure real-part:
In procedure real-part: Wrong type argument in position 1: (1 . 2)
~~~~
As you can see, Guile complains about getting a pair as argument for
`real-part'. This is, because it still tries to use the original `real-part',
rather than the one I imported. I am calling `real-part' by using
`rect:real-part', so it should be even clearer, which `real-part' function it is
supposed to use.
This feels like a bug to me. Am I overlooking something very simple, or
misunderstanding something fundamental about modules or imports? I am really
surprised, that I have not hit this earlier in my Guile usage. Is this perhaps
only in 3.0.9?
Best regards,
Zelphir
--
repositories:https://notabug.org/ZelphirKaltstahl
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Guile import issue
2023-06-14 20:15 Guile import issue Zelphir Kaltstahl
@ 2023-06-15 9:59 ` Unstable Horse via General Guile related discussions
2023-06-15 12:27 ` Zelphir Kaltstahl
2023-06-15 10:29 ` Jean Abou Samra
1 sibling, 1 reply; 6+ messages in thread
From: Unstable Horse via General Guile related discussions @ 2023-06-15 9:59 UTC (permalink / raw)
To: Zelphir Kaltstahl, Guile User
Hmm, if I rewrite your rectangular.scm to:
~~~~rectangular.scm~~~~
(define-module (rectangular)
#:use-module ((guile) #:select ((lambda* . λ)))
#:export (real-part))
(define real-part
(λ (num)
(car num)))
~~~~
This works both with `import' and `use-modules', so the problem might
be somewhere in `library'.
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Guile import issue
2023-06-14 20:15 Guile import issue Zelphir Kaltstahl
2023-06-15 9:59 ` Unstable Horse via General Guile related discussions
@ 2023-06-15 10:29 ` Jean Abou Samra
2023-06-15 10:33 ` Jean Abou Samra
1 sibling, 1 reply; 6+ messages in thread
From: Jean Abou Samra @ 2023-06-15 10:29 UTC (permalink / raw)
To: Zelphir Kaltstahl, Guile User
[-- Attachment #1: Type: text/plain, Size: 2003 bytes --]
I agree, it seems like a bug.
Here is a slightly more minimal example:
```
$ cat rectangular.scm
(library (rectangular)
(export real-part)
(import (guile))
(define real-part car))
$ cat solution.scm
(use-modules ((rectangular) #:prefix rect:))
(display (rect:real-part '(1 . 2)))
$ guile3.0 --fresh-auto-compile -L . solution.scm
[...]
ERROR: In procedure real-part:
In procedure real-part: Wrong type argument in position 1: (1 . 2)
```
On the other hand, this doesn't happen if you replace rectangular.scm with
```
(define-module (rectangular)
#:export (real-part))
(define real-part car)
```
I think the implementation of the R6RS library form is to blame here: look at this.
```
scheme@(guile-user)> ,expand (library (rectangular) (export real-part) (import (guile)) (define real-part car))
$1 = (begin
(let ((m ((@@ (guile) define-module*)
'(rectangular)
#:filename
#f
#:pure
#t
#:version
'()
#:declarative?
#t)))
((@@ (guile) set-current-module) m)
m)
(let ((iface ((@@ (guile) resolve-r6rs-interface) '(guile))))
((@@ (guile) call-with-deferred-observers)
(lambda ()
((@@ (guile) module-use-interfaces!)
((@@ (guile) current-module))
((@@ (guile) list) iface)))))
(if #f #f)
((@@ (guile) call-with-deferred-observers)
(lambda ()
((@@ (guile) module-export!)
((@@ (guile) current-module))
'())))
((@@ (guile) call-with-deferred-observers)
(lambda ()
((@@ (guile) module-re-export!)
((@@ (guile) current-module))
'(real-part))))
((@@ (guile) call-with-deferred-observers)
(lambda ()
((@@ (guile) module-replace!)
((@@ (guile) current-module))
'())))
(define real-part car))
```
As you can see, the library macro has turned the (export real-part) part into a re-export from (guile).
[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 228 bytes --]
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Guile import issue
2023-06-15 10:29 ` Jean Abou Samra
@ 2023-06-15 10:33 ` Jean Abou Samra
2023-06-15 12:25 ` Zelphir Kaltstahl
0 siblings, 1 reply; 6+ messages in thread
From: Jean Abou Samra @ 2023-06-15 10:33 UTC (permalink / raw)
To: Zelphir Kaltstahl, Guile User
[-- Attachment #1: Type: text/plain, Size: 639 bytes --]
Le jeudi 15 juin 2023 à 12:29 +0200, Jean Abou Samra a écrit :
> As you can see, the library macro has turned the (export real-part) part into a re-export from (guile).
Sigh. This is the code from `module/ice-9/r6rs-libraries.scm`:
```
(define (compute-exports ifaces specs)
(define (re-export? sym)
(or-map (lambda (iface) (module-variable iface sym)) ifaces))
(define (replace? sym)
(module-variable the-scm-module sym))
```
This will just treat anything as re-export if it's defined in one of the imported modules, even if the module being defined also has a same-named binding...
[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 228 bytes --]
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Guile import issue
2023-06-15 10:33 ` Jean Abou Samra
@ 2023-06-15 12:25 ` Zelphir Kaltstahl
0 siblings, 0 replies; 6+ messages in thread
From: Zelphir Kaltstahl @ 2023-06-15 12:25 UTC (permalink / raw)
To: Jean Abou Samra; +Cc: stable.master, Guile User
On 6/15/23 12:33, Jean Abou Samra wrote:
>
> Le jeudi 15 juin 2023 à 12:29 +0200, Jean Abou Samra a écrit :
>
>> As you can see, the library macro has turned the (export real-part) part into
>> a re-export from (guile).
>>
> Sigh. This is the code from |module/ice-9/r6rs-libraries.scm|:
>
> |(define (compute-exports ifaces specs) (define (re-export? sym) (or-map
> (lambda (iface) (module-variable iface sym)) ifaces)) (define (replace? sym)
> (module-variable the-scm-module sym)) |
>
> This will just treat anything as re-export if it's defined in one of the
> imported modules, even if the module being defined also has a same-named
> binding...
>
Hello Jean!
I should learn how to check these things myself in the Guile sources. Thank you
for that.
This is what I suspected from the behavior I saw.
OK, should I raise this on the Guile developers list?
I can work around it by using define-module in my repo for now. Not mission
critical, although I usually prefer using more "portable" expressions, when I can.
Best regards,
Zelphir
--
repositories:https://notabug.org/ZelphirKaltstahl
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2023-06-15 12:27 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-06-14 20:15 Guile import issue Zelphir Kaltstahl
2023-06-15 9:59 ` Unstable Horse via General Guile related discussions
2023-06-15 12:27 ` Zelphir Kaltstahl
2023-06-15 10:29 ` Jean Abou Samra
2023-06-15 10:33 ` Jean Abou Samra
2023-06-15 12:25 ` Zelphir Kaltstahl
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).