Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

lisp

Name: Anonymous 2011-06-16 19:25

How do you guys feel about lisp? I like common lisp. Lets play a game: find my stupid mistakes.

<code>
(defun plot (f min max &key (step 1) (width 50) (height 50) (char #\*))
  "Plot F with input from MIN to MAX by STEP on a WIDTH * HEIGHT grid."
  (let ((results (loop for argument from min to max by step
            collect (funcall f argument))))
    (format t "~a results~%" (length results))
    (loop for result
       in (normalize (compress results
                   (round (/ (length results) height)))
             width) do
     (loop repeat (round result)
        do (write-char char))
     (write-char #\Newline))))

(defun normalize (values limit)
  "Normalize VALUES so that they range from 0 to
LIMIT."
  (let ((scale (/ limit (loop for value in values
               maximize value))))
    (loop for value in values
       collect (* scale value))))

(defun compress (values density)
  "Compress VALUES by DENSITY."
  (loop for i from 1 by 1
     for value in values
     for sum = 0 then (+ sum value)
     when (= 0 (mod i density))
     collect (let ((sample (/ sum density)))
           (setf sum 0)
           sample)))
</code>

Name: Anonymous 2011-06-16 19:26

Sorry to say but this board sucks at colouring lisp :(

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List