CL and iterators - a newbie question
sirola_at_fisica.unige.it
Date: 05/23/04
- Next message: Wade Humeniuk: "Re: CL and iterators - a newbie question"
- Previous message: Paul F. Dietz: "Re: use of identity"
- Next in thread: Wade Humeniuk: "Re: CL and iterators - a newbie question"
- Reply: Wade Humeniuk: "Re: CL and iterators - a newbie question"
- Reply: William Bland: "Re: CL and iterators - a newbie question"
- Reply: Alexey Dejneka: "Re: CL and iterators - a newbie question"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Sun, 23 May 2004 18:36:51 GMT
Hello,
I'm learning lisp and, as an exercise, trying to implement iterators
with CL. I implemented a simple as follows, using a closure:
(defun sarray-iterator (v &key (start 0))
(declare (type (simple-array double-float) v)
(type fixnum start))
(let ((next-position start))
(declare (type fixnum next-position)
(type double-float result))
#'(lambda ()
(let ((result 0d0))
(setq result (aref v next-position))
(incf next-position)
result))))
I tried to profile it a bit using the following code:
(setf (symbol-function 'try2) (sarray-iterator
(make-array 500000
:element-type 'double-float
:initial-element 1.0d0)
:start 0))
(profile:profile try2)
(try2)
(profile:report-time)
the profiler (cmucl) reported
Consed | Calls | Secs | Sec/Call | Bytes/C. | Name:
-----------------------------------------------------------------------
16 | 1 | 0.000 | 0.00000 | 16 | TRY2
so it seems the iterator conses 16 bytes per call (2 double
floats?), am I right? Where does the cons happen? Is it possible to
write a non-consing iterator?
Thanks in advance,
e.
-- Enrico Sirola
- Next message: Wade Humeniuk: "Re: CL and iterators - a newbie question"
- Previous message: Paul F. Dietz: "Re: use of identity"
- Next in thread: Wade Humeniuk: "Re: CL and iterators - a newbie question"
- Reply: Wade Humeniuk: "Re: CL and iterators - a newbie question"
- Reply: William Bland: "Re: CL and iterators - a newbie question"
- Reply: Alexey Dejneka: "Re: CL and iterators - a newbie question"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|
|