From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Zelphir Kaltstahl Newsgroups: gmane.lisp.guile.user Subject: Re: Question about data structures Date: Sun, 22 Nov 2020 21:24:48 +0100 Message-ID: References: <3b07669d7286df2542796e309db101423bb3e147.camel@divoplade.fr> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="27703"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.10.0 To: divoplade , Guile User Original-X-From: guile-user-bounces+guile-user=m.gmane-mx.org@gnu.org Sun Nov 22 21:25:14 2020 Return-path: Envelope-to: guile-user@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kgvv7-00075F-IE for guile-user@m.gmane-mx.org; Sun, 22 Nov 2020 21:25:13 +0100 Original-Received: from localhost ([::1]:53934 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kgvv6-0000Vp-HS for guile-user@m.gmane-mx.org; Sun, 22 Nov 2020 15:25:12 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:44406) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kgvur-0000VW-Tk for guile-user@gnu.org; Sun, 22 Nov 2020 15:24:58 -0500 Original-Received: from mout01.posteo.de ([185.67.36.65]:56968) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kgvum-0002j8-8k for guile-user@gnu.org; Sun, 22 Nov 2020 15:24:56 -0500 Original-Received: from submission (posteo.de [89.146.220.130]) by mout01.posteo.de (Postfix) with ESMTPS id ADB0216005F for ; Sun, 22 Nov 2020 21:24:49 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=posteo.de; s=2017; t=1606076689; bh=tuiNtjS4MBCWs71LCnUWRDRV/E8u2aYxwtRVAvSavTM=; h=Subject:To:From:Date:From; b=hybCqsaDNz/tU41jWbDfYkINURdue9019O3pravws27KIydCvZOpRII5lUAyLiTRS Ouyt1bwguoCe2861IdE1YVVeMqOzKJkCpAvwTqIHrVj4bMPAHAcoNbSlij6fUXb8bd XRGNB3myFWSMgwWkJiDsh4Aw1q+bayvxI+cASnwVLYdRrjuObqbGVLQSdRRrTEiF3G 5yhfhzqlyFBcl2ZZfm33D26wl8PMlvX06WK1/1Ub5dKsP5EX0nD1GsYtljcGwhUBjh KyK/B/JE/L38os6ZcpsACKOA7w4lvF4qbgzHThwMdSpKI7RAIjpfJEP+PgI5w2xr4l B5OGernBv3PuQ== Original-Received: from customer (localhost [127.0.0.1]) by submission (posteo.de) with ESMTPSA id 4CfMG90vvdz6tmB; Sun, 22 Nov 2020 21:24:48 +0100 (CET) X-Tagtoolbar-Keys: D20201122212448422 In-Reply-To: <3b07669d7286df2542796e309db101423bb3e147.camel@divoplade.fr> Content-Language: en-US Received-SPF: pass client-ip=185.67.36.65; envelope-from=zelphirkaltstahl@posteo.de; helo=mout01.posteo.de X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, NICE_REPLY_A=-0.001, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_MSPIKE_H4=-0.01, RCVD_IN_MSPIKE_WL=-0.01, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: guile-user@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: General Guile related discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guile-user-bounces+guile-user=m.gmane-mx.org@gnu.org Original-Sender: "guile-user" Xref: news.gmane.io gmane.lisp.guile.user:17037 Archived-At: Hi divoplade! I know there is reverse and I think I did implement it before, when working through SICP exercises. Thanks for that implementation and input though! I think the point I wanted to make is rather to avoid `reverse` completely. If I had a vector, I could simply go by index backwards or forwards without adding any runtime complexity. But a vector is of defined length, not expandable like a list via cons, which means it might not be the best idea under some circumstances. Other circumstances make lists less ideal. If those circumstances appear together, then I probably should be using another data structure. Or pay the price in time complexity for some operations. I just read, that Python "lists" are actually implemented as https://en.wikipedia.org/wiki/Dynamic_array. So I guess a more specific but less generally useful question is: "What do I use in Guile, if I were using a dynamic array in Python?" I almost never find myself reversing a Python "list". Probably because it can be indexed in reverse order indices. Best regards, Zelphir On 11/22/20 8:45 PM, divoplade wrote: > Hello Zelphir! > > Le dimanche 22 novembre 2020 à 19:48 +0100, Zelphir Kaltstahl a écrit : >> However, when I use the list in >> reverse and ever need to output the lines in the list in their >> original >> order, I would first need to `reverse` the list again. > There is a "reverse" function; you could implement it yourself as a > tail-recursive function if you wanted (it's currently implemented in C, > so my guess is it's even more efficient). You don't need vectors for > that. > > (define (my-reverse-aux accumulation list) > (if (null? list) > accumulation > (my-reverse-aux (cons (car list) accumulation) (cdr list)))) > > (define (my-reverse list) > (my-reverse-aux '() list)) > > (my-reverse '(a b c d e f g h)) > -- repositories: https://notabug.org/ZelphirKaltstahl