From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Damien Mattei Newsgroups: gmane.lisp.guile.user Subject: Re: why I love scheme Date: Wed, 15 Dec 2021 22:12:42 +0100 Message-ID: References: <7faa8b38-4e28-9926-4842-9c0d005bae85@posteo.de> <98123b25-7995-ec8f-fc5a-30ff29efb9d6@posteo.de> Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="2873"; mail-complaints-to="usenet@ciao.gmane.io" Cc: Guile User Original-X-From: guile-user-bounces+guile-user=m.gmane-mx.org@gnu.org Wed Dec 15 22:29:05 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 1mxbph-0000Yg-2R for guile-user@m.gmane-mx.org; Wed, 15 Dec 2021 22:29:05 +0100 Original-Received: from localhost ([::1]:53096 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mxbpf-0004wp-Si for guile-user@m.gmane-mx.org; Wed, 15 Dec 2021 16:29:03 -0500 Original-Received: from eggs.gnu.org ([209.51.188.92]:42282) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mxba6-0000SM-IG for guile-user@gnu.org; Wed, 15 Dec 2021 16:12:58 -0500 Original-Received: from [2607:f8b0:4864:20::b2f] (port=38489 helo=mail-yb1-xb2f.google.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mxba3-0007Rh-Ma for guile-user@gnu.org; Wed, 15 Dec 2021 16:12:57 -0500 Original-Received: by mail-yb1-xb2f.google.com with SMTP id v64so58805203ybi.5 for ; Wed, 15 Dec 2021 13:12:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:cc; bh=mkw8iG9iywYNbgY3U1K1eBHEdTBrgI7EcsXjc3+bdy0=; b=TAi4rGGTeT+iqdo+xpkkT9WGEqzbOLx/zDJtN6kX23ckBTqZJHFxczy+Lb+XodGdR0 uZxerpRC0uCeCnb8rAO7rn0W4jSqJw+I+jjnaroMjweI/rHVCpME8nv/GofZG6RULYmn ts4ZcltACH3CIBTeMlijq2cjPmzIWbEFH7vPCaCwJMs1WvBU02m3e0WJZQBPjmnC3t9j v61FZQuqlSH0NKmOrKdh3mTFdpW+2TqIHmDJgEtkdojcW0fJLMzVUCaQi1X+7WCvBFi7 6F1qjXE5CdxGwKjpNW9xLXLq58Aqt2ha/RFihY0j1D75khxkZqwnss4LHRag+mGIs53X 0QTA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:cc; bh=mkw8iG9iywYNbgY3U1K1eBHEdTBrgI7EcsXjc3+bdy0=; b=6Wq7Ow2sV/8HeKqoxbZIUKq1k/yfbB3pDN/hrZd3otwCe5qStYy50rFmzIh6TTOPc2 JPSo45y+f+IGNcq4BXYJ5VfbCbVEEM06CAFfnwGtJGAE9SKGCd5Pxsh5wkwazACHanwO SRcyBGe7EfFO+LzpfqnQK9wOYqKfN5BBQsnC3ji0VaUh88d3S5PR2bF07NJb6lDj9i1g 6RTV9uub4x4DSalqYc5kWUqvQT21RnaLkcjccz7EXzHHQOCsYlkz9/sCN6tEbZAvZTm4 DUcIrQUGa4Wnc1YyJHzVHi7SFb3xjfc4870Hcaik955EXSVn/inJvuaCutSZieAA/wkj iCww== X-Gm-Message-State: AOAM532IXJJq62JCLOhPy12ZC0FIVmXTcVomj2jRrWfA/c05WjjkeNIt 9G8VlsjzbNYwIS4dikW8In667ve/NeJwuKl313rftX4OgKo= X-Google-Smtp-Source: ABdhPJxJHa02wsB4iwDT4qXXincffIVmAygSRuP/AEsqPTdQuhRIUnTaItlNzq8D4CZOOXnOtSRyJSt+w3tQu8QkRv4= X-Received: by 2002:a25:ccc7:: with SMTP id l190mr9284052ybf.466.1639602772883; Wed, 15 Dec 2021 13:12:52 -0800 (PST) In-Reply-To: <98123b25-7995-ec8f-fc5a-30ff29efb9d6@posteo.de> X-Host-Lookup-Failed: Reverse DNS lookup failed for 2607:f8b0:4864:20::b2f (failed) Received-SPF: pass client-ip=2607:f8b0:4864:20::b2f; envelope-from=damien.mattei@gmail.com; helo=mail-yb1-xb2f.google.com X-Spam_score_int: -2 X-Spam_score: -0.3 X-Spam_bar: / X-Spam_report: (-0.3 / 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, FREEMAIL_FROM=0.001, HTML_MESSAGE=0.001, MISSING_HEADERS=1.021, RCVD_IN_DNSWL_NONE=-0.0001, RDNS_NONE=0.793, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no 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:17857 Archived-At: hello Stefan, i have had two Scheme teacher before graduating and being teaching scheme too. One tell us that basically CPS is the same as recursivity. The other one said students to always give an example of the use of a Scheme function of our own unless it did not read and give a note to our work. ;-) Damien On Wed, Dec 15, 2021 at 9:32 PM Zelphir Kaltstahl < zelphirkaltstahl@posteo.de> wrote: > 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 < > zelphirkaltstahl@posteo.de > > > 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 > >