From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Stefan Huchler Newsgroups: gmane.emacs.help Subject: Re: beginnerquestion (nconc) Date: Fri, 17 Mar 2017 17:59:20 +0100 Message-ID: <87k27nzvo7.fsf@mail.de> References: <87shmc1m2u.fsf@mail.de> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Trace: blaine.gmane.org 1489770045 23351 195.159.176.226 (17 Mar 2017 17:00:45 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Fri, 17 Mar 2017 17:00:45 +0000 (UTC) User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.1 (gnu/linux) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Fri Mar 17 18:00:41 2017 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1covF1-0005Xy-NL for geh-help-gnu-emacs@m.gmane.org; Fri, 17 Mar 2017 18:00:39 +0100 Original-Received: from localhost ([::1]:49959 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1covF7-0008W9-FT for geh-help-gnu-emacs@m.gmane.org; Fri, 17 Mar 2017 13:00:45 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:59655) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1covEg-0008Vq-Ct for help-gnu-emacs@gnu.org; Fri, 17 Mar 2017 13:00:19 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1covEd-0000fx-P4 for help-gnu-emacs@gnu.org; Fri, 17 Mar 2017 13:00:18 -0400 Original-Received: from [195.159.176.226] (port=34532 helo=blaine.gmane.org) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1covEd-0000fP-Hl for help-gnu-emacs@gnu.org; Fri, 17 Mar 2017 13:00:15 -0400 Original-Received: from list by blaine.gmane.org with local (Exim 4.84_2) (envelope-from ) id 1covES-0002aM-UN for help-gnu-emacs@gnu.org; Fri, 17 Mar 2017 18:00:04 +0100 X-Injected-Via-Gmane: http://gmane.org/ Original-Lines: 32 Original-X-Complaints-To: usenet@blaine.gmane.org Cancel-Lock: sha1:wJo+RnSKLREg+PcTlqnC1deJNRY= X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 195.159.176.226 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Original-Sender: "help-gnu-emacs" Xref: news.gmane.org gmane.emacs.help:112593 Archived-At: Yuri Khan 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.