Subject: Re: basic questions
From: rpw3@rpw3.org (Rob Warnock)
Date: Tue, 20 Nov 2007 06:39:48 -0600
Newsgroups: comp.lang.lisp
Message-ID: <e86dncxCt-gJSN_anZ2dnUVZ_ualnZ2d@speakeasy.net>
Barry Fishman  <barry_fishman@acm.org> wrote:
+---------------
| $ cat >hello
| ":" ; exec lisp -quiet -noinit -load "`which $0`" ${1+"$@"}
| (defvar *args* (nthcdr 5 *command-line-strings*))
| (format t "Hello ~a!~%" (car *args*))
| (quit)
| ^D
| $ chmod 755 hello
+---------------

Awww!!! Now you've given away *all* our secrets!!  ;-}

Well, not quite all:

    $ cat ./show-stock-by-season
    #!/usr/local/bin/cmucl -script
    (require :utils)
    (require :pg)
    (use-package :utils)
    (use-package :pg)

    (when (null (first *script-args*))
      (error "Need season arg"))

    (defun sql-sanitize (x)
      (coerce (loop for c across x
		collect c
		when (eql c #\')
		 collect c)
	      'string))

    (with-pg-connection (conn "rpw3" "rpw3")
      (let* ((season (sql-sanitize (first *script-args*)))
	     (query (format nil "select * from stock ~@
				 where c1 = '~a'" season))
	     (result (pg-exec conn query))
	     (cols (mapcar #'car (pg-result result :attributes)))
	     (rows (pg-result result :tuples)))
	(format t "~{~a~%~}" (cons cols rows))))

    $ ./show-stock-by-season fall
    (season format title stock_number)
    (fall tape My Favorite Thanksgiving 16)
    $ ./show-stock-by-season xmas
    (season format title stock_number)
    (xmas book My Favorite Christmas 2)
    (xmas video The Grinch who Stole Christmas 4)
    (xmas video Home Alone 6)
    $ 


-Rob

p.s. How to make that "-script" thingy work *without*
changing the distributed CMUCL executable or core image is
the subject of my next bit of open-sourcing. "Film at 11..."
Hint: It's just a small hack to "site-init.lisp".

-----
Rob Warnock			<rpw3@rpw3.org>
627 26th Avenue			<URL:http://rpw3.org/>
San Mateo, CA 94403		(650)572-2607