From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED.blaine.gmane.org!not-for-mail From: Hans-Werner Roitzsch Newsgroups: gmane.lisp.guile.bugs Subject: bug#36682: Error in Guile scripting examples Date: Tue, 16 Jul 2019 00:39:43 +0200 Message-ID: <6956abda-8d34-8f3a-0816-9faacee7c7e7@posteo.net> Mime-Version: 1.0 Content-Type: multipart/alternative; boundary="------------EFCA7833A77C60E9DDD2AD1B" Injection-Info: blaine.gmane.org; posting-host="blaine.gmane.org:195.159.176.226"; logging-data="198010"; mail-complaints-to="usenet@blaine.gmane.org" User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.7.2 To: 36682@debbugs.gnu.org Original-X-From: bug-guile-bounces+guile-bugs=m.gmane.org@gnu.org Tue Jul 16 01:20:11 2019 Return-path: Envelope-to: guile-bugs@m.gmane.org Original-Received: from lists.gnu.org ([209.51.188.17]) by blaine.gmane.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.89) (envelope-from ) id 1hnAGP-000pKF-4G for guile-bugs@m.gmane.org; Tue, 16 Jul 2019 01:20:09 +0200 Original-Received: from localhost ([::1]:44246 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hnAGO-00086k-2m for guile-bugs@m.gmane.org; Mon, 15 Jul 2019 19:20:08 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:37857) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hnAGK-00086e-Rm for bug-guile@gnu.org; Mon, 15 Jul 2019 19:20:06 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hnAGJ-0004W0-BA for bug-guile@gnu.org; Mon, 15 Jul 2019 19:20:04 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:40563) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hnAGI-0004VT-GE for bug-guile@gnu.org; Mon, 15 Jul 2019 19:20:03 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1hnAGI-00084k-AG for bug-guile@gnu.org; Mon, 15 Jul 2019 19:20:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Hans-Werner Roitzsch Original-Sender: "Debbugs-submit" Resent-CC: bug-guile@gnu.org Resent-Date: Mon, 15 Jul 2019 23:20:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 36682 X-GNU-PR-Package: guile X-Debbugs-Original-To: bug-guile@gnu.org Original-Received: via spool by submit@debbugs.gnu.org id=B.156323279231022 (code B ref -1); Mon, 15 Jul 2019 23:20:02 +0000 Original-Received: (at submit) by debbugs.gnu.org; 15 Jul 2019 23:19:52 +0000 Original-Received: from localhost ([127.0.0.1]:49384 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1hnAG6-00084F-F1 for submit@debbugs.gnu.org; Mon, 15 Jul 2019 19:19:52 -0400 Original-Received: from lists.gnu.org ([209.51.188.17]:45614) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1hn9fX-00079q-Ez for submit@debbugs.gnu.org; Mon, 15 Jul 2019 18:42:04 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:59258) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hn9fV-0002or-RD for bug-guile@gnu.org; Mon, 15 Jul 2019 18:42:03 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hn9fT-0003Cs-NH for bug-guile@gnu.org; Mon, 15 Jul 2019 18:42:01 -0400 Original-Received: from mout02.posteo.de ([185.67.36.66]:40139) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hn9fT-0003An-4B for bug-guile@gnu.org; Mon, 15 Jul 2019 18:41:59 -0400 Original-Received: from submission (posteo.de [89.146.220.130]) by mout02.posteo.de (Postfix) with ESMTPS id 884012400E5 for ; Tue, 16 Jul 2019 00:41:56 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=posteo.net; s=2017; t=1563230516; bh=txTSSqhWWLBVWC8AvltNEhfuG3CazhVb+qXBsykO8U8=; h=To:From:Subject:Date:From; b=obRTBo1HJx7XL84VqoijY9641U6itXhVKOGJzSNEVrG30P4jUUGEQU75B5DyR3aKI iQdscqLjSNwNMo1fp6IFRRseGtUSHUlBVrNks0kfZQb71Q1HUfaBG98FOB83JYNU0z 1l3xltjBkFRVvMHJZZmpdB99XmM5Wdis8YNTbpfyrd5KA0fpQ8CwV9q2zYqb9TJKgF Khm0mA8uW0PPutuOEbRYmOhJ3INosrul1i1y6prA2TWG85uIpv8tQUuAHYPYxFg9/U W489en1K2Z8PmETouAadTBT/iz2izSUnW9k/0/peLTJ5anJbdKwIMMuPpxwZJaCKRy XeQb4YhiLDRkw== Original-Received: from customer (localhost [127.0.0.1]) by submission (posteo.de) with ESMTPSA id 45ndnH4YK3z9rxG for ; Tue, 16 Jul 2019 00:41:55 +0200 (CEST) Content-Language: en-US X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Mailman-Approved-At: Mon, 15 Jul 2019 19:19:48 -0400 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.51.188.43 X-BeenThere: bug-guile@gnu.org List-Id: "Bug reports for GUILE, GNU's Ubiquitous Extension Language" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-guile-bounces+guile-bugs=m.gmane.org@gnu.org Original-Sender: "bug-guile" Xref: news.gmane.org gmane.lisp.guile.bugs:9396 Archived-At: This is a multi-part message in MIME format. --------------EFCA7833A77C60E9DDD2AD1B Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Hello GNU Team! I wish to report a bug in either Guile's documentation or Guile's code with regard to running scripts. There are some examples of that given in Guile's documentation at: https://www.gnu.org/software/guile/manual/html_node/Scripting-Examples.ht= ml#Scripting-Examples In the following I will describe the problem. I have the file `modules.scm` with the following code: ----8<----start-of-code---->8---- #!/usr/bin/env sh exec guile -l fact.scm -e '(@ (my-module) main)' -s "$0" "$@" !# ;; Explanation: ;; -e (my-module) ;; If run as a script run the `my-module` module's `main`. ;; (Use `@@` to reference not exported procedures.) ;; -s ;; Run the script. (define-module (my-module) =C2=A0 #:export (main)) ;; Create a module named `fac`. ;; Export the `main` procedure as part of `fac`. (define (n-choose-k n k) =C2=A0 (/ (fact n) =C2=A0=C2=A0=C2=A0=C2=A0 (* (fact k) =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 (fact (- n k))))) (define (main args) =C2=A0 (let ((n (string->number (cadr args))) =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 (k (string->number (caddr args= )))) =C2=A0=C2=A0=C2=A0 (display (n-choose-k n k)) =C2=A0=C2=A0=C2=A0 (newline))) ----8<----end-of-code---->8---- And I have the following `fact.scm`: ----8<----start-of-code---->8---- #!/usr/local/bin/guile \ -e main -s !# ;; How to run this program? ;; Example: ;; guile -e main -s factorial-script.scm 50 ;; Explanation: ;; -e specifies the procedure to run ;; -s specifies to run this as a script ;; 50 is the number we take as input to the script (define (fact n) =C2=A0 (if (zero? n) 1 =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 (* n (fact (- n 1))))) (define (main args) =C2=A0 (display (fact (string->number (cadr args)))) =C2=A0 (newline)) ----8<----end-of-code---->8---- The script is made executable by doing: chmod +x modules.scm Then I call the script as follows: ./modules.scm 10 3 This results in the error: ----8<----start-of-code---->8---- Backtrace: =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 4 (apply-smo= b/1 #) In ice-9/boot-9.scm: =C2=A0=C2=A0=C2=A0 705:2=C2=A0 3 (call-with-prompt ("prompt") # #) In ice-9/eval.scm: =C2=A0=C2=A0=C2=A0 619:8=C2=A0 2 (_ #(#(#= ))) In /home/xiaolong/development/Guile/scripting/./modules.scm: =C2=A0=C2=A0=C2=A0 26:13=C2=A0 1 (main _) =C2=A0=C2=A0=C2=A0=C2=A0 18:0=C2=A0 0 (n-choose-k _ _) /home/xiaolong/development/Guile/scripting/./modules.scm:18:0: In procedu= re n-choose-k: In procedure module-lookup: Unbound variable: fact ----8<----end-of-code---->8---- According to my understanding of the tutorial in the Guile documentation that I linked to above this code should work. I also described the problem some time ago at: https://stackoverflow.com/questions/50272618/guile-scheme-scripting-tutor= ial-loading-scripts My Guile version is: guile (GNU Guile) 2.2.4 Best regards, Hans-Werner Roitzsch --------------EFCA7833A77C60E9DDD2AD1B Content-Type: text/html; charset=utf-8 Content-Transfer-Encoding: quoted-printable

Hello GNU Team!

I wish to report a bug in either Guile's documentation or Guile's code with regard to running scripts.

There are some examples of that given in Guile's documentation at:

= https://www.gnu.org/software/guile/manual/html_node/Scripting-Examples.ht= ml#Scripting-Examples

In the following I will describe the problem.


I have the file `modules.scm` with the following code:

----8<----start-of-code---->8----
#!/usr/bin/env sh
exec guile -l fact.scm -e '(@ (my-module) main)' -s "$0" "$@"
!#

;; Explanation:
;; -e (my-module)
;; If run as a script run the `my-module` module's `main`.
;; (Use `@@` to reference not exported procedures.)
;; -s
;; Run the script.

(define-module (my-module)
=C2=A0 #:export (main))

;; Create a module named `fac`.
;; Export the `main` procedure as part of `fac`.

(define (n-choose-k n k)
=C2=A0 (/ (fact n)
=C2=A0=C2=A0=C2=A0=C2=A0 (* (fact k)
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 (fact (- n k)))))

(define (main args)
=C2=A0 (let ((n (string->number (cadr args)))
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 (k (string->number (caddr a=
rgs))))
=C2=A0=C2=A0=C2=A0 (display (n-choose-k n k))
=C2=A0=C2=A0=C2=A0 (newline)))
----8<----end-of-code---->8----

And I have the following `fact.scm`:

----8<----start-of-code---->8----
#!/usr/local/bin/guile \
-e main -s
!#

;; How to run this program?
;; Example:
;; guile -e main -s factorial-script.scm 50
;; Explanation:
;; -e specifies the procedure to run
;; -s specifies to run this as a script
;; 50 is the number we take as input to the script

(define (fact n)
=C2=A0 (if (zero? n) 1
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 (* n (fact (- n 1)))))

(define (main args)
=C2=A0 (display (fact (string->number (cadr args))))
=C2=A0 (newline))
----8<----end-of-code---->8----

The script is made executable by doing:

chmod +x modules.scm

Then I call the script as follows:

./modules.scm 10 3

This results in the error:

----8<----start-of-code---->8----
Backtrace:
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 4 (apply-smo=
b/1 #<catch-closure 119cb80>)
In ice-9/boot-9.scm:
=C2=A0=C2=A0=C2=A0 705:2=C2=A0 3 (call-with-prompt ("prompt") #<proced=
ure 11aa8e0 at ice-9/eval.scm:330:13 ()> #<procedure default-prom=E2=
=80=A6>)
In ice-9/eval.scm:
=C2=A0=C2=A0=C2=A0 619:8=C2=A0 2 (_ #(#(#<directory (guile-user) 12331=
40>)))
In /home/xiaolong/development/Guile/scripting/./modules.scm:
=C2=A0=C2=A0=C2=A0 26:13=C2=A0 1 (main _)
=C2=A0=C2=A0=C2=A0=C2=A0 18:0=C2=A0 0 (n-choose-k _ _)

/home/xiaolong/development/Guile/scripting/./modules.scm:18:0: In procedu=
re n-choose-k:
In procedure module-lookup: Unbound variable: fact
----8<----end-of-code---->8----

According to my understanding of the tutorial in the Guile documentation that I linked to above this code should work.

I also described the problem some time ago at:

ht= tps://stackoverflow.com/questions/50272618/guile-scheme-scripting-tutoria= l-loading-scripts

My Guile version is:

guile (GNU Guile) 2.2.4

Best regards,

Hans-Werner Roitzsch

--------------EFCA7833A77C60E9DDD2AD1B--