Robert Uhl <eadmund42@NOSPAMgmail.com> wrote:
+---------------
| rpw3@rpw3.org (Rob Warnock) writes:
| > Robert Uhl <eadmund42@NOSPAMgmail.com> wrote:
| > +---------------
| > | I don't know that any Lisp will ever be suitable for shell scripting...
| > +---------------
| >
| > Hunh?!? I use CMUCL for "shell scripting" all the time!!!
|
| You don't find the start-up times a pain?
+---------------
Not at all. Remember, unlike SBCL, CMUCL still contains a full
interpreter which is quite fast at running simple code. Also, almost
all modern operating systems do a *very* good job of caching the
CMUCL executable & image files [which are mmap()'d COW at startup],
so that repeated execution is *fast*! -- in the range of 20 ms
(that's "milliseconds"!) on all the machines I usually run on.
Times for CLISP are similar.[1] They're even usable for low-volume
CGI scripting! ;-}
+---------------
| At least in SBCL, stuff like capturing stdin & stdout is more
| of a pain than in a simple shell, perl or python script.
+---------------
I don't understand. I use CMUCL scripts in pipes all the time, e.g.:
$ cat ./powers
#!/usr/local/bin/cmucl -script
(unless (= 1 (length *script-args*))
(format *error-output* "usage: ~a #powers~%" *script-name*)
(unix:unix-exit 1))
(let ((npowers (read-from-string (first *script-args*))))
(loop for line = (read-line nil nil nil)
while line do
(let ((n (read-from-string line)))
(format t "~s~{ ~s~}~%" n (loop for p from 2 to npowers
collect (expt n p))))))
$ for i in 2 3 5 10; do echo $i; done | ./powers 5
2 4 8 16 32
3 9 27 81 243
5 25 125 625 3125
10 100 1000 10000 100000
$ for i in 2 3 5 10; do echo $i; done | ./powers 5 | cut -d' ' -f3-
8 16 32
27 81 243
125 625 3125
1000 10000 100000
$
Almost exactly the same code [though with differences on the "#!" line
and in how you do an "exit 1"] should work on SBCL or CLISP or indeed
most CLs.
-Rob
[1] Actually, my measurements some time ago indicated that CMUCL's
startup is actually *slightly* faster than CLISP's [despite CMUCL's
greatly larger memory footprint]:
$ cat ./test3c.lisp
#!/usr/local/bin/clisp -q
(format t "hello world!~%")
$ time-hist ./test3c.lisp
Timing 100 runs of: ./test3c.lisp
4 0.019
26 0.020
70 0.021
$
versus:
$ cat ./test3a.lisp
#!/usr/local/bin/cmucl -script
(format t "hello world!~%")
$ time-hist ./test3a.lisp
Timing 100 runs of: ./test3a.lisp
66 0.016
34 0.017
$
[The "-script" switch for CMUCL is a local hack to "site-init.lisp"
that I've been intending to publish for several years. My bad.
Soon, soon...]
-----
Rob Warnock <rpw3@rpw3.org>
627 26th Avenue <URL:http://rpw3.org/>
San Mateo, CA 94403 (650)572-2607