The Association of Lisp Users page
http://www.elwood.com/alu/table/good.htm states that lisp is good for:
Highly customizable "quick and dirty" utilities for doing
everyday
things. (i.e. as the most powerful scripting language
available).
However, I have had trouble finding information on how to use lisp in a
scripting context. I searched the internet and my ANSCI Common Lisp
book for examples of scripting code, eg. code that starts like:
#!/usr/local/bin/lisp
but I have only found lisp code written for running within the
interpreter. Can I write a script that invokes lisp as a command
interpreter, like a python or perl script? I tried doing that, but my
lisp implementation (CMU CL) just ignored the body of the script.
Again, sorry if this is a stupid question, but I really want to know.
--
Drake Emko
dr...@lynxus.com
> Again, sorry if this is a stupid question, but I really want to know.
The scsh (Scheme Shell) is specially designed to do a lot
of this stuff. You can also use things like CLisp
for scripting tasks (just see the manual).
It's extremely implementation-dependent how you do this. Here's how you
do it for several versions of Scheme. Note the various options required to
treat the script as a file to be loaded, and the various ways of getting
at the script's arguments:
Elk: #!/usr/local/bin/elk -l
(display "Hello, world! Args = ")
(display (command-line-args))
(newline)
% foo.elk bar baz
Hello, world! Args = (bar baz)
%
MzScheme:
% cat foo.mz
#!/usr/local/bin/mzscheme -r
(display "Hello, world! Args = ")
(display argv) ; note: "argv" is a vector
(newline)
% foo.mz bar baz
Hello, world! Args = #(bar baz)
%
Scsh: % cat foo.scsh
#!/usr/local/bin/scsh -s
!#
(display "Hello, world! Args = ")
(display (command-line)) ; includes the script name
(newline)
% foo.scsh bar baz
Hello, world! Args = (foo.scsh bar baz)
%
SIOD: % cat foo.siod
#!/usr/local/bin/siod -v0
(writes nil "Hello, world! Args = ")
(print *args*) ; includes the interpreter, its args, & the script name
% foo.siod bar baz
Hello, world! Args = ("/usr/local/bin/siod" "-v0" "foo" "bar" "baz")
%
It requires that the Lisp or Scheme reader know to ignore the "#!" line,
which most Schemes seem to. ("Scsh" does it by defining "#!....!#" to be
another form of "#|...|#, whereas the others just special-case the first
line of any LOADed file.)
As distributed, CLISP doesn't handle this [AFAIK], but you can either
hack on the source code of CLISP a little, or fake up a style sorta
like "scsh" with the following kludge:
% cat foo
#!/bin/sh
dir=/usr/local/lib/clisp
hack="(set-dispatch-macro-character
#\\# #\\! ; double the backslashes for 'sh'
#'system::comment-reader
*readtable*)
(defvar script-name \"$0\" )
(defvar script-args \"$*\" )
(load script-name)"
exec $dir/lisp.run -q -M $dir/lispinit.mem -x "$hack"
!#
;;;;;;;;;;;; the script's Lisp code starts here ;;;;;;;;;;;;
(format t "~%Hello world! Args = ~s~%" script-args)
(exit)
% foo bar baz
T
SCRIPT-NAME
SCRIPT-ARGS
;; Loading file foo ...
Hello world! Args = "bar baz"
%
Unfortunately, I haven't found any way (without hacking the source) to
suppress the first three values printed to stdout or the "Loading..."
message. Maybe other CLs do it better...?
-Rob
-----
Rob Warnock, 8L-855 rp...@sgi.com
Applied Networking http://reality.sgi.com/rpw3/
Silicon Graphics, Inc. Phone: 650-933-1673
2011 N. Shoreline Blvd. FAX: 650-964-0811
Mountain View, CA 94043 PP-ASEL-IA
> interpreter. Can I write a script that invokes lisp as a command
> interpreter, like a python or perl script? I tried doing that, but my
Check the STk Scheme system http://kaolin.unice.fr/STk/.
Paolo
--
Paolo Amoroso <amo...@mclink.it>
Paolo Amoroso wrote in message <3653d8e3...@news.mclink.it>...
Guilty as charged!! I was speaking of clisp-1996-04-17. (*blush*)
Time to upgrade, I guess... ;-}