SICP lec1b: # Computing process

来源:互联网 发布:打车软件补贴方案 编辑:程序博客网 时间:2024/05/16 11:06

Computing process

心智

kinds of expressions

number
symbols


lambda
definations
conditionals


combinations


condition

if

(define (+ x u)
(if (= x 0)
y
(+ (-1 x) (1 y))
)
)

Fibonacci

(define (fib n)    (if (< n 2)        n        (+  (fib (- n 1))            (fib (- n 1))        )    ))

tips: 1+ function means add args 1 and return


Hanoi Tower

(define (dohanoi n to from using)  (if (> n 0)      (begin        (dohanoi (- n 1) using from to)        (display "move ")        (display from)        (display " --> ")        (display to)        (newline)        (dohanoi (- n 1) to using from)        #t)      #f))(define (hanoi n)    (dohanoi n 3 1 2))
原创粉丝点击