SICP lec1b: # Computing process

  • 2017-12-03
  • 39
  • 0

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

评论

还没有任何评论,你来说两句吧

正在获取,请稍候...
00:00/00:00