[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
why I love scheme
From: |
Stefan Israelsson Tampe |
Subject: |
why I love scheme |
Date: |
Wed, 15 Dec 2021 00:44:34 +0100 |
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))))
- why I love scheme,
Stefan Israelsson Tampe <=