From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: arne_bab@web.de Newsgroups: gmane.lisp.guile.devel Subject: [PATCH] doc: describe the -e (module) shorthand as on equal footing with (@ ...) Date: Wed, 18 May 2016 22:25:07 +0200 Message-ID: NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Trace: ger.gmane.org 1463603149 7383 80.91.229.3 (18 May 2016 20:25:49 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Wed, 18 May 2016 20:25:49 +0000 (UTC) Cc: arne_bab@web.de To: guile-devel@gnu.org Original-X-From: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Wed May 18 22:25:41 2016 Return-path: Envelope-to: guile-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1b3828-0005tO-9m for guile-devel@m.gmane.org; Wed, 18 May 2016 22:25:32 +0200 Original-Received: from localhost ([::1]:46978 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b3827-0005sh-Hn for guile-devel@m.gmane.org; Wed, 18 May 2016 16:25:31 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:46031) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b3820-0005qQ-Lf for guile-devel@gnu.org; Wed, 18 May 2016 16:25:26 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1b381v-0007o1-IL for guile-devel@gnu.org; Wed, 18 May 2016 16:25:23 -0400 Original-Received: from mout.web.de ([212.227.17.11]:56998) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b381u-0007n0-9E for guile-devel@gnu.org; Wed, 18 May 2016 16:25:19 -0400 Original-Received: from fluss.draketo.de ([85.212.71.115]) by smtp.web.de (mrweb102) with ESMTPSA (Nemesis) id 0MVu1U-1b5Ipe49MW-00X7e9; Wed, 18 May 2016 22:25:15 +0200 X-Mercurial-Node: e5938da9b89fcee1936487df32fb649135d8a94c X-Mercurial-Series-Index: 1 X-Mercurial-Series-Total: 1 X-Mercurial-Series-Id: User-Agent: Mercurial-patchbomb/3.7.3 X-Provags-ID: V03:K0:y+Sw6SFh+rspgYBTwwR4vcse8F6ZB/VBvkwWwyocn7CQ/EbNUqK P+UNINBPriYX02pJzTUQGT3Gwrt90oKrPbd7NnoHPtHRI/tQL55iYu44Xxz5jPZfyEqoH7R RvPaBx3+T9aFlixEFNYFkc8thNw9SMHUWEnIt9ZGHBoZF+32rNuP2viCY2z/9LoUqrF7Z8w 7BZQZsUxssnMvYHlMmtqw== X-UI-Out-Filterresults: notjunk:1;V01:K0:7CSam/ekQcQ=:ZV8iqR/Sy2zq3k+HgQdJmQ MXbwaw9cisS/iNV+3GEBEIEXhbiFzLB5GR3n9DAV7cC1wJPqWfp4e8T4uvNvNGUrmnQQpjYww 3OfYNQjz7igN45pOcKVBclc6wVVNI2lSwwihBePuXOP/SrDmMmDfYMgD9qGjNibH52+ltP/2Y +3ErVVGz8w6d7ftdCDOoWZnd14IThyIdaWITRwoi6j43G4yqDTSQDdsAsHExQpswKTj1K7qw0 Mh9bhzJ6MaGih796kpZqG+Alj32xi4BDcyVA7OHDZHSNtzMFe0p6CJOmix5AEUU7Qy0WpJNIU x3cxR7P0XkQettODPkzACgvl/Vv7tqc+Z15PCsbK/kKKrMoQOiXPlP5sROWwmCVMUPqRC4Sd1 POzYfSCwIM99si3FGEfkoUYcWRRXRktxexlUzk0UvHgysrprqB5rRXSO3cejqWjSYzZ0kF0R2 5BOOJWzMlyr0/UGjwehLcekujjw/uT6jBdovNqA30fUkqBiE3HyfSL7j1PJS8lkthVYEx59RS UNm81Et172LOvWc5r8bExZC3I4V79xF2sSH7bpQhqsS2E1kVtzuGZT/h11KMMW23D2OCp4gJs pa4g7ppP/HU3KpZfdj0GQSmxiIngueGa9jNLxCe3KeJhjAI3bBjBoK9DwLLKxdyCaNNP82XrS a70e9dfQ3iLOlPTooeHu5BreBJsCtvyYBxhtZZkFecgfZHWSpAhnVON1Rj3j5Lr+6fqnwVcwb miHndThKfRBS7saPopQXp1fR10Iwy/Dt3rjZ/zj20sif4zDhsTyOnwyOTGMJAK/+XNicG8Gq X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 212.227.17.11 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:18321 Archived-At: doc/ref/guile-invoke.texi | 15 ++++------ doc/ref/scheme-scripts.texi | 62 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 68 insertions(+), 9 deletions(-) # HG changeset patch # User Arne Babenhauserheide # Date 1463602731 -7200 # Wed May 18 22:18:51 2016 +0200 # Node ID e5938da9b89fcee1936487df32fb649135d8a94c # Parent 4f269918e38cd48905546c485173c4f9dbfa0717 doc: describe the -e (module) shorthand as on equal footing with (@ ...) diff --git a/doc/ref/guile-invoke.texi b/doc/ref/guile-invoke.texi --- a/doc/ref/guile-invoke.texi +++ b/doc/ref/guile-invoke.texi @@ -102,15 +102,12 @@ that is defined in the script. It can a @var{module-name} @var{symbol})}, and in that case, the symbol is looked up in the module named @var{module-name}. -For compatibility with some versions of Guile 1.4, you can also use the -form @code{(symbol ...)} (that is, a list of only symbols that doesn't -start with @code{@@}), which is equivalent to @code{(@@ (symbol ...) -main)}, or @code{(symbol ...) symbol} (that is, a list of only symbols -followed by a symbol), which is equivalent to @code{(@@ (symbol ...) -symbol)}. We recommend to use the equivalent forms directly since they -correspond to the @code{(@@ ...)} read syntax that can be used in -normal code. See @ref{Using Guile Modules} and @ref{Scripting -Examples}. +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}. @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 --- 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")}. +@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 @@ 1 100891344545564193334812497256 @end example +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 @c Local Variables: @c TeX-master: "guile.texi"