[Top][All Lists]

[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: Bahman Movaqar
Subject: Re: [Chicken-users] Idiomatic way to access nth element of a list
Date: Sun, 14 Dec 2014 20:24:25 +0330
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.3.0

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:

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 - -
PGP Key ID: 0x6AB5BD68 (

Attachment: signature.asc
Description: OpenPGP digital signature

reply via email to

[Prev in Thread] Current Thread [Next in Thread]