Created
November 18, 2011 02:37
-
-
Save sunng87/1375401 to your computer and use it in GitHub Desktop.
spark in common lisp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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) #\,)))))) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Usage:
chmod u+x clspark
clspark "1,2,3,4,5"
echo "1,2,3,4,5" | clspark