Skip to content

Instantly share code, notes, and snippets.

@eschulte
Last active December 24, 2015 10:08
Show Gist options
  • Save eschulte/6781511 to your computer and use it in GitHub Desktop.
Save eschulte/6781511 to your computer and use it in GitHub Desktop.
Use feedgnuplot to visualize list data from the Common Lisp REPL
;; Use feedgnuplot to visualize list data from the Common Lisp REPL.
;;
;; Useful for visualizing distributions of large lists.
;;
;; Example usage.
;;
;; (feedgnuplot (loop :for x :below 200 :collect (sin (/ x 25))))
;; (feedgnuplot (loop :for x :below 2000 :collect (random 25)) :histogram t)
;; (feedgnuplot (loop :for x :from 1 :upto 200 :collect (list (float (/ x 25)) (sin (/ x 25)))))
;; (feedgnuplot (loop :for x :from 1 :upto 200 :collect (list (float (/ x 25)) (sin (/ x 25))))
;; :domain t)
(defvar path-to-feedgnuplot "/usr/bin/feedgnuplot")
(defun feedgnuplot (list &key domain lines histogram)
(let ((proc
(#+ccl ccl:run-program
#+sbcl sb-ext:run-program
path-to-feedgnuplot
`(,@(when domain '("--domain"))
,@(when lines '("--lines"))
,@(when histogram
(list "--exit" "--histogram"
(format nil "~d"
(if (numberp histogram) histogram 0)))))
:input :stream :wait nil)))
(with-open-stream (feed
#+ccl (ccl:external-process-input-stream proc)
#+sbcl (sb-ext:process-input proc))
(format feed "~{~{~a~^ ~}~^~%~}~%" (mapcar (lambda (el)
(if (listp el) el (list el)))
list)))
proc))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment