Subject: bug#36682: Error in Guile scripting examples

From: Maxim Cournoyer <[email-masked]>
Date: Mon, 12 Dec 2022 20:08:28 -0500

Hi,

Maxim Cournoyer <[email-masked]> writes:

[...]

> I have the following two files:
>
> fact:
>
> #!/run/current-system/profile/bin/guile \
> -e main -s
> !#
> (define-module (fact)
>  #:export (fact))
>
> (define (fact n)
>   (if (zero? n) 1
>     (* n (fact (- n 1)))))
>
> (define (main args)
>   (display (fact (string->number (cadr args))))
>   (newline))
>
>
> fac:
>
> #!/run/current-system/profile/bin/guile \
> -e (@@ (fac) main) -s
> !#
> (define-module (fac)
>   #:export (main))
>
> (use-modules (fact))
>
> (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)))
>
>
> But with Guile 3.0.8, this gives me:
>
> ./fac 5 20
> ice-9/read.scm:126:4: In procedure lp:
> #<unknown port>:1:4: unexpected end of input while searching for: )
>
> Which I don't understand.

OK, so what is apparently problematic with modules is the use of '-e (@@
(module-name) proc-name)' with Guil modules.  For the 'fac' file above,
modifying it like this:

--8<---------------cut here---------------start------------->8---
 #!/run/current-system/profile/bin/guile \
 -e (fac) -s
 !#
 (define-module (fac)
   #:export (main))

 (use-modules (fact))

 (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)))
--8<---------------cut here---------------end--------------->8---

works.  This relies on 'main' being defined and public.  I hope that
helps!

-- 
Thanks,
Maxim