[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Guile-commits] 14/14: doc: Describe -e (module) on equal footing with (
From: |
Andy Wingo |
Subject: |
[Guile-commits] 14/14: doc: Describe -e (module) on equal footing with (@ ...). |
Date: |
Wed, 1 Mar 2017 15:21:05 -0500 (EST) |
wingo pushed a commit to branch master
in repository guile.
commit 1026a768306bb11e7bdc3bdeff54e424b73e0c91
Author: Arne Babenhauserheide <address@hidden>
Date: Thu Sep 29 17:11:26 2016 +0200
doc: Describe -e (module) on equal footing with (@ ...).
* doc/ref/guile-invoke.texi, doc/ref/scheme-scripts.texi:
describe the -e (module) shorthand as on equal footing with (@ ...)
Co-authored-by: Ludovic Courtès <address@hidden>
---
doc/ref/guile-invoke.texi | 12 +++-----
doc/ref/scheme-scripts.texi | 68 +++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 72 insertions(+), 8 deletions(-)
diff --git a/doc/ref/guile-invoke.texi b/doc/ref/guile-invoke.texi
index d0f728e..a18984f 100644
--- a/doc/ref/guile-invoke.texi
+++ b/doc/ref/guile-invoke.texi
@@ -102,14 +102,10 @@ 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}.
-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
+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
address@hidden(@@ @var{module-name} main)}, where @var{module-name} is
address@hidden(symbol ...)} form. @xref{Using Guile Modules} and @ref{Scripting
Examples}.
@item -ds
diff --git a/doc/ref/scheme-scripts.texi b/doc/ref/scheme-scripts.texi
index 296bea7..d845148 100644
--- 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")}.
address@hidden guile -e '(ex4)' -s /u/jimb/ex4.scm foo
+Load the file @file{/u/jimb/ex4.scm}, and then call the function
address@hidden from the module '(ex4)', passing it the list
address@hidden("/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}
@@ -369,6 +374,7 @@ Suppose that we now want to write a script which computes
the
@code{(choose @var{n} @var{m})} is the number of distinct subsets
containing @var{n} objects each. It's easy to write @code{choose} given
@code{fact}, so we might write the script this way:
+
@example
#!/usr/local/bin/guile \
-l fact -e main -s
@@ -402,6 +408,68 @@ $ ./choose 50 100
100891344545564193334812497256
@end example
+To call a specific procedure from a given module, we can use the special
+form @code{(@@ (@var{module}) @var{procedure})}:
+
address@hidden
+#!/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)))
address@hidden example
+
+We can use @code{@@@@} to invoke non-exported procedures. For exported
+procedures, we can simplify this call with the shorthand
address@hidden(@var{module})}:
+
address@hidden
+#!/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)))
address@hidden example
+
+For maximum portability, we can instead use the shell to execute
address@hidden with specified command line arguments. Here we need to
+take care to quote the command arguments correctly:
+
address@hidden
+#!/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)))
address@hidden example
+
Finally, seasoned scripters are probably missing a mention of
subprocesses. In Bash, for example, most shell scripts run other
programs like @code{sed} or the like to do the actual work.
- [Guile-commits] 09/14: i18n: Do not represent zero as "-0"., (continued)
- [Guile-commits] 09/14: i18n: Do not represent zero as "-0"., Andy Wingo, 2017/03/01
- [Guile-commits] 05/14: tests: Avoid statprof test failure on systems without 'setitimer'., Andy Wingo, 2017/03/01
- [Guile-commits] 04/14: build: Honor $SOURCE_DATE_EPOCH for the recorded timestamp., Andy Wingo, 2017/03/01
- [Guile-commits] 06/14: doc: Fix typo in keywords documentation., Andy Wingo, 2017/03/01
- [Guile-commits] 10/14: tests: Use 'pass-if-equal' for (ice-9 i18n) tests., Andy Wingo, 2017/03/01
- [Guile-commits] 13/14: i18n: 'number->locale-string' guesses the minimum number of decimals., Andy Wingo, 2017/03/01
- [Guile-commits] 12/14: i18n: Fix corner cases for monetary and number string conversions., Andy Wingo, 2017/03/01
- [Guile-commits] 02/14: build: Compress with lzip too., Andy Wingo, 2017/03/01
- [Guile-commits] 03/14: scandir: Avoid 'stat' calls on each entry., Andy Wingo, 2017/03/01
- [Guile-commits] 08/14: Recognize sh3 as compilation targets, Andy Wingo, 2017/03/01
- [Guile-commits] 14/14: doc: Describe -e (module) on equal footing with (@ ...).,
Andy Wingo <=