Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!sdd.hp.com!hplabs!hplabsz!mayer From: mayer@hplabsz.HPL.HP.COM (Niels Mayer) Newsgroups: comp.lang.lisp Subject: Re: Lisp shells for Unix (was: Extensible languages....) Message-ID: <5881@hplabsz.HPL.HP.COM> Date: 4 Sep 90 00:33:32 GMT References: <13198@hydra.gatech.EDU> Reply-To: mayer@hplabs.hp.com (Niels Mayer) Organization: Hewlett-Packard Labs, Software & Systems Lab, Palo Alto, CA. Lines: 81 Summary: Expires: Sender: Followup-To: In article yukngo@obelix.gaul.csd.uwo.ca (Cheung Yukngo) writes: >1. How should pipes be specified? > (pipe (cat prog.c) (egrep "here") (> "matches")) ? What's the point of doing that?? I'd rather just say (system "cat prog.c | egrep "here" > matches") and then use the return value of the system(3s) call in my lisp prog. I think the | > sytax of current shells capture the flow of data quite nicely. THe lisp syntax above captures the notion of doing functional programming with return values, not streams of data. We want a syntax that captures the notion of dataflow (see also the comments about computing w/ "streams" from Abelson & Sussman's SICP Ch. 3.??)... I think that if you're expecting to do interesting things with streams, you want to settle on a different kind of syntax + semantics than the above. IMHO, the interesting thing to do with Lisp, is to use it as a shell scripting language, rather than a shell command language. Use lisp to parse and capture the output of text-stream oriented unix commands. In particular, I think it's neat to be able to run unix programs, parse their output, and do intereting lispy things with the output. Not only is it neat, but it can give you a nice flexible lispy interface that talks to the rest of the unix world. Interfacing things like popen(3s), scanf(3s), help in this respect. I use such programming alot in my WINTERP environment (a Motif UI + Application prototyping and extension lang based on XLISP -- anon ftp from expo.lcs.mit.edu:contrib/winterp/winterp-.tar.Z). Here's a example of translating unix piped data into the lisp world. It is used to collect data for a search browser built atop the grep(1) command (see winterp/examples/grep-br.lsp for details): ;; define a class of "grep items" (SETQ Grep-Item-Class (SEND Class :new '(file-name line-num match-line) )) ;; define a method to read grep items from a pipe. (SEND Grep-Item-Class :ANSWER :read-grep-info '(pipe) '( (if (AND (SETQ file-name (FSCANF-STRING pipe "%[^:]:")) (SETQ line-num (FSCANF-FIXNUM pipe "%d:")) (SETQ match-line (FSCANF-STRING pipe "%[^\n]\n")) ) SELF ;return SELF if succesful NIL ;return NIL if hit EOF ) )) ;; a function returning a list of "grep-item" objects corresponding to ;; output (DEFUN grep (grep-arg-string) (DO* (;; loop variables, initializers, and increments. (fp (POPEN (STRCAT "grep -n " grep-arg-string " /dev/null") :DIRECTION :INPUT)) (line (SEND (SEND Grep-Item-Class :NEW) :read-grep-info fp) (SEND (SEND Grep-Item-Class :NEW) :read-grep-info fp)) (result '()) ;init to an empty list ) ;; loop test and return ((NULL line) ;:read-grep-info returns NIL on EOF (PCLOSE fp) ;close the pipe opened above (REVERSE result) ;return list of grep objects. ) ;; loop body (SETQ result (CONS line result)) ;prepend grep-obj to list )) PS: I will be out of town for a month, so don't expect followups or quich e-mail response... ------------------------------------------------------------------------------- Niels Mayer -- hplabs!mayer -- mayer@hplabs.hp.com Human-Computer Interaction Department Hewlett-Packard Laboratories Palo Alto, CA. *