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

Pages: 1-

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: op 2011-06-16 19:25

here again in code tags......


(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)))

Name: Anonymous 2011-06-16 19:26

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

Name: Anonymous 2011-06-16 19:28

>>3
Yeah, use [m] tags.

Name: Anonymous 2011-06-17 0:27

You missed a parenthesis.

Name: Anonymous 2011-06-17 2:07

(funcall f argument)
This is what's wrong with Common Lisp. It's just plain ugly.

Name: Anonymous 2011-06-17 2:53

(loop for result
       in (normalize (compress results
                   (round (/ (length results) height)))
             width) do
     (loop repeat (round result)
        do (write-char char))
Indenting in this one is atrocious.

Name: Anonymous 2011-06-17 2:55

(loop for result
       in (normalize (compress results
                   (round (/ (length results) height)))
             width) do
     (loop repeat (round result)
        do (write-char char))

Hmm...

Name: Anonymous 2011-06-17 2:55

(loop for result[o]
       in (normalize (compress results
                   (round (/ (length results) height)))
             width) do
     (loop repeat (round result)
        do (write-char char))[/o]
Yeah.

Name: Anonymous 2011-06-17 2:57

>>9
BBCode? More like rocket science, amirite?

Name: Anonymous 2011-06-17 10:46

>>10
no shit

(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)))
         (density (round (/ (length results) height))))
    (loop for result
       in (normalize (compress results density) 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)))

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