Newsgroups: comp.lang.lisp
Path: cantaloupe.srv.cs.cmu.edu!bb3.andrew.cmu.edu!nntp.sei.cmu.edu!cis.ohio-state.edu!math.ohio-state.edu!howland.reston.ans.net!agate!ames!cnn.nas.nasa.gov!eos!kronos.arc.nasa.gov!ptolemy.arc.nasa.gov!kpc
From: k p c <kpc@ptolemy.arc.nasa.gov>
Subject: Unix pipelines in Common Lisp (a la sh or scsh)
Message-ID: <1995Nov25.025938.21297@ptolemy-ethernet.arc.nasa.gov>
X-Disclaimer: No organization, company, or government is represented here.
X-Attribution: kpc
Lines: 59
Sender: usenet@ptolemy-ethernet.arc.nasa.gov (usenet@ptolemy.arc.nasa.gov)
Nntp-Posting-Host: phenotype.arc.nasa.gov
Reply-To: kpc@ptolemy.arc.nasa.gov
Cc: kpc@ptolemy.arc.nasa.gov
Organization: NASA Ames Research Ctr., AI Research and Aero. Facil. Branches.
	Disclaimer: neither a civil servant nor a representative.
Date: Sat, 25 Nov 1995 03:08:26 GMT

I want to do easy pipes in CL, like | in an sh script.  scsh has & and
|.  An example is calling find, xargs, a lisp function, and grep in a
Unix pipeline.

Is this feasible in CL?  There is nothing in the archives AFAICT.
Please let me know if you've tried it.

Is it efficient?  Are there problems with blocking, asynchrony,
multiple processing, memory, conditions (e.g. Unix hangup or pipe
signals), or anything else?  Did you also look into sockets, string
streams, etc.?  Did you also look into standard error, tees, joins,
:if-exists, etc.?  How come your code is not in the archive?  :-)

Allegro's run-shell-command function seems to have the necessary
keywords to write such a command using streams.  Other implementations
have similar functions, so maybe #+ style portability is possible.

    run-shell-command command [:input intype] [:output outype] [:error-
      output eo] [:wait w] [:if-input-does-not-exist ifdne] [:if-output-
      exists ioe] [:if-error-output-exists ieoe]

Here is one example:

	;;
	;;bogus example to show a Unix pipeline.
	;;
	;;here we run the sort program on a file and pipe the output
	;;to a properly written lisp function and finally /bin/grep.
	;;
	;;there is no input to the pipeline and the output would
	;;perhaps go to *standard-output* in this example.
	;;
	;;different syntax, such as keywords to support backgrounding
	;;and redirection, is possible.
	;;

	(pipe	"sort /etc/myfile"			;simple call, no input
		(print-lines-containing "abc")		;lisp function
		'("/bin/grep" "mygrep" "-i" "def")	;direct exec
		)

Note that the direct exec might not be available in most CL's.  It's
not essential.  I have ignored several issues for simplicity.  This is
just an example.  I am interested in what people have done.

For use as a scripting language I have evaluated scsh, guile, and a
dozen other schemes, as well as xlisp-plus, xlisp-stat, ISO Lisp,
elisp, and a few small lisps.  Although a few are close, none has the
CL compatibility that I prefer.  Hence the desire to use gcl, clisp,
cmucl, and Allegro.  gcl has built in regexps now.

If you post a followup to this article, please also send a courtesy
verbatim copy by email to help work around potentially unreliable
feeds.

---
kpc@ptolemy.arc.nasa.gov.  AI, multidisciplinary neuroethology, info filtering.
	You care for nothing but shooting, dogs, & rat-catching, & you will be
	a disgrace to yourself & all your family -- Darwin's father to Charles
