Search found 11 matches

by s-imp
Wed Sep 01, 2010 5:27 am
Forum: Common Lisp
Topic: averaging
Replies: 12
Views: 11437

Re: averaging

:oops: I didn't use the key argument. Thanks for the example. It was very helpful.
by s-imp
Tue Aug 31, 2010 9:19 pm
Forum: Common Lisp
Topic: averaging
Replies: 12
Views: 11437

Re: averaging

I like the idea of closures, though it is a bit above my pay-grade at the moment, Duke. I had another solution that used 'let' and 'dolist', but I didn't want to use setf. It must have been something I read somewhere about minimizing their usage. Is that just for a style of programming using Common ...
by s-imp
Tue Aug 31, 2010 9:05 pm
Forum: Common Lisp
Topic: averaging
Replies: 12
Views: 11437

Re: averaging

Thanks Kohath.

reduce worked beautifully. And I knew something was wrong when I used 'eval'.
by s-imp
Tue Aug 31, 2010 6:48 pm
Forum: Common Lisp
Topic: averaging
Replies: 12
Views: 11437

Re: averaging

I'm sure this is bad but:

Code: Select all

(defun average-list (lst)
  (/
     (eval (append '(+)
                  (mapcar #'(lambda (x) (first (last x))) lst)))
     (length lst)))

by s-imp
Mon Aug 30, 2010 2:12 am
Forum: Common Lisp
Topic: File I/O woes
Replies: 9
Views: 7771

Re: File I/O woes

I've been looking through all my books and scratching my head, but I found this nice web-page I shall be going over with a fine toothed comb when the time is right:

http://la7dja.org/lisp/clml/utils.lisp
by s-imp
Sun Aug 29, 2010 10:09 pm
Forum: Common Lisp
Topic: "Morphing/Warping" of two lists
Replies: 8
Views: 8065

Re: "Morphing/Warping" of two lists

Wouldn't you just find the difference between A and B for each point, divide by how many intermediate steps to get a transform list (T) and then mapcar adding T to A, and using each result list as the new A until A becomes B?
by s-imp
Sun Aug 29, 2010 9:53 pm
Forum: Common Lisp
Topic: stuck
Replies: 14
Views: 12253

Re: stuck

;) Got'cha
by s-imp
Sun Aug 29, 2010 8:24 pm
Forum: Common Lisp
Topic: stuck
Replies: 14
Views: 12253

Re: stuck

Yeah, I thought about 'length', but I knew to avoid creating cons cells for a new list as you do get a performance penalty for it. Thank you both for the info on tail-recursion. So my function is not tail recursive (as it calls #'+ last). I traced it and then disassembled it to see what was going on...
by s-imp
Sun Aug 29, 2010 5:47 pm
Forum: Common Lisp
Topic: stuck
Replies: 14
Views: 12253

Re: stuck

I heard that recursion was a lispy way of doing things, but there could be a better way. I'm not sure if it comes with a performance cost. Perhaps one of the pros can chime in. I'm still trying to get my head around what tail recursion is.
by s-imp
Sun Aug 29, 2010 3:25 pm
Forum: Common Lisp
Topic: stuck
Replies: 14
Views: 12253

Re: stuck

I'm just a newbie, how is this for a recursive solution:

Code: Select all

(defun odd-count (lst)
  (if (null lst)
       0
       (+ (if (oddp (first lst)) 1 0)
            (odd-count (rest lst)))))
Is there a simpler way to do this recusively?