scheme 代码片段

(1)
(quotient 10 2)
(quotient (+ 8 7) 5)
(+ (* 3
      (+ (* 2 4)
         (+ 3 5)))
   (+ (- 10 7)
      6))
(2)
(define pi 3.14)
(* pi 2)
(define (Abs x)
    (if (< x 0)
        (- x)
        x))
(Abs -3)
(3)
(define (square x) (* x x))
(define (average x y) (/ (+ x y) 2))
(average 2 3)
(4)
(load "demo.scm")
(5)
(define (plus4 x) (+ x 4))
(define plus4 (lambda (x) (+ x 4)))
((lambda (x y z) (+ x y (square z)))1 2 3)


(define (square x) (* x x))
(define sum-square
    (lambda (x y) (+ (square x) (square y)))
)
(sum-square 3 4)
(print "Hello, World!")
(6)
#lang racket
(define (square x) (* x x))

((lambda (x y z) (+ x y (square z))) 1 2 3)

(print "hello")

(7)
#lang racket
(define (fib n)
    (cond ((= n 0) 0)
        ((= n 1) 1)
        (else (+ (fib (- n 1)) (fib (- n 2))))
     )
)
(fib 35)

(8)
(begin (print 1) (print 2) 3 4 5)

(9)
(define x 9)
(cond ((> x 10) (begin (print "big")  (print "guy")))
    (else (begin (begin (print "small") (print "fry")))))

(10)
(if (> x 10) (begin 
             	(print 'big')
             	(print 'guy'))
              (begin 
                (print 'small')
               	(print 'fry')))
(11)
(define a 2)
(define b 3)
(define c (let ((a 3)
                (b (+ 2 2)))
                (sqrt (+ (* a a) (* b b)))))
c

(12)
(let ((a 3) (b 3)) (sum-square a b)) 

(13)
(define a (cons 1 (cons 2 (cons 3 (cons 4 null)))))
a

(14)
(cons 1 (cons 2 null))
(define x (cons 1 (cons 2 null)))
x
(car x)
(cdr x)
(cons 1 (cons 2 (cons 3 (cons 4 null))))
(15)
(define a 1)
(define b 2)
(list a b)
(16)
(list quotient 10 2)
(eval (list quotient 10 2))
(17)
(begin 
 (define (f x total)
     (if (< x 10)
         (f (+ x 2) (+ total (* x x)))
         total))
 	 (f 2 0))
(begin
 	(define (f x total)
        (if (< (* x x) 50)
            (f (+ x 1) (+ total x))
            total))
(f 1 0))))
(18)
(define (sum-while starting-x while-condition add-to-total update-x)
      (begin
      (define (f x total)
          (if while-condition
              	(f update-x (+ total, add-to-total))
              total
          )
       )
       (f starting-x 0)
     )
)
(eval (sum-while 2 (< x 10) (* x x) (+ x 2)))
(eval (sum-while 1 (< (* x x) 50) x (+ x 1)))

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

BoneInscri

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值