Hi Charles, Mike ,
" I don't know why Rob is so fond of hand coded iterative palliations. " -- because I can
without joking -->
Be careful, iterations and variadic structures do not belong together -- example :
(silent
(define sq (sequence 1 100000))
(define ar (array (length sq) sq))
(define (tst x)
(let (( acc 0 ))
(dotimes (i (length x))
(++ acc (nth i x)))))
)
-------------------------------repl
> (time (tst sq)) ;; variadic container (a list)
21640.625 !!!!!!!!!!!!!!!!!!!!!!!! that's 22 sec !!!!!!!!!!!!!!!!!!!!!!!!!
> > (time (tst ar)) ;; non-variadic container (vector/array)
46.875
>
---------------------------
because : the iterative process has to start from 0 every time -- it does not remember the location of a previous pointer - the array / vector works identical with languages as Basic, C etc ... However, by writing the stuff myself , I do know where to locate the pointers , I do know when to set up accumulators in recursive mechanisms , ... )
(define (tst L)
(letrec (( tst* (lambda (L acc)
(if (null? L) acc
(tst* (cdr L) (+ acc (car L))))))
(tst* L 0) )
this one goes thru the pointers as -> A -> B -> C ... -> NULL
the iterative form goes
-> A
-> -> B
-> -> -> C
-> -> ........................ ->NULL
(of course C , Oxygen , Basic's etc.. can increment the pointers , but his doesn't make sense if the "pointée" is of variadic type and/or length -- in Lisp the pointers are stored inside the data , it is not something as one memory location holding an address )
"Also, any such constructs reimplemented via LISP macros and/or lambdas would be slower than their core equivalents by definition." -- allmost all (except the fexpressions in NewLISP) languages do the (macro)expansion while loading the code -- a compiler will do this anyway -- the expanded macro definitions are identical as coded without them, but the source is clearer to read and certainly write ....
I prefer to write something as (inc x) i.o. (set! x (+ 1 x)) certainly if used frequently , the generated code is identical ...
(of course if already existing , rewriting same is idiotic , but I don't think Scheme has (inc ) (dec ) (++ ) (-- ) etc ..
best Rob
(ps named let is a recursive mechanism, not ?? -- I think it's based on a (letrec ... )
furthermore , AFAIK Scheme can't even index lists , there is no (elt list index) or (nth index list) , to avoid doing what I did at the start of this text ...
(letrec ((countdown (lambda (i)
(if (= i 0) 'liftoff
(begin
(display i)
(newline)
(countdown (- i 1)))))))