Sysop: | Amessyroom |
---|---|
Location: | Fayetteville, NC |
Users: | 40 |
Nodes: | 6 (0 / 6) |
Uptime: | 10:30:42 |
Calls: | 291 |
Files: | 910 |
Messages: | 76,424 |
(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))))
(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 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.
Scheme:
(define (list-of-length? n lst)
(cond ((zero? n) (null? lst))
((null? lst) #f)
(#t (list-of-length? (- n 1) (cdr lst)))))
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.
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.
Kaz Kylheku <643-408-1753@kylheku.com> writes:
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.
Like in geography: "Where does London end?" (-:
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.
I have read so a couple of times. Interesting. But what is a Lisper to
do in the source code? Convert it all to vectors/arrays? Use more
imperative idioms than recursion? Do not care, because it is all handled
by the implementation?
Honestly curious,
Lists are fine in most situations. Just maybe when you find yourself
doing discrete Fourier transforms on nested lists on what is supposed
to be some sort of real time signal processing code, maybe have a word
with yourself.
Kaz Kylheku <643-408-1753@kylheku.com> writes:
The battle you are trying to pick here is outdated.
I have read so a couple of times. Interesting. But what is a Lisper to
do in the source code? Convert it all to vectors/arrays? Use more
imperative idioms than recursion? Do not care, because it is all handled
by the implementation?