Post by B. Pym(defun list-of-length (n list)
"Predicate which tests whether LIST is a list
of length N."
(loop for i from 0 below n
when (null list) do (return nil)
do (pop list)
finally (return (null list))))
Instead of using a macro whose source measures 60 kilobytes,
... we can use a macro whose source is 20 lines and which is not
included in our languager implementation, and then claim that a 7 line
function that must be accompanied by that macro is shorter than a 5 line
function depending only on ANSI Common Lisp.
Post by B. Pymwe can make it shorter by simply using recursion. Of course,
that's not possible in CL since it's not a Lispy language and
doesn't offer tail-call optimization.
The Common Lisp specification doesn't require it, but implementations
offer it.
The ISO C specification deosn't require any optimization at all; yet C
users rely on optimizations (one of them being TCO, by the way).
In C, nobody in their right mind writes i >> 1 rather than i / 2 any
more, even though ISO C doesn't "offer" the assumption that i / 2 will
be reduced to a shift.
Scheme offers very little; most serious work done with Scheme picks
an implementation and uses it.
Many of your own posts pick a particular Scheme like Gauche and
often use its extensions that are not in Scheme.
Post by B. Pym(define (list-of-length? n lst)
(cond ((zero? n) (null? lst))
((null? lst) #f)
(#t (list-of-length? (- n 1) (cdr lst)))))
You would avoid this kind of function entirely (and linked lists
all together) in code that is to be maximally performant. Linked
lists have poor cache performance. Chasing down a linked list
involved dependent loads which the machine cannot prefetch, unlike
marching down an array that is contiguously laid out in memory.
The battle you are trying to pick here is outdated.
Whether list processing code is recursive or iterative, and how fast it
is, is largerly irrelevant. Most list processing is compile time code
wrangling (macros and whatnot). Performance of the compile time is
not highly relevant, or else nobody would be using C++.
--
TXR Programming Language: http://nongnu.org/txr
Cygnal: Cygwin Native Application Library: http://kylheku.com/cygnal
Mastodon: @***@mstdn.ca