Re: efficiently accumulating values
- From: Pascal Bourguignon <pjb@xxxxxxxxxxxxxxxxx>
- Date: Thu, 06 Jul 2006 11:01:52 +0200
liyer.vijay@xxxxxxxxx writes:
liyer.vijay@xxxxxxxxx wrote:
[snip my own stuff]
Hi,
I found the reference in PCL (Peter, if you're reading this, thanks)
to VECTOR-PUSH-EXTEND which dramatically reduces time to 0.346
seconds. Here is the program:
(defun find-words (graph)
"Given GRAPH find all possible words."
(destructuring-bind (m n) (array-dimensions graph)
(loop with result = (make-array 0 :adjustable t :fill-pointer 0)
as i from 0 to (1- m)
I'd write:
:for i :from 0 :below m
Some would write:
for i below m
do (loop as j from 0 to (1- n)
do (loop as word in (get-words graph i j)
if (and (zerop i) (zerop j))
do (vector-push-extend word result)))
finally (return (coerce result '(or cons list))))))
list == (or nil cons) therefore (or cons list) == list
However, I'd still like to know if there's a better way, and since I
didn't mention it in my last post, any suggestions, comments,
criticisms on coding style, programming are greatly appreciated.
Now, what you seem to be doing in find-words, is jusd that:
(defun find-words (graph)
"Given GRAPH find all possible words."
(let ((words (get-words graph 0 0)))
(if words
(copy-list words)
'())))
Unless get-words is not a pure function. Do you have any side effect
in get-words?
--
__Pascal Bourguignon__ http://www.informatimago.com/
HEALTH WARNING: Care should be taken when lifting this product,
since its mass, and thus its weight, is dependent on its velocity
relative to the user.
.
- Follow-Ups:
- Re: efficiently accumulating values
- From: liyer . vijay
- Re: efficiently accumulating values
- References:
- efficiently accumulating values
- From: liyer . vijay
- Re: efficiently accumulating values
- From: liyer . vijay
- efficiently accumulating values
- Prev by Date: Re: Why is lisp better than java perl or python or ruby?
- Next by Date: Re: pointless rant against newlisp and other tangents.
- Previous by thread: Re: efficiently accumulating values
- Next by thread: Re: efficiently accumulating values
- Index(es):
Relevant Pages
|