MIT/GNU Scheme 第一日

;---------------------------最原始的-------------------------------

(+ 2 3 4)

;Value: 9

 

 

;---------------------------定義Emmbed--------------------

(define x 2)

 

(define mm (* x 3))

 

mm

;Value:6

 

 

;-----------------------幾種函數的定義---------------------

 

(define (sum a b)

            (+ a b))

 

(sum 1 2)

;Value:3

 

 

;------------- Cond 使用   --

(define (abs x)

            (cond ( (>  x  0)  x)

                      ( (<  x  0)  (- x))

                      (else 0)))

 

(abs -11)

;Value :11

 

;--------------- If 使用 ---  邏輯運算使用, and or  not -------------

(define (summ a b c)

            (cond ((and (> a b) (> c b)) (+ a c))

                      ((and (> a c) (> b c)) (+ a b))

                      (else (+ b c))))

(summ 1 2 3)

;Value:5

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章