From: Nala Ginrut <nalaginrut@gmail.com>
To: Stefan Israelsson Tampe <stefan.itampe@gmail.com>
Cc: Guile User <guile-user@gnu.org>
Subject: Re: why I love scheme
Date: Wed, 15 Dec 2021 09:21:47 +0800 [thread overview]
Message-ID: <CAPjoZodyyLLa_7up9RChbtWfzj44=Ojyz6h=_z3tP_i2TkPjwg@mail.gmail.com> (raw)
In-Reply-To: <CAGua6m1DJoVxROD2R3QJmezZCOYoQH0jaS_W+O1Ac0jL1SCu+Q@mail.gmail.com>
I see your point.
Yes, continuation (CPS) is pretty cool to replace the hidden stack magic
for recursive algorithms. :-)
Best regards.
On Wed, Dec 15, 2021, 07:45 Stefan Israelsson Tampe <stefan.itampe@gmail.com>
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))))
>
next prev parent reply other threads:[~2021-12-15 1:21 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-12-14 23:44 why I love scheme Stefan Israelsson Tampe
2021-12-15 1:21 ` Nala Ginrut [this message]
2021-12-15 9:38 ` Zelphir Kaltstahl
[not found] ` <CAGua6m2cwQShFHSwoEqqF5HiSewGU1cDJyBsZvmicVT46N=pOA@mail.gmail.com>
2021-12-15 20:30 ` Zelphir Kaltstahl
2021-12-15 21:12 ` Damien Mattei
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/guile/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='CAPjoZodyyLLa_7up9RChbtWfzj44=Ojyz6h=_z3tP_i2TkPjwg@mail.gmail.com' \
--to=nalaginrut@gmail.com \
--cc=guile-user@gnu.org \
--cc=stefan.itampe@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).