Skip to content

Instantly share code, notes, and snippets.

@snmsts
Created October 4, 2015 14:30
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save snmsts/5abde1792c14c8a36e6c to your computer and use it in GitHub Desktop.
Save snmsts/5abde1792c14c8a36e6c to your computer and use it in GitHub Desktop.
#!/bin/sh
#|-*- mode:lisp -*-|#
#|
exec ros -Q -- $0 "$@"
|#
(defvar *filters* '(/line))
(defvar *results* '())
(defun /line (output error)
(values
(lambda (input)
(loop :for line := (read-line input nil nil)
:while line
:do (funcall output line)))
error))
(defun to-stream (stream)
(lambda (x)
(typecase x
(string (format stream "~A~%" x))
((simple-array (unsigned-byte 8) (*))
(write-sequence x stream))
(t (format stream "~S~%" x)))))
(defun main (&rest argv)
(declare (ignorable argv))
(loop
:with output := (let ((output (to-stream *standard-output*)))
(lambda (input) (funcall output input)))
:with error := (let ((output (to-stream *error-output*)))
(lambda (input) (funcall output input)))
:for f :in *filters*
:do (multiple-value-setq (output error)
(funcall f output error))
:finally (funcall output *standard-input*))
(mapc #'funcall *results*))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment