[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Chicken-users] Idiomatic way to access nth element of a list
From: |
Richard |
Subject: |
Re: [Chicken-users] Idiomatic way to access nth element of a list |
Date: |
Sun, 14 Dec 2014 17:53:59 +0000 |
Forgot to CC the list, and now I lost my original message :(
... trying again
Hello Bayren,
To access the nth-element of a list one would use list-ref. For example:
(list-ref (list 1 2 3 4) -> 3)
The problem with linked-lists is that in order to access an element the
list has to be traversed. To access/modify elements in constant time it
might be better to use vectors instead. If you need vectors that grow in
size dynamically have a look at the dyn-vector egg:
http://wiki.call-cc.org/eggref/4/dyn-vector
greetings,
Richard
Bahman Movaqar writes:
> How would a seasoned Schemer access the nth element of a list? (drop)?
> Does it have any performance penalty?
>
> TIA,
--