From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Arne Babenhauserheide Newsgroups: gmane.lisp.guile.devel Subject: Re: [PATCH] doc: describe the -e (module) shorthand as on equal footing with (@ ...) Date: Thu, 29 Sep 2016 17:14:55 +0200 Message-ID: <87oa36g2kw.fsf@web.de> References: <8760sv3atk.fsf@web.de> <87r3bj835b.fsf@pobox.com> <8760sisc4j.fsf@web.de> <87shvl698r.fsf@pobox.com> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: multipart/signed; boundary="=-=-="; micalg=pgp-sha256; protocol="application/pgp-signature" X-Trace: blaine.gmane.org 1475162156 4623 195.159.176.226 (29 Sep 2016 15:15:56 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Thu, 29 Sep 2016 15:15:56 +0000 (UTC) User-Agent: mu4e 0.9.16; emacs 24.5.1 Cc: guile-devel@gnu.org To: Andy Wingo Original-X-From: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Thu Sep 29 17:15:52 2016 Return-path: Envelope-to: guile-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bpd3i-0007jq-57 for guile-devel@m.gmane.org; Thu, 29 Sep 2016 17:15:38 +0200 Original-Received: from localhost ([::1]:38710 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bpd3g-00015d-LY for guile-devel@m.gmane.org; Thu, 29 Sep 2016 11:15:36 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:40479) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bpd3L-00012w-Bl for guile-devel@gnu.org; Thu, 29 Sep 2016 11:15:16 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bpd3F-0003X0-CV for guile-devel@gnu.org; Thu, 29 Sep 2016 11:15:14 -0400 Original-Received: from mout.web.de ([217.72.192.78]:60248) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bpd3F-0003Tl-36 for guile-devel@gnu.org; Thu, 29 Sep 2016 11:15:09 -0400 Original-Received: from fluss ([85.212.22.241]) by smtp.web.de (mrweb103) with ESMTPSA (Nemesis) id 0MT8fq-1bOhxn2quM-00S7CZ; Thu, 29 Sep 2016 17:14:57 +0200 In-reply-to: <87shvl698r.fsf@pobox.com> X-Provags-ID: V03:K0:Y0/d5/ik5rz2LGXo9nYxy60XZ+CGhkv/1ns5zaDAhWjWoaB+FXe W3LKjSGyJXwXCO3RFDs8ElQJA68Q7ZcJmZDwk+6914PZ8GMrmcQI7PdPqIRbXDf6Lw98kNQ AuYOWsNZfYd9DybcxOiiYwCi3G6V4uKW0topD27dTSvmi/IciaT/0HALjuC4cLJP7x3x46K fjEO4PVmHn7m8BK8LbjNA== X-UI-Out-Filterresults: notjunk:1;V01:K0:vKMjUIgMKtg=:KZp5YMt3kU8H+UvizlVxnq QdNVMXXl+o5OszGRFqv8S2SktBSDdduWIOdx1AaoytxMfZ4cMwP7XKcZuKmnQy9i7Czq9eCQL vb6fuJ/wq2tQQZiLyIOX+qLA86B+7DZOUzxogMWZ9V+mxMZYKvKIGZlVywvBP0ZF8xrh/ZjcS HllMps1vo6++h2DAl4QIgigqcy0ld7SB5RScDH4q/jdM060gvczdUUfbu/+SJWhfxZ8TY+jf+ K50wuSuddOwQKJ4w/2QiMyY1L9ZAkuVYvbNJvKcvbe7jDnCdsG4ggwowE3D8hKktcUnT+ibfO p+TlX5097a0x1/MN16ruW9EN7sI68/oEMeeh/mUleH4ZmOZh/cHHtvEw+iYWABIb2JZaVIx1x OaK9BH49r+bOTKwoCq3zj36klu18FQZHZ7QaeJQnejd9eMeAVkZ+TO4oCHK6sFw3t43+xxB5t J99qbtyF1nI6UyCl3aDM96PfqA5NrqT0GRq5K6/LGa/535lTtLpaaCh0FkyPM+4NdZMkPPKfL dyg7S38qiegPnCVcXsy5AWiICZoqQyO3WYdgrWZnDiUvGsfQNY9fLyE9xLDvJLbi/BAd4+CD0 L/8klvCDmk2jDZMHKgLAtZDYnBrcSP+68FeOJrCRe6mlq8ubMvQ8lqPLEZL9WLNjVff12yLqI 5oqI6ZY0h3vFFPW68RI1HvBvf3iYvAoOAQgXqZU0wy1m2JTdDrQcTZMSGuX4P/c6lpAG/znLC 7bE3CZ+GsWS9geV7ocjop9AL/o7e6Jnir4J7+LLrrdjLEshrnLBKQ27MV+o= X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 217.72.192.78 X-BeenThere: guile-devel@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: "Developers list for Guile, the GNU extensibility library" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Original-Sender: "guile-devel" Xref: news.gmane.org gmane.lisp.guile.devel:18691 Archived-At: --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Andy Wingo writes: > On Wed 06 Jul 2016 23:14, Arne Babenhauserheide writes: > >> Does the following suffice as ChangeLog entry? >> >> >> 2016-05-18 Arne Babenhauserheide >> >> * doc/ref/guile-invoke.texi, doc/ref/scheme-scripts.texi: >> describe the -e (module) shorthand as on equal footing with (@ ...) >> >> >> It=E2=80=99s mostly generated with hg log --template changelog -r tip. > > Hi, > > In Guile we work with git :) If you would like a patch applied, please > attach it in git-format-patch format, with the commit log in the > standard format. Check the git logs for examples. It's easy: just do > "git commit -a", paste in your change log with the summary line and no > indentation, then "git format-patch HEAD^". Sorry for answering late. I missed your answer again (just noticed the unresolved todo in my agenda and checked explicitly). I now essentially typed in your commands, plus some manual patch -p1 to use my own patch :) Is this OK? From=204751b9c4c85152281f0d57eda6a1c4ce50166ad4 Mon Sep 17 00:00:00 2001 From: Arne Babenhauserheide Date: Thu, 29 Sep 2016 17:11:26 +0200 Subject: [PATCH] describe the -e (module) shorthand as on equal footing with (@ ...) * doc/ref/guile-invoke.texi, doc/ref/scheme-scripts.texi: describe the -e (module) shorthand as on equal footing with (@ ...) =2D-- doc/ref/guile-invoke.texi | 15 +++++------ doc/ref/scheme-scripts.texi | 62 +++++++++++++++++++++++++++++++++++++++++= ++++ 2 files changed, 68 insertions(+), 9 deletions(-) diff --git a/doc/ref/guile-invoke.texi b/doc/ref/guile-invoke.texi index bc33ce0..e25960a 100644 =2D-- a/doc/ref/guile-invoke.texi +++ b/doc/ref/guile-invoke.texi @@ -102,15 +102,12 @@ that is defined in the script. It can also be of the= form @code{(@@ @var{module-name} @var{symbol})}, and in that case, the symbol is looked up in the module named @var{module-name}. =20 =2DFor compatibility with some versions of Guile 1.4, you can also use the =2Dform @code{(symbol ...)} (that is, a list of only symbols that doesn't =2Dstart with @code{@@}), which is equivalent to @code{(@@ (symbol ...) =2Dmain)}, or @code{(symbol ...) symbol} (that is, a list of only symbols =2Dfollowed by a symbol), which is equivalent to @code{(@@ (symbol ...) =2Dsymbol)}. We recommend to use the equivalent forms directly since they =2Dcorrespond to the @code{(@@ ...)} read syntax that can be used in =2Dnormal code. See @ref{Using Guile Modules} and @ref{Scripting =2DExamples}. +As a shorthand you can use the form @code{(symbol ...)}, that is, a +list of only symbols that doesn't start with @code{@@}. It is +equivalent to @code{(@@ @var{module-name} main)} with @code{(symbol ...)} +the @var{module-name}. To use a different function than @var{main}, +you can use the form @code{(symbol ...) function}. See @ref{Using +Guile Modules} and @ref{Scripting Examples}. =20 @item -ds Treat a final @option{-s} option as if it occurred at this point in the diff --git a/doc/ref/scheme-scripts.texi b/doc/ref/scheme-scripts.texi index 7552dba..4999a47 100644 =2D-- a/doc/ref/scheme-scripts.texi +++ b/doc/ref/scheme-scripts.texi @@ -293,6 +293,11 @@ and exit. Load the file @file{/u/jimb/ex4}, and then call the function @code{main}, passing it the list @code{("/u/jimb/ex4" "foo")}. =20 +@item guile -e '(ex4)' -s /u/jimb/ex4.scm foo +Load the file @file{/u/jimb/ex4.scm}, and then call the function +@code{main} from the module '(ex4)', passing it the list +@code{("/u/jimb/ex4" "foo")}. + @item guile -l first -ds -l last -s script Load the files @file{first}, @file{script}, and @file{last}, in that order. The @code{-ds} switch says when to process the @code{-s} @@ -402,6 +407,63 @@ $ ./choose 50 100 100891344545564193334812497256 @end example =20 +To execute the function main from a module, we can use the special form +@code{(@@ (module) function)}: +@example +#!/usr/local/bin/guile \ +-l fact -e (@@ (fac) main) -s +!# +(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))) +@end example + +We can use @code{@@@@} to run non-exported functions. For exported +functions, we can simplify this call with the shorthand @code{(module)}: +@example +#!/usr/local/bin/guile \ +-l fact -e (fac) -s +!# +(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))) +@end example + +For maximum portability among *nixes, we can use the shell to +@code{exec} guile with specified command line arguments. Here we need to +take care to quote the command arguments correctly: +@example +#!/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))) +@end example =20 @c Local Variables: @c TeX-master: "guile.texi" =2D-=20 2.7.3 Best wishes, Arne =2D-=20 Unpolitisch sein hei=C3=9Ft politisch sein ohne es zu merken --=-=-= Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v2 iQIcBAEBCAAGBQJX7S/wAAoJEBPvjUUkA8PrsMcP/R0IXEXb5gDibhQYQMhxuggc YWp9CQOL6CgDuSqge1dL0EAry6T4ZtMtJvc7FgrwYg6JUnYjcDgRv3//ne0d0wpT 6SVs3hltBmrVH2Vn7GfPWZ/2CDJeCsbdkg5DtK4cILW23fFtHhcpVCQ+oS9VAWXD f2yaRF0MiuUbzkkZuONPJ4oO7slHRSHxqWe2U05q383le9lbBiUqZ0G9v/Wotsym K0r/4TIty35QT4+5uYWNVZFcimZk5MktJmvqsA38NZl8eJb/1672/XV7HWa/DcAd nSA1uHyP5OQQWKne+SwjFwPwj73qHzSeUzSI7SKoNv0OqgpbmTRBh3hpqL8YYN/z 9sAPE2NISpG5B/LOKRMB6qRerqJ1QOdWxI+BlnwPQidf1iE45QF4fwV6qBu47jVS 7iBl8dzJYdfT/SXH019yAAmtR+BYkoQaAvI8N7rFeqn74lO9ZnrGnb4lXSXRf5cP 1NYnhOUmh+2PN25an2vJP/cikdIcGxnicv3OlGfLwP81Jaws3sl++LfWEs6I5DM8 e/0kqm3P9WqiWnsEsjiDd+n/cpkJV582ODeVpChE4UMy6GoHE2S5M4kFgc0VYgd+ e+NC7gQovQIUFgIhdSTvNMuRWKZK9JHyoVShFuGCrmJj6t0hDI6/UBjhKfTo2RVA DTn9T7bZxJFgYmv0QNqS =Oa54 -----END PGP SIGNATURE----- --=-=-=--