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: why I love scheme Date: Wed, 15 Dec 2021 20:30:46 +0000 Message-ID: <98123b25-7995-ec8f-fc5a-30ff29efb9d6@posteo.de> References: <7faa8b38-4e28-9926-4842-9c0d005bae85@posteo.de> 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="1217"; mail-complaints-to="usenet@ciao.gmane.io" Cc: Guile User To: Stefan Israelsson Tampe Original-X-From: guile-user-bounces+guile-user=m.gmane-mx.org@gnu.org Wed Dec 15 21:32:21 2021 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 1mxawn-00005g-O5 for guile-user@m.gmane-mx.org; Wed, 15 Dec 2021 21:32:21 +0100 Original-Received: from localhost ([::1]:46336 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mxawm-0008Jf-Oi for guile-user@m.gmane-mx.org; Wed, 15 Dec 2021 15:32:20 -0500 Original-Received: from eggs.gnu.org ([209.51.188.92]:32976) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mxavP-000598-9D for guile-user@gnu.org; Wed, 15 Dec 2021 15:30:55 -0500 Original-Received: from mout01.posteo.de ([185.67.36.65]:45965) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mxavK-00050w-CS for guile-user@gnu.org; Wed, 15 Dec 2021 15:30:53 -0500 Original-Received: from submission (posteo.de [89.146.220.130]) by mout01.posteo.de (Postfix) with ESMTPS id 5271224002A for ; Wed, 15 Dec 2021 21:30:48 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=posteo.de; s=2017; t=1639600248; bh=VpVoRT6intWJpRcQaWE/o+lM11tQ+HCMPoOQvWRXRfY=; h=Subject:To:From:Cc:Date:From; b=cSAXX+jzHxAPp4dGt8RH6G5VDTXdG4BWGBpeeKBQIp80w1QlwYIkP/pDdxVsJGdMJ zXO+XYz3TNyJlaKkssKFio4nmdr4LWxAg4oj2IchmRvZw4tIJ1E0PFUclOFNRPmJCJ 7QiQfuGLvt3vgPbHHk4Iq5Ib+x7QsmXMd9uko89OznqLkkdNuYhjAwk1P/+9MyX3Ee 6BefqJkcp2cMPA/N0ouKr2f6j7kCD+Bk+c5u4rdp1PBKNJhxJKVmzRaaJsKrs22cOq nwpZatc4HR9Ci1KJ5ZhLfNFesC8jeW1TCmF+G7Mg/i7QvnKEzUrgRgMdNHbThuJg9y IGG7tSY9h8BUA== Original-Received: from customer (localhost [127.0.0.1]) by submission (posteo.de) with ESMTPSA id 4JDn1z4BRMz9rxK; Wed, 15 Dec 2021 21:30:47 +0100 (CET) In-Reply-To: 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, HTML_MESSAGE=0.001, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-Content-Filtered-By: Mailman/MimeDel 2.1.29 X-BeenThere: guile-user@gnu.org X-Mailman-Version: 2.1.29 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:17856 Archived-At: I did not know, that lambdas are allocated on the heap. I have a few questions now: How does this affect using fibers? (And how do fibers work better in that case?) The unrolling you mentioned. Would same not be possible for the naive-but-not-tail-recursive version? Is the idea, that the continuation tail recursive version does work better, because the compiler is somehow able to optimize it better? If so, why? I am asking, because I once had the same kind of problem and then read, that instead of growing stack levels, I am growing the continuation, so not winning anything. But perhaps that was wrong and I should have gone for the continuation solution. I would like to be able to make an educated decision when next meeting such a problem. Best regards, Zelphir On 12/15/21 1:59 PM, Stefan Israelsson Tampe wrote: > I believe that the lambda closures will be allocated from the heap and hence > this procedure will > be perfect if you are using fibers.. Also the compiler can do magic if it > want's and unroll  > and untangle a few iterations, so it can be very fast as well.My point is that > the named let > is such a nice  looping construct (try to do this with a for loop in java). I > use it all the time > and only sometimes I need to move to even more advanced constructs like letrec.  > > On Wed, Dec 15, 2021 at 10:38 AM Zelphir Kaltstahl > wrote: > > Hello Stefan! > > This translates a recursive tree function into a tail recursive function. > However, in this case, I am not sure it is really worth doing, in > comparison to > the naive (+ first-branch other-branch) solution. The reason is, that > instead of > a call stack for multiple branches, you are only moving that stuff into a > longer > and longer continuation, which will be on the stack in each recursive call. > > However, I think you or other people on the list probably know more about this > than I do and about how the approaches compare in terms of memory and time. > Maybe the stack frames are more in size than the memory consumed by the > overhead > of the continuation, or the other way around. > > Regards, > Zelphir > > On 12/15/21 12:44 AM, Stefan Israelsson Tampe wrote: > > Maybe you think the below program is trivial, but I adore named let's so > > much that I just cannot fathom that when people go functional they totally > > miss this beauty > > > > > > (define (count tree) > > > > ;; s = total sum up to now > > > > ;; t = tree of the type (car = child . cdr = siblings) > > > > ;; cont is the continuation, (cont 10) will continue > > > > ;; the calculation with the sum=10 see how we initiate > > > > ;; with a continuation that evaluates returns it's argument > > > > > > (let loop ((s 0) (t tree) (cont (lambda (s) s))) > > > > (if (pair? t) > > > > (loop s (car t) (lambda (s) (loop s (cdr t) cont))) > > > > (cont (if (number? t) t 0)))) > > -- > repositories: https://notabug.org/ZelphirKaltstahl > > -- repositories: https://notabug.org/ZelphirKaltstahl