Help us understand the problem. What is going on with this article?

SICP読書女子会#20 2.2.2

More than 3 years have passed since last update.

オンラインSICP読書女子会 #20 (2.2.2(3)) - connpass
SICP/2.2.2.scm at master · cocodrips/SICP

(display "==========Scele tree===========")
(newline)
(define (scale-tree tree factor)
    (cond 
        ((null? tree) ())
        ((not (pair? tree)) (* tree factor))
        (else (cons (scale-tree (car tree) factor)
                    (scale-tree (cdr tree) factor))))
)

(display (scale-tree (list 1 (list 2) 3) 10))
(newline)
(define (scale-tree tree factor)
    (map (lambda (sub-tree)
        (if (pair? sub-tree)
            (scale-tree sub-tree factor)
            (* sub-tree factor)))
    tree)
)

Ex 2.30

;; ex 2.30
(display "==========Ex 2.30===========")
(newline)

;; 普通に
(define (square-tree tree)
    (cond 
        ((null? tree) ())
        ((not (pair? tree)) (* tree tree))
        (else (cons (square-tree (car tree)) (square-tree (cdr tree)))))
)

(display (square-tree (list 1 (list 2) 3)))
(newline)
;(1 (4) 9)

;; map
(define (square-tree tree)
    (map (lambda (sub-tree)
        (if (pair? sub-tree)
            (square-tree sub-tree)
            (* sub-tree sub-tree)))
    tree)
)
(display (square-tree (list 1 (list 2) 3)))
(newline)
;(1 (4) 9)

Ex 2.31

(display "==========Ex 2.31===========")
(newline)
(define (tree-map tree f)
    (map (lambda (sub-tree)
        (if (pair? sub-tree)
            (tree-map sub-tree f)
            (f sub-tree)))
    tree)
)
(display (tree-map (list 1 (list 5) 7) (lambda (x) (* x x))))
(newline)
;(1 (25) 49)

Ex 2.32

(display "==========Ex 2.32===========")
(newline)
(define (subsets s)
    (if (null? s)
        (list ())
        (let 
            ((rest (subsets (cdr s))))
            (append rest (map (lambda (x) (cons x (car s))) rest)))))
(display (subsets (list 1 4 7)))
(newline)


;(1) -> () (1)
;(1 2 3)         : ()
;        (2 3)   : () (1)
;        (3)     : () (1) (2) (1 2)
;        ()      : () (1) (2) (1 2) (3) (1 3) (2 3) (1 2 3)
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ユーザーは見つかりませんでした