Scheme

symbols

booleans

t true

f false

strings

‘hello world!

numbers

no need to say

calculations

(+ 1 2) 3 (the same: +-*/<>=)

(modulo 35 4) 3

logic

  1. (if [if-false])

Scheme:

1
2
3
(if (> x 3)
1
2)

python:

1
2
3
4
if x > 3:
1
else:
2
  1. cond
1
2
3
4
(cond
((> x 0) 'positive)
((< x 0) 'negative)
(else 'zero))
  1. and & or

and (and x1 x2 …)

or (or x1 x2 …)

symbols

booleans

t true

f false

strings

‘hello world!

numbers

no need to say

calculations

(+ 1 2) 3 (the same: +-*/<>=)

(modulo 35 4) 3

logic

  1. (if [if-false])

Scheme:

  1. begin: bring few expressions together
1
2
3
(cond ((> x 10) (begin (print 'big)   (print 'guy))) 
(else
(begin (print 'small) (print 'fry)))

defination

parameter:

  1. (define )

(define x 2)

functions(precedure in Scheme):

(define ( ) )

(define (add_four x) x+4)

  1. (lambda () )

  2. (temporate binding) let() expression

(define c (let (a 3) (b (+ 2 2)))(sqrt (+ (a a) ( b b))))

• cons: Two-argument procedure that creates a linked list

• car: Procedure that returns the first element of a list

• cdr: Procedure that returns the rest of a list

• nil: The empty list

list: join the lists/elements together

1
2
3
4
5
6
7
8
9
10
11
>(cons 1 (cons 2 nil))
(1 2)
> (define x (cons 1 (cons 2 nil))
> x
(1 2)
> (car x)
1
> (cdr x)
(2)
> (cons 1 (cons 2 (cons 3 (cons 4 nil))))
(1 2 3 4)

quotation marks

quotations (‘a)

cons(1, a) error!

cons(1, ‘a) (1, a)

quasiquotations (`a)

‘(a ,(+ b 1)) => (a (unquote (+ b 1))

`(a ,(+ b 1)) => (a 5)

for generating scheme programs

unquote (,a)

programs are languages

scheme sentences are lists

scm> (list ‘quotient 10 2)

(quotient 10 2)

scm> (eval (list ‘quotient 10 2))

5

for example:to generate while statement for scheme

python:

1
2
3
4
5
 x = 2 
total = 0
while x < 10:
total = total + x * x
x = x + 2

scheme:

1
2
3
4
5
6
(begin 
(define (f x total)
(if (< x 10)
(f (+ x 2) (+ total (* x x)))
total))
)