Subject: Re: possible doc bug in guile manual

From: George Demmy <[email-masked]>
Date: Fri, 14 Oct 2022 16:04:53 -0500

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-masked]> 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: