[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: beginnerquestion (nconc)
From: |
Stefan Huchler |
Subject: |
Re: beginnerquestion (nconc) |
Date: |
Fri, 17 Mar 2017 17:59:20 +0100 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/25.1 (gnu/linux) |
Yuri Khan <yuri.v.khan@gmail.com> writes:
> You are probably annoyed because you are familiar with list
> implementations in other languages where appending an element is a
> cheap operation. For example, with a doubly linked list, appending at
> either end is constant time.
>
> However, Lisp uses singly linked lists. Appending at the start is a
> matter of allocating a single cons cell and setting its cdr to point
> to the old head of the list. However, appending at the end requires
> traversing the whole list to find its last cell, and then adding a new
> cell there. That’s what nconc does. So if your list is 1000 items
> long, populating it from beginning to end takes roughly 500000
> operations. Populating from the end to beginning and then reversing
> will only take on the order of 3000 operations.
Hello Yuri,
thanks at least I see know WHY it is designed that way, performence.
But if I have to reverse, wouldnt it be easier that there is some sort
of:
(yreverse sequence)
that alters the sequence directly, or overwrites it.
instead of:
(setq sequence (nreverse sequence))
would make it less ugly.
- beginnerquestion (nconc), Stefan Huchler, 2017/03/17
- Re: beginnerquestion (nconc), Thien-Thi Nguyen, 2017/03/17
- Re: beginnerquestion (nconc), Yuri Khan, 2017/03/17
- Re: beginnerquestion (nconc),
Stefan Huchler <=
- Re: beginnerquestion (nconc), Stefan Monnier, 2017/03/17
- Re: beginnerquestion (nconc), Stefan Huchler, 2017/03/21
- Re: beginnerquestion (nconc), Stefan Huchler, 2017/03/21
- Re: beginnerquestion (nconc), John Mastro, 2017/03/21
- Re: beginnerquestion (nconc), Stefan Huchler, 2017/03/21
- Re: beginnerquestion (nconc), Michael Heerdegen, 2017/03/22
- Re: beginnerquestion (nconc), John Mastro, 2017/03/22
- Re: beginnerquestion (nconc), Michael Heerdegen, 2017/03/21