From: Eric de Groot
Subject: CMUCL CGI scripting
Date: 
Message-ID: <viFL6.11077$vf6.1192810@news1.rdc1.sdca.home.com>
How can I use CMUCL from the cgi-bin?  I've been using CLISP, and it handles
just like perl, eg:

#!/usr/bin/clisp
(format t "Content-type text/html;~%~%Hello World!~%")

Is anything like that possible with CMUCL?  Interpreted and compiled.  I
love how simple CLISP is, but now I need to talk to MySQL and all I can find
is UncommonSQL, but it's for CMUCL.  Anyone know how I can work with MySQL
from CLISP?  Database stuff aside, how would you do the above script with
CMUCL?  Thanks.

-Eric

From: Johannes Gr�dem
Subject: Re: CMUCL CGI scripting
Date: 
Message-ID: <lzy9s0u6rl.fsf@wintermute.copyleft.no>
"Eric de Groot" <············@ericdegroot.com> writes:

> #!/usr/bin/clisp
> (format t "Content-type text/html;~%~%Hello World!~%")

Eric Marsden has a program that lets you do this with CMUCL.  Get it
at http://www.chez.com/emarsden/downloads/.  Also, you might want to check
out mod_lisp at http://www.fractalconcept.com/asp/mod_lisp2/.

-- 
johs
From: Rob Warnock
Subject: Re: CMUCL CGI scripting
Date: 
Message-ID: <9dviid$8v856$1@fido.engr.sgi.com>
Mike McDonald <·······@mikemac.com> replied to:
+---------------
| ······@schlund.de (Hannah Schroeter) writes:
| > #! /bin/sh
| > exec sbcl --noinform --noprint --noprogrammer			\
| >     --eval '(load "foo.lisp")' --eval '(quit)' --end-toplevel-options
+---------------

And since most people who write scripts want to have the whole thing
inline -- not in a separate file -- he countered with:

+---------------
| #! /bin/sh -f
| exec /usr/local/bin/cmucl -quiet -batch \
|      -eval '(setq *prompt* "")' -noinit <<\EOF
| (progn
|     ;; My code goes here
|     (print `hello-world)
|     (values))
| EOF
+---------------

But in my experience most people who write scripts want them
in-line *and* want to be able to access the normal inherited
standard-input when the script runs (say, to interact with the
user, or with a piped stdin), which Mike's approach precludes.

Here's the gross, ugly, smelly hack I've been using with CMUCL &
CLISP (with minor variations) to provide both at the same time:

	% cat ~/bin/hello_cmucl
	#!/bin/sh -f
	exec /usr/local/bin/cmucl -eval \ 
	"(progn		; double the backslashes for 'sh'
	   (set-dispatch-macro-character #\\# #\\!
	     (get-dispatch-macro-character #\\# #\\| ))
	   (defvar *script-name* \"$0\")     
	   (defvar *script-args* \"$*\")     
	   (load *script-name* :verbose nil))"    
	|# ; close the block comment [CLISP needs "!#" here]

	(format t "Hello world!~%Script = ~S~%Args = ~S~%"
		  *script-name* *script-args*)
	;(format t "~%Input a number: ")	; oops, not if piped
	(let ((x (read)))
	  (format t "~S squared = ~S~%" x (* x x)))
	(quit)

	% echo 23.45 | hello_cmucl foo bar "baz gorp"
	Hello world!
	Script = "/u/rpw3/bin/hello_cmucl"
	Args = "foo bar baz gorp"
	23.45 squared = 549.9025
	% 


-Rob

p.s. The main problem remaining with the above is Unix command-line
arguments with spaces in them (e.g., "baz gorp"), since the "$*"
doesn't distinguish between inter- and intra-arg whitespace. The
usual Unix solution here would be to use ··@", e.g.:

	"(progn ...
	   (defvar *script-args* '#(···@\")) ; build a vector of strings
	   ...)"

but that doesn't work because the inter-arg quotes [or more precisely,
the <quote><space><quote> sequences] that ··@" introduces don't get
backslash-quoted here, and thus break the string argument to "-eval"
in the middle, causing a premature EOF. (Oops!)

-----
Rob Warnock, 31-2-510		····@sgi.com
SGI Network Engineering		<URL:http://reality.sgi.com/rpw3/>
1600 Amphitheatre Pkwy.		Phone: 650-933-1673
Mountain View, CA  94043	PP-ASEL-IA
From: Eric Marsden
Subject: Re: CMUCL CGI scripting
Date: 
Message-ID: <wzir8xommhf.fsf@mail.dotcom.fr>
>>>>> "rw" == Rob Warnock <····@rigden.engr.sgi.com> writes:

  rw> % echo 23.45 | hello_cmucl foo bar "baz gorp"
  rw> Hello world!
  rw> Script = "/u/rpw3/bin/hello_cmucl"
  rw> Args = "foo bar baz gorp"
  rw> 23.45 squared = 549.9025
  rw> 
  rw> p.s. The main problem remaining with the above is Unix command-line
  rw> arguments with spaces in them (e.g., "baz gorp")

you can avoid this (for CMUCL anyways) using my trampoline program
<URL:http://www.chez.com/emarsden/downloads/cmucl-trampoline.c>

,----
| ~/tmp$ echo 23.45 | trampoline-demo foo bar "baz gorp"
| Script "/home/emarsden/bin/trampoline-demo" invoked with arguments 
| ("foo" "bar" "baz gorp")
| 23.45 squared = 549.9025
`----

where trampoline-demo looks like

,----
| #!/home/emarsden/bin/cmucl-trampoline \
| -noinit -batch -quiet -core /home/emarsden/lib/cmucl/ecm.img
| !#
| 
| (format t "Script ~s invoked with arguments ~&~s~%"
|         *command-line-utility-name*
|         (cdr (member "-eval=(ext:quit)" *command-line-strings* :test #'string=)))
| (let ((x (read)))
|   (format t "~S squared = ~S~%" x (* x x)))
`----

Your image needs a reader macro for the #! ... !#. 

-- 
Eric Marsden                          <URL:http://www.laas.fr/~emarsden/>