bug#58529: possible doc bug in guile manual

George Demmy <[email protected]>
Newsgroups gmane.lisp.guile.bugs
Message-ID <CA+7PDU1m0X=k5aMWCfYArpfwj5szfD49RFpJc+EZt-s9=Lfrmw@mail.gmail.com>
Sorry about the fat finger automagic send from gmail...

Reading through the gnu manual, I wanted to get a better handle on
some of @ module syntax introduced in:
https://www.gnu.org/software/guile/manual/html_node/Scripting-Examples.html
I cut and pasted fact and choose into their own files.

I used this version of choose:

#!/usr/bin/env sh
exec guile -l fact -e '(@ (fac) main)' -s "$0" "$@"
!#
(define-module (fac)
  #:export (main))

(define (choose n m)
  (/ (fact m) (* (fact (- m n)) (fact n))))

(define (main args)
  (let ((n (string->number (cadr args)))
        (m (string->number (caddr args))))
    (display (choose n m))
    (newline)))

It was pure cut and paste, no edits save changing /usr/local/bin/guile
to /usr/bin/guile. Running choose I got

./choose:8:6: In procedure main: Unbound variable: fact

I wondered if there was something going on with -l fact, so I changed
the args for choose to:

exec guile -l fact -e main -s "$0" "$@"

and it indeed ran main from fact. Then I changed it to:

exec guile -l fact -e fact -s "$0" "$@"

and it unsurprisingly yielded:

fact:5:6: In procedure fact:
In procedure =: Wrong type argument in position 1: ("./choose.scm" "4")

So, guile is loading fact (the file and its contents), but it seems
that define-module has got something to do with it.

This is guile 3.0.8 on an up-to-date cygwin. You get similar behavior
on guile 2.0.14 on OpenSUSE LEAP 15.3.

Regards,

George Demmy

On Fri, Oct 14, 2022 at 3:48 PM George Demmy <[email protected]> wrote:
>
> Hi,
>
> Reading through the gnu manual, I wanted to get a better handle on
> some of @ module syntax introduced in:
> https://www.gnu.org/software/guile/manual/html_node/Scripting-Examples.html
> I cut and pasted fact and choose into their own files.
>
> I used this version of choose:
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.