Search found 11 matches
- Wed Sep 01, 2010 5:27 am
- Forum: Common Lisp
- Topic: averaging
- Replies: 12
- Views: 11437
Re: averaging
I didn't use the key argument. Thanks for the example. It was very helpful.
- 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 ...
- 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'.
reduce worked beautifully. And I knew something was wrong when I used 'eval'.
- 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)))
- 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
http://la7dja.org/lisp/clml/utils.lisp
- 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?
- Sun Aug 29, 2010 9:53 pm
- Forum: Common Lisp
- Topic: stuck
- Replies: 14
- Views: 12253
Re: stuck
Got'cha
- 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...
- 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.
- 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:
Is there a simpler way to do this recusively?
Code: Select all
(defun odd-count (lst)
(if (null lst)
0
(+ (if (oddp (first lst)) 1 0)
(odd-count (rest lst)))))