Skip to content

Instantly share code, notes, and snippets.

@sunng87
Created November 18, 2011 02:37
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sunng87/1375401 to your computer and use it in GitHub Desktop.
Save sunng87/1375401 to your computer and use it in GitHub Desktop.
spark in common lisp
#!/usr/bin/clisp
(defconstant ticks (list "▁" "▂" "▃" "▄" "▅" "▆" "▇" "█"))
(defun spark (data-list)
(let ((max-value (apply #'max data-list))
(ticks-length (length ticks)))
(let ((ticks-unit (/ max-value (- ticks-length 1))))
(map 'list (lambda (x) (elt ticks (ceiling (/ x ticks-unit)))) data-list))))
;; copied from cl-cookbook: http://cl-cookbook.sourceforge.net/strings.html
(defun split (string spliter)
(loop for i = 0 then (1+ j)
as j = (position spliter string :start i)
collect (subseq string i j)
while j))
(format t
(apply #'concatenate 'string
(spark (map 'list #'read-from-string
(if *args*
(split (first *args*) #\,)
(split (read-line) #\,))))))
@sunng87
Copy link
Author

sunng87 commented Nov 19, 2011

Usage:

chmod u+x clspark

clspark "1,2,3,4,5"

echo "1,2,3,4,5" | clspark

@zlatanvasovic
Copy link

Great implementation. :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment