On 12/14/2014 09:18 PM, Richard wrote:
> Hello Bayman,
>
> The get to the nth element of a list one would use list-ref.
> For example:
>
> (list-ref (list 1 2 3 4) 2) -> 3
>
> The problem with linked lists is that in order to get to the nth element
> the list has to be traversed, which does bring a performance penalty.
>
> You can use vectors instead of list if you want to access/modify
> elements in constant time. If you need a vector that can dynamically
> grow take a look at the dyn-vector egg:
> http://wiki.call-cc.org/eggref/4/dyn-vector.
>
>
> Bahman Movaqar writes:
>
>> How would a seasoned Schemer access the nth element of a list? (drop)?
>> Does it have any performance penalty?
>>

Thanks Richard and Shawn for the answer. For my use case I find it
acceptable to use the cleaner more comprehensive list interface (rather
than vectors) at the expense of the performance penalty.

-- 
Bahman Movaqar

http://BahmanM.com - https://twitter.com/bahman__m
https://github.com/bahmanm - https://gist.github.com/bahmanm
PGP Key ID: 0x6AB5BD68 (keyserver2.pgp.com)

Attachment: signature.asc
Description: OpenPGP digital signature

_______________________________________________
Chicken-users mailing list
[email protected]
https://lists.nongnu.org/mailman/listinfo/chicken-users

Reply via email to