From: Frank Buss
Subject: Lisp as a script language
Date: 
Message-ID: <cb74cd$4dp$1@newsreader2.netcologne.de>
At http://merd.sourceforge.net/pixel/language-study/scripting-language/ Ben 
Sizer has compared various languages for using as a scripting language. 
Lisp is missing, so I'll try it. Perhaps the experts in this group can fill 
up the missing topics and then we can mailing it to the site maintainer of 
Scriptometer.

The following examples has been tested with CMUCL 18e under Linux and this 
command line: 

lisp -quiet -load test.lisp

The file "test.lisp" contains the programs. I tried to use CL, only.

smallest: <empty>

hello world:
(write-line "Hello World")
(quit)

argv (access command line parameters): no standard CL solution, I think

env (access environment variable): no standard CL solution, I think

test if file exists (readable), return exit code error (non zero) if a file 
does not exist (is not readable): I have not found a standard CL way to 
return an exit code

formatting:
(let ((a 1) (b 2))
  (write-line 
    (format t "~A + ~A = ~A" a b (+ a b))))
(quit)

sed in place: needs access to command line arguments

compile what must be: I have not found a standard CL function for executing 
an external program

grep: needs access to command line arguments

Looks like standard CL is a bit limited, so perhaps it would be a better 
idea to compare a special implementation, but I don't know which is the 
most used implementation or the best implementation for this test.

-- 
Frank Bu�, ··@frank-buss.de
http://www.frank-buss.de, http://www.it4-systems.de

From: Christopher C. Stacy
Subject: Re: Lisp as a script language
Date: 
Message-ID: <u7ju03k0l.fsf@news.dtpq.com>
>>>>> On Mon, 21 Jun 2004 17:03:09 +0000 (UTC), Frank Buss ("Frank") writes:

 Frank> argv (access command line parameters): no standard CL solution, I think
 Frank> env (access environment variable): no standard CL solution, I think
 Frank> I have not found a standard CL way to return an exit code
 Frank> I have not found a standard CL function for executing an external program.

 Frank> Looks like standard CL is a bit limited, so perhaps it would be a better 
 Frank> idea to compare a special implementation, but I don't know which is the 
 Frank> most used implementation or the best implementation for this test.

The ANSI standard does not address any of those Unix interfaces, 
as it was designed to be applicable to many other kinds of operating
systems.  It is assumed that the actual implementations will include
whatever additional features are needed to get that kind of work done 
on the specific platform.  There are no ANSI standards for binding
Lisp to operating systems, although there are some de facto standard
libraries for some things.

What Lisp implementation would be the "best" is very subjective.  
I would suggest reading the documentation for the implementation 
that you already tried to see if it does all the things you want.
There are quite a few implementations of ANSI Common Lisp that
run on Unix type systems.

You seem to be using CMUCL, which is a very popular high-quality
free implementation.  (Doesn't have an IDE or all the goodies
that you get with a commercial implementation, though.)
Another popular one is called CLISP.

If you're going to be using Lisp programs as components of shell-
scripting applications, then you might want to consider the relative
startup time/resources overhead of the different implementations.
(I don't have any figures on that, but you can trivially do the
experiments yourself.)

You should also consider that you might use Lisp as the main component
of the scripted application, rather than having the shell play that role.
You'll need to read up on how your implementation handles external programs
and pipes, for those pieces that live outside of Lisp.
From: Björn Lindberg
Subject: Re: Lisp as a script language
Date: 
Message-ID: <hcsfz8ostfu.fsf@knatte.nada.kth.se>
Frank Buss <··@frank-buss.de> writes:

> At http://merd.sourceforge.net/pixel/language-study/scripting-language/ Ben 
> Sizer has compared various languages for using as a scripting language. 
> Lisp is missing, so I'll try it. Perhaps the experts in this group can fill 
> up the missing topics and then we can mailing it to the site maintainer of 
> Scriptometer.
> 
> The following examples has been tested with CMUCL 18e under Linux and this 
> command line: 
> 
> lisp -quiet -load test.lisp
> 
> The file "test.lisp" contains the programs. I tried to use CL, only.
> 
> smallest: <empty>
> 
> hello world:
> (write-line "Hello World")
> (quit)
> 
> argv (access command line parameters): no standard CL solution, I think
> 
> env (access environment variable): no standard CL solution, I think
> 
> test if file exists (readable), return exit code error (non zero) if a file 
> does not exist (is not readable): I have not found a standard CL way to 
> return an exit code
> 
> formatting:
> (let ((a 1) (b 2))
>   (write-line 
>     (format t "~A + ~A = ~A" a b (+ a b))))
> (quit)
> 
> sed in place: needs access to command line arguments
> 
> compile what must be: I have not found a standard CL function for executing 
> an external program
> 
> grep: needs access to command line arguments
> 
> Looks like standard CL is a bit limited, so perhaps it would be a better 
> idea to compare a special implementation, but I don't know which is the 
> most used implementation or the best implementation for this test.

I suggest that you go with a specific implementation. One possibility
is Clisp, which can be run as a shebang script, just as several of the
other languages on that page. Here are the first five "programs" in
Clisp:

#!/usr/bin/clisp -q

; Smallest running program:
; <empty>

; Hello world:
(princ "Hello world")

; Command line arguments:
(princ (first *args*))

; Environment variables:
(princ (getenv "HOME"))

; Return non-zero exit code when file does not exist:
(unless (probe-file "/etc/mtab") (exit 1))

As you have discovered, there is no standard (as in ANSI) way to find
out the command line arguments or environment variables, so the above
is Clisp-specific, although other implementations have similar ways to
do the same thing. Additionally, there are compatibility packages
which provides uniform access to such OS specific things by wrapping
the underlying implementation calls.

Also, you can see that the other languages on that page is allowed to
use functionality in modules and even run external programs, , so it
cannot be considered cheating to use additional CL packages for
functionality that might be missing in "pure" CL. Eg. Osicat and
cl-ppcre are good candidates for such modules.

I cannot say that I think that that scripting language guide is
terribly useful though, but presumably just writing the programs in a
CL could be a useful learning exercise.


Bj�rn
From: Rob Warnock
Subject: Re: Lisp as a script language
Date: 
Message-ID: <54KdndLa5cO9DErd4p2dnA@speakeasy.net>
Bj�rn Lindberg <·······@nada.kth.se> wrote:
+---------------
| Frank Buss <··@frank-buss.de> writes:
| > Looks like standard CL is a bit limited, so perhaps it would be a better 
| > idea to compare a special implementation, but I don't know which is the 
| > most used implementation or the best implementation for this test.
| 
| I suggest that you go with a specific implementation.
+---------------

But remember to isolate the platform-specific stuff so you can easily
add support for more platforms later.

+---------------
| Here are the first five "programs" in Clisp:
+---------------

And just for fun, in CMUCL as well:

+---------------
| #!/usr/bin/clisp -q
| ; Smallest running program:
| ; <empty>
+---------------

As it comes "out of the box", CMUCL doesn't directly support "shebang"
style. However, there are at least three reasonable solutions:

1. Trampoline off /bin/sh (the following "exec" must be all in one line)
   on those operating systems which default to /bin/sh:

      ":" ; exec cmucl -noinit -eval "(setq *load-verbose* nil)" -load "`which $0`" ${1+"-args"} ······@"}
      ; ...your Lisp code here...

2. Use a specialized trampoline program, such as the one given here:

      <URL:http://www.chez.com/emarsden/downloads/cmucl-trampoline.c>

   which lets your script start something like this:

      #!/usr/bin/cmucl-trampoline \
      -quiet -batch -noinit
      #!
      ; ...your Lisp code here...

3. Make a little hack to "/usr/local/lib/cmucl/lib/site-init.lisp"
   [which I keep saying I'm going to post, but haven't gotten around to
   yet -- maybe this will be enough motivation] that lets you do this:

      #!/usr/local/bin/cmucl -script
      ; ...your Lisp code here...

So given one of the above, then:

+---------------
| ; Hello world:
| (princ "Hello world")
+---------------

Same in CMUCL.

+---------------
| ; Command line arguments:
| (princ (first *args*))
+---------------

  (princ (second ext:*command-line-strings*))

+---------------
| ; Environment variables:
| (princ (getenv "HOME"))
+---------------

Add the following routine to your startup code, then same in CMUCL:

   ;;; GETENV -- Mostly-portable code for accessing Unix
   ;;; (or Windows?) environment variables. Morphed very slightly
   ;;; from <URL:http://cl-cookbook.sourceforge.net/os.html>
   ;;; Copyright (c) 2002 The Common Lisp Cookbook Project 
   ;;; See: <URL:http://cl-cookbook.sourceforge.net/license.html>
   (defun getenv (name &optional default)
     (or
      #+CMU (cdr (assoc name ext:*environment-list* :test #'string=))
      #+Allegro (sys:getenv name)
      #+CLISP (ext:getenv name)
      #+ECL (si:getenv name)
      #+SBCL (sb-unix::posix-getenv name)
      #+LISPWORKS (lispworks:environment-variable name)
      default))

+---------------
| ; Return non-zero exit code when file does not exist:
| (unless (probe-file "/etc/mtab") (exit 1))
+---------------

Same in CMUCL, except use (QUIT 1) instead of (EXIT 1).

Also, see the function EXT:RUN-PROGRAM to see how to run programs
from within CMUCL. E.g., in the simple case where we just want to
run a sub-process, get its output on stdout, and wait for it to exit,
given the following definition:

   #+cmu
   (defun system (command-string)
     (let ((proc (run-program "/bin/sh" (list "-c" command-string)
			      :wait t :input t :output t :error t)))
       (prog1 (process-exit-code proc) (process-close proc))))

you can then do this:

   > (system "ls -l foo*.[0-9]")
   -rw-r--r--  1 rpw3  rpw3   5361 Mar 30 13:40 foo.1
   -rw-r--r--  1 rpw3  rpw3   4504 Apr 14 22:57 foo.2
   -rw-r--r--  1 rpw3  rpw3   6211 Apr 14 23:01 foo.3
   -rw-r--r--  1 rpw3  rpw3  55971 Apr 14 23:04 foo.4

   0
   > (system "ls -l foo3*")
   ls: foo3*: No such file or directory

   1
   > 


-Rob

-----
Rob Warnock			<····@rpw3.org>
627 26th Avenue			<URL:http://rpw3.org/>
San Mateo, CA 94403		(650)572-2607
From: Eric Eide
Subject: Re: Lisp as a script language
Date: 
Message-ID: <ywracyvhcby.fsf@ioka.flux.utah.edu>
"Frank" == Frank Buss <··@frank-buss.de> writes:

	Frank> At
	Frank> http://merd.sourceforge.net/pixel/language-study/scripting-language/
	Frank> Ben Sizer has compared various languages for using as a
	Frank> scripting language.  Lisp is missing, so I'll try it.  Perhaps
	Frank> the experts in this group can fill up the missing topics and
	Frank> then we can mailing it to the site maintainer of Scriptometer.

If you're interested in Lisp-based scripting, you should look at Scsh
<http://www.scsh.net/>, which is still being maintained.  From the Web page:

	Scsh is an open-source Unix shell embedded within Scheme, running on
	all major Unix platforms including AIX, Cygwin, Linux, FreeBSD, GNU
	Hurd, HP-UX, Irix, Mac OS X, Solaris, and some others.

	Scsh is a variant of Scheme 48 (an R5RS compliant new-tech Scheme
	system) Scsh is designed for writing real-life standalone Unix programs
	and shell scripts.  Scsh spans a wide range of application, from
	"script" applications usually handled with perl or sh, to more standard
	systems applications usually written in C.

	[...]

	The latest version of scsh is 0.6.6, released March 29, 2004.  You may
	download this or previous versions of scsh.

Eric.

-- 
-------------------------------------------------------------------------------
Eric Eide <·····@cs.utah.edu>  .         University of Utah School of Computing
http://www.cs.utah.edu/~eeide/ . +1 (801) 585-5512 voice, +1 (801) 581-5843 FAX
From: Björn Lindberg
Subject: Re: Lisp as a script language
Date: 
Message-ID: <hcs7jtzr634.fsf@knatte.nada.kth.se>
Eric Eide <·····@cs.utah.edu> writes:

> "Frank" == Frank Buss <··@frank-buss.de> writes:
> 
> 	Frank> At
> 	Frank> http://merd.sourceforge.net/pixel/language-study/scripting-language/
> 	Frank> Ben Sizer has compared various languages for using as a
> 	Frank> scripting language.  Lisp is missing, so I'll try it.  Perhaps
> 	Frank> the experts in this group can fill up the missing topics and
> 	Frank> then we can mailing it to the site maintainer of Scriptometer.
> 
> If you're interested in Lisp-based scripting, you should look at Scsh
> <http://www.scsh.net/>, which is still being maintained.

What are the advantages compared to CL of using Scsh for scripting? I
know it has integration with system calls and process control, but is
it much better than what the CL implementations offer?


Bj�rn
From: Eric Eide
Subject: Re: Lisp as a script language
Date: 
Message-ID: <ywr8yeewcpe.fsf@ioka.flux.utah.edu>
"Bj�rn" == Bj�rn Lindberg <·······@nada.kth.se> writes:

	Bj�rn> What are the advantages compared to CL of using Scsh for
	Bj�rn> scripting?  I know it has integration with system calls and
	Bj�rn> process control, but is it much better than what the CL
	Bj�rn> implementations offer?

I have to admit that I can't make a fair comparison, because I don't really
know what the CL implementations offer.

In addition to the scsh features you mentioned, scsh also has "an awk facility
for pattern-directed computation over streams of records, a rich facility for
matching regular-expression patterns in strings, event-based interrupt
handling, user-level threads, a futuristic module system, and an interactive
environment" as described at <http://www.scsh.net/>.

I'm sure that the CL implementations have at least the last of these :-).

Eric.

-- 
-------------------------------------------------------------------------------
Eric Eide <·····@cs.utah.edu>  .         University of Utah School of Computing
http://www.cs.utah.edu/~eeide/ . +1 (801) 585-5512 voice, +1 (801) 581-5843 FAX
From: Björn Lindberg
Subject: Re: Lisp as a script language
Date: 
Message-ID: <hcshdsxt2xh.fsf@fnatte.nada.kth.se>
Eric Eide <·····@cs.utah.edu> writes:

> "Bj�rn" == Bj�rn Lindberg <·······@nada.kth.se> writes:
> 
> 	Bj�rn> What are the advantages compared to CL of using Scsh for
> 	Bj�rn> scripting?  I know it has integration with system calls and
> 	Bj�rn> process control, but is it much better than what the CL
> 	Bj�rn> implementations offer?
> 
> I have to admit that I can't make a fair comparison, because I don't really
> know what the CL implementations offer.

What I am really looking for is what someone who knows both CL and
Scsh well thinks. It seems to me that CL with some easily written
extensions can function very well as a Unix scripting language, so I'm
wondering if it would be worth it for a CL programmer to take the time
to learn Scsh just for scripting instead of using CL.


Bj�rn
From: Kenny Tilton
Subject: Re: Lisp as a script language
Date: 
Message-ID: <rNCDc.3833$oW6.648058@twister.nyc.rr.com>
Bj�rn Lindberg wrote:

> Eric Eide <·····@cs.utah.edu> writes:
> 
> 
>>"Bj�rn" == Bj�rn Lindberg <·······@nada.kth.se> writes:
>>
>>	Bj�rn> What are the advantages compared to CL of using Scsh for
>>	Bj�rn> scripting?  I know it has integration with system calls and
>>	Bj�rn> process control, but is it much better than what the CL
>>	Bj�rn> implementations offer?
>>
>>I have to admit that I can't make a fair comparison, because I don't really
>>know what the CL implementations offer.
> 
> 
> What I am really looking for is what someone who knows both CL and
> Scsh well thinks.

That's not me, but...

  It seems to me that CL with some easily written
> extensions can function very well as a Unix scripting language, so I'm
> wondering if it would be worth it for a CL programmer to take the time
> to learn Scsh just for scripting instead of using CL.

Tilton's Law says "Fix the right problem." The problem is not that you 
want to use Scheme, the problem is that there is no CLsh project on 
common-lisp.net. <hint>

Others have said the capability is there, just that it varies between 
implementations and OSes. Kevin Rosenberg gave us UFFI under the same 
circumstances. <hint>

LTk and its derivative Celtic offer a start on CLsh with 
run-program/run-shell-command/whatever. I have been predicting for a 
while now that CL libraries would come from newbies who dig CL but miss 
the libraries. <hint> And it is a great way to learn CL, because there 
is a target (SCsh) to emulate (steal?), not all that much CL to write, 
and there is the motivation of going from newby to the CL Hall of Fame 
in a month.

:)

kt

-- 
Home? http://tilton-technology.com
Cells? http://www.common-lisp.net/project/cells/
Cello? http://www.common-lisp.net/project/cello/
Why Lisp? http://alu.cliki.net/RtL%20Highlight%20Film
Your Project Here! http://alu.cliki.net/Industry%20Application
From: Sam Steingold
Subject: Re: Lisp as a script language
Date: 
Message-ID: <ur7s0tzkk.fsf@gnu.org>
> * Kenny Tilton <·······@alp.ee.pbz> [2004-06-27 16:41:59 +0000]:
>
> Others have said the capability is there, just that it varies between
> implementations and OSes.

CLOCC/PORT/shell.lisp offers some unification

-- 
Sam Steingold (http://www.podval.org/~sds) running w2k
<http://www.camera.org> <http://www.iris.org.il> <http://www.memri.org/>
<http://www.mideasttruth.com/> <http://www.honestreporting.com>
C combines the power of assembler with the portability of assembler.
From: Pascal Bourguignon
Subject: Re: Lisp as a script language
Date: 
Message-ID: <87pt7lhs2y.fsf@thalassa.informatimago.com>
·······@nada.kth.se (Bj�rn Lindberg) writes:

> Eric Eide <·····@cs.utah.edu> writes:
> 
> > "Bj�rn" == Bj�rn Lindberg <·······@nada.kth.se> writes:
> > 
> > 	Bj�rn> What are the advantages compared to CL of using Scsh for
> > 	Bj�rn> scripting?  I know it has integration with system calls and
> > 	Bj�rn> process control, but is it much better than what the CL
> > 	Bj�rn> implementations offer?
> > 
> > I have to admit that I can't make a fair comparison, because I don't really
> > know what the CL implementations offer.
> 
> What I am really looking for is what someone who knows both CL and
> Scsh well thinks. It seems to me that CL with some easily written
> extensions can function very well as a Unix scripting language, so I'm
> wondering if it would be worth it for a CL programmer to take the time
> to learn Scsh just for scripting instead of using CL.

I decided that it was not worthwhile to learn more scheme just for scripting.

I started to write a "scripting" package in clisp including macrology
to get a syntax closer to scsh (to build complex forks and pipes), but
I never used it in all the scripts I've been writting in clisp for two
years.


-- 
__Pascal Bourguignon__                     http://www.informatimago.com/

There is no worse tyranny than to force a man to pay for what he does not
want merely because you think it would be good for him. -- Robert Heinlein
From: Lars Magne Ingebrigtsen
Subject: Re: Lisp as a script language
Date: 
Message-ID: <m3fz8nlj64.fsf@quimbies.gnus.org>
Frank Buss <··@frank-buss.de> writes:

> Looks like standard CL is a bit limited, so perhaps it would be a better 
> idea to compare a special implementation, but I don't know which is the 
> most used implementation or the best implementation for this test.

I think most implementations give you access to these things, but in
vaguely different ways.

In any case, if you plan on doing scripting in Lisp, then you'll most
likely end up with a special-purpose delivered image for doing that
that has the convenience functions you expect to find in a scripting
language.

We use Lisp extensively for tiny scripts that we run off of cron and
the like, and it basically uses a delivered LispWorks image with the
goodies we need.

Like:

------
#!/usr/bin/lws

(format t "The first argument is ~a~%" (argv 0))
------


-- 
(domestic pets only, the antidote for overdose, milk.)
  ·····@gnus.org * Lars Magne Ingebrigtsen
From: Frank Buss
Subject: Re: Lisp as a script language
Date: 
Message-ID: <cbhr7j$54$1@newsreader2.netcologne.de>
Lars Magne Ingebrigtsen <·····@gnus.org> wrote:

> In any case, if you plan on doing scripting in Lisp, then you'll most
> likely end up with a special-purpose delivered image for doing that
> that has the convenience functions you expect to find in a scripting
> language.

Yes, this looks like the best way to do it and this is the advantage of 
Lisp. Bash has more points in the Scriptometer page, but if you implement 
your own functions, it should be possible to use it more flexible than 
calling bash functions or scripts, and it is much easier for programmers to 
use and read it than cryptic bash or perl.

-- 
Frank Bu�, ··@frank-buss.de
http://www.frank-buss.de, http://www.it4-systems.de