I am a relatively new lisp user and new to programming in general, so
forgive me if I am missing something obvious...
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
·····@lynxus.com
In article <·················@lynxus.com>, Drake Emko <·····@lynxus.com> wrote:
> 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).
--
http://www.lavielle.com/~joswig
Drake Emko <·····@lynxus.com> wrote:
+---------------
| However, I have had trouble finding information on how to use lisp in a
| scripting context... 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.
+---------------
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 ····@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
Clemens Heitzinger <········@ag.or.at> wrote:
+---------------
| ····@rigden.engr.sgi.com (Rob Warnock) writes:
| > As distributed, CLISP doesn't handle this [AFAIK]...
|
| You are probably using an old CLISP version. #!/usr/local/bin/clisp
| has been working for quite some time. It works for sure with CLISP
| 1998-09-09.
+---------------
Guilty as charged!! I was speaking of clisp-1996-04-17. (*blush*)
Time to upgrade, I guess... ;-}
-Rob
-----
Rob Warnock, 8L-855 ····@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
On Tue, 17 Nov 1998 22:43:12 +0000, Drake Emko <·····@lynxus.com> wrote:
> 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 <·······@mclink.it>
XLISP 3.0 (which is a dialect of Scheme) can also be used as a scripting
language. It can also be built as a DLL under Windows 95 and can load other
DLLs containing additional functions written in C.
Paolo Amoroso wrote in message <················@news.mclink.it>...
>On Tue, 17 Nov 1998 22:43:12 +0000, Drake Emko <·····@lynxus.com> wrote:
>
>> 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 <·······@mclink.it>