bug-guile
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

bug#36682: Error in Guile scripting examples


From: Maxim Cournoyer
Subject: bug#36682: Error in Guile scripting examples
Date: Mon, 12 Dec 2022 20:08:28 -0500
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/28.2 (gnu/linux)

Hi,

Maxim Cournoyer <maxim.cournoyer@gmail.com> 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





reply via email to

[Prev in Thread] Current Thread [Next in Thread]