From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED.blaine.gmane.org!not-for-mail From: Arne Babenhauserheide Newsgroups: gmane.lisp.guile.bugs Subject: bug#36682: Error in Guile scripting examples Date: Tue, 16 Jul 2019 01:44:39 +0200 Message-ID: <875zo2g8wo.fsf@web.de> References: <6956abda-8d34-8f3a-0816-9faacee7c7e7@posteo.net> Mime-Version: 1.0 Content-Type: multipart/signed; boundary="=-=-="; micalg=pgp-sha256; protocol="application/pgp-signature" Injection-Info: blaine.gmane.org; posting-host="blaine.gmane.org:195.159.176.226"; logging-data="31610"; mail-complaints-to="usenet@blaine.gmane.org" User-Agent: mu4e 1.2.0; emacs 26.2 To: 36682@debbugs.gnu.org Original-X-From: bug-guile-bounces+guile-bugs=m.gmane.org@gnu.org Tue Jul 16 01:46: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 1hnAfY-00082X-Uj for guile-bugs@m.gmane.org; Tue, 16 Jul 2019 01:46:09 +0200 Original-Received: from localhost ([::1]:44324 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hnAfX-0004hI-TM for guile-bugs@m.gmane.org; Mon, 15 Jul 2019 19:46:07 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:42050) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hnAfU-0004be-Jl for bug-guile@gnu.org; Mon, 15 Jul 2019 19:46:05 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hnAfS-0000z9-E6 for bug-guile@gnu.org; Mon, 15 Jul 2019 19:46:03 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:40581) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hnAfS-0000yw-9u for bug-guile@gnu.org; Mon, 15 Jul 2019 19:46:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1hnAfS-0000JC-4t for bug-guile@gnu.org; Mon, 15 Jul 2019 19:46:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Arne Babenhauserheide Original-Sender: "Debbugs-submit" Resent-CC: bug-guile@gnu.org Resent-Date: Mon, 15 Jul 2019 23:46:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 36682 X-GNU-PR-Package: guile X-Debbugs-Original-To: bug-guile@gnu.org X-Debbugs-Original-Cc: 36682@debbugs.gnu.org Original-Received: via spool by submit@debbugs.gnu.org id=B.15632343081101 (code B ref -1); Mon, 15 Jul 2019 23:46:02 +0000 Original-Received: (at submit) by debbugs.gnu.org; 15 Jul 2019 23:45:08 +0000 Original-Received: from localhost ([127.0.0.1]:49402 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1hnAea-0000Hh-2U for submit@debbugs.gnu.org; Mon, 15 Jul 2019 19:45:08 -0400 Original-Received: from lists.gnu.org ([209.51.188.17]:42824) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1hnAeY-0000Ha-Kv for submit@debbugs.gnu.org; Mon, 15 Jul 2019 19:45:06 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:41884) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hnAeX-0004Oc-Fy for bug-guile@gnu.org; Mon, 15 Jul 2019 19:45:06 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hnAeW-0000FA-8w for bug-guile@gnu.org; Mon, 15 Jul 2019 19:45:05 -0400 Original-Received: from mout.web.de ([212.227.15.3]:56563) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hnAeV-0000CS-Vz for bug-guile@gnu.org; Mon, 15 Jul 2019 19:45:04 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=web.de; s=dbaedf251592; t=1563234286; bh=9dBohTMoCRmdX90i+AFyztdqjwsJ5O9VANvynXylg6g=; h=X-UI-Sender-Class:References:From:To:Cc:Subject:In-reply-to:Date; b=gBTuhqJWX2s2xycO22jXeN9ssHMXoM1jVOS9txfdzi+igMBpA27woiIEesfMPyICW d3FRhxrS6/+KBMctr0qqSK0yHNZMP2QQq4qCf92CINpVQK9jCw1ci4yXttmPZDGdAX BuzwH2dR60TauUvkWjjadWB3F7/yosbcwZZFfDz8= X-UI-Sender-Class: c548c8c5-30a9-4db5-a2e7-cb6cb037b8f9 Original-Received: from fluss ([84.149.83.171]) by smtp.web.de (mrweb001 [213.165.67.108]) with ESMTPSA (Nemesis) id 0Lj2TO-1iJjyV3rig-00dCOJ; Tue, 16 Jul 2019 01:44:46 +0200 In-reply-to: <6956abda-8d34-8f3a-0816-9faacee7c7e7@posteo.net> X-Provags-ID: V03:K1:L+sHWg1zxQpDE+Rgcn43Me6z8FM5mVcmCWeaHUg6NsyTx+IY2jR JCCmRqig7gERITbm3f2TnLG2LgD3ycDvPlr4u7w6TbqZ3B8BdHnbabf2XjUmYt8x7PEezZN 53ItuU1VQv91BMXXtFi2BtdeR6oO/Zh7JCSTB0YrNPT3A+a50FRruJC8HToXW22EZi6TU6F hVvgAejkHc4w9LOZ/pe+w== X-UI-Out-Filterresults: notjunk:1;V03:K0:EvkDqP4ZVbo=:TXk7FdgdlofiG6Njswpq/H Jloy5jwtY/smTNr8+fH108FityQ1tV10M8FKBFWBc/j2K9b0BXKXi94ENXj5AvudaI2qjyyGd pZrYoLSGovYqb7+WEPbYEx5+BF54X3CfFBvqP3TIr/bI4lNDFcFjItZ+8lfW4LsCbpq5WPNnZ v0qin2zfGo1P62gXgbzQKDnk7X7dp7udWKoTuEZx0orFUxU8J5I+UGbViasdaBQJJF3GelSC8 QzIu4rKoPSU4tnqCMaQo2V2JMELfAhcLQCYtVosBAlv9PKYHwTLzLIQLA6uAaYO61UmpqK+bg OblKShH187ibu8MWsrHvSn6ZJsQx7XbZ3K9aUo35y2D7FqgQVUEkSOPSyZsHUQpLze3ZVBAft hcR8AaPFNS3aZHyeXNrKqYJqUVuau7em09J2ioWyjMLD5H36jK1Y5m6VY5BPOYXFB2LfRjViM I6m8lJ0mqDKblm/C/aepMJCRgDX5ZgQIZSZFRl5rt9YOZmIC6rKa3nc31ZzqudSR/qtUVd2xx KTCfzJzoVlrupxLunxh+sFP0Dmz+/5Z3lNpruDesFrzNQEx/yeb5NZA3qrc0xvsDYOueB39e+ 0KdOsHmYZgtSvNfb5rH7UwzoBY7Pw3Z4Guot26qb6QhUtB4I3RwyTyqwr9bFhj4exZ5D7cHaO 9Xko= X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] 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:9397 Archived-At: --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Hello Hans-Werner Roitzsch, It looks like you=E2=80=99re mixing up two concepts: the fac creates a modu= le and loads the fact which is not a module, so basically main and choose live in another namespace than fact (define-module starts a new namespace). And it seems that this is indeed a bug in the documentation, because https://www.gnu.org/software/guile/manual/html_node/Scripting-Examples.html= #Scripting-Examples jumps to defining fac as a module but does not at the same time define and import fact as a module, too. Hans-Werner Roitzsch writes: > 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) > #:export (main)) At this point you need (use-modules (fact)) > ;; Create a module named `fac`. > ;; Export the `main` procedure as part of `fac`. > > (define (n-choose-k n k) > (/ (fact n) > (* (fact k) > (fact (- n k))))) > > (define (main args) > (let ((n (string->number (cadr args))) > (k (string->number (caddr args)))) > (display (n-choose-k n k)) > (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 To be usable as module, this needs to be defined as module: (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)) > ----8<----end-of-code---->8---- =E2=80=A6 > chmod +x modules.scm > ./modules.scm 10 3 Does it work with the added module definition and import? If yes, then this looks like a bug in the documentation. > Best regards, > > Hans-Werner Roitzsch Best wishes, and thank you for reporting! Arne =2D- Unpolitisch sein hei=C3=9Ft politisch sein ohne es zu merken --=-=-= Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAEBCAAdFiEE801qEjXQSQPNItXAE++NRSQDw+sFAl0tD+oACgkQE++NRSQD w+uv/A//TFj/xrwPZNtlVlTG4tbyISUg/fGU0Z8EnFS/BzHgsG26Z/KBW58MJ/fW lfAWdYOnzauXa+DJU4LHs/HEfBNgYEsXFXur56OZA39bJ4F2WiRgZibcfHD45Rwt RC8txwbldyUHz1AW009LHyGJqxlt+wAhf24VFMDdbaLFxZrG/O81YLx9nzHXumea hFoQt8JIMPvjjoWgjm18LPCYC2bDChkIYdLDrBDSWhKJx2SuWSdJftpAsmxI0+Dh 2ChT5F6UT48Kzh/ymU1xCf1wTpb1H91x5fZJS1xYSfLIes9pkQM1qCDzY00xYhW4 CsUuSXqK+4WadEK9L1ggtMOIdxpKfElEhaz+gsG8NqOMPg8NOL93IDap7i1y5aTY tuKi7AoJ1Rp8eJCCdXuX9Nc5/674OKlc9YptFaWW9VfvuePVw1wrYoKsa2qcfKZE KcTr77BIt1DfIrBJsPXtfyG5diC/pb09JK7SgD2d77lp28DVdFVRHWyC/+GwVAyY 6/GQvX7PCFVeDierSYbkKaK+s1fohtl3Wek28Z9pgLMFbj3FilHwE/Q/X1UIsvQF pgix2uyUeBxofevoVTwxZTrrZ6UAbT/jN5c2/6mzaRiMAogc673qwBz/yHLNpAQr yULU8Xz/Cy4t2wAQv8fVsnzkjpSijGtIo39eppVnhxxug7HaJ3OIswQBAQgAHRYh BN0ovebZh1yrzkqLHdzPDbMLwQVIBQJdLQ/qAAoJENzPDbMLwQVI8OcD/iKSTl+x etXZzW46EajYzN6uweCViwt3jApIAFPj7rL604XAR9BmnxeEC0o8IfceIHyJ4YsH lAdTJOEvG40whMnUYhIYsCncEWkjvzXoqHPljY8j4ZT2/OBH2r5JLlfB3oMSBvWg qnBRLa093dldcgjMwS8IKjd1C1YGikD20GuT =d4KY -----END PGP SIGNATURE----- --=-=-=--