diff options
author | EuAndreh <eu@euandre.org> | 2021-06-08 18:25:02 -0300 |
---|---|---|
committer | EuAndreh <eu@euandre.org> | 2021-06-08 18:27:26 -0300 |
commit | ffb853ee209581b03182c9daf3c90e19a639407d (patch) | |
tree | d35f6bc533d2bfe61d04a5b70922ad2322221642 /_pastebins/2021-06-08-debit-reading-session-sicp-solutions-pt-1.md | |
parent | _tils/2020-11-12-diy-bare-bones-ci-server-with-bash-and-nix.md: Fix link to e... (diff) | |
download | euandre.org-ffb853ee209581b03182c9daf3c90e19a639407d.tar.gz euandre.org-ffb853ee209581b03182c9daf3c90e19a639407d.tar.xz |
/home/andreh/dev/libre/dotfiles/scripts/pastebin.sh: Auto-add _pastebins/2021-06-08-debit-reading-session-sicp-solutions-pt1.md
Diffstat (limited to '')
-rw-r--r-- | _pastebins/2021-06-08-debit-reading-session-sicp-solutions-pt-1.md | 77 |
1 files changed, 77 insertions, 0 deletions
diff --git a/_pastebins/2021-06-08-debit-reading-session-sicp-solutions-pt-1.md b/_pastebins/2021-06-08-debit-reading-session-sicp-solutions-pt-1.md new file mode 100644 index 0000000..b97ef08 --- /dev/null +++ b/_pastebins/2021-06-08-debit-reading-session-sicp-solutions-pt-1.md @@ -0,0 +1,77 @@ +--- + +title: Debit Reading Session - SICP solutions pt.1 + +date: 2021-06-08 + +layout: post + +lang: en + +ref: debit-reading-session-sicp-solutions-pt-1 + +--- + +```scheme +;; 1.41 +(define (double f) + (lambda (x) + (f (f x)))) + + +:;; 1.42 +(define (compose f g) + (lambda (x) + (f (g x)))) + + +;;; 1.43 +(define (repeated f n) + (if (= 1 n) + identity + (comp (repeated f (dec n))))) + + +;;; 2.27 +(define (map-tree node-fn leaf-fn tree) + (cond + ((null? tree) tree) + ((not (pair? tree)) (leaf-fn tree)) + (else + (node-fn + (cons (map-tree node-fn leaf-fn (car tree)) + (map-tree node-fn leaf-fn (cdr tree))))))) + +(define (map-nodes f tree) + (map-tree f identity tree)) + +(define (deep-reverse x) + (map-nodes reverse x)) + + +;;; 2.28 +(define (flatten tree) + (define (rec acc t) + (cond + ((null? t) acc) + ((not (pair? t)) (cons t acc)) + (else + (rec (rec (cdr t) acc) + (car t))))) + (rec nil tree)) + + +;;; 2.30 +(define (square-tree tree) + (map-leaves square tree)) + + +;;; 2.31 +(define square-tree map-leaves) ; ha! + + +;;; 2.32 +TODO +``` + +FYI: I just typed those in, I didn't yet test them yet. |