unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
* why I love scheme
@ 2021-12-14 23:44 Stefan Israelsson Tampe
  2021-12-15  1:21 ` Nala Ginrut
  2021-12-15  9:38 ` Zelphir Kaltstahl
  0 siblings, 2 replies; 5+ messages in thread
From: Stefan Israelsson Tampe @ 2021-12-14 23:44 UTC (permalink / raw)
  To: Guile User

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))))


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2021-12-15 21:12 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-12-14 23:44 why I love scheme Stefan Israelsson Tampe
2021-12-15  1:21 ` Nala Ginrut
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

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).