Skip to content

Latest commit

 

History

History
250 lines (207 loc) · 2.06 KB

README.md

File metadata and controls

250 lines (207 loc) · 2.06 KB

compound procedures

> (define (sum x y) (+ x y))
ok
> (sum 10 20)
30
> ((lambda (x) x) 1)
1
> sum
#<procedure>
> (define c ((lambda (x) (lambda () x)) 3))
ok
> (c)
3

primitive procedures

  • null?
> (null? "a")
#f
> (null? 1)
#f
> (null? '())
#t
  • boolean?
> (boolean? 1)
#f
> (boolean? #f)
#t
  • symbol?
> (symbol? 'a)                   
#t
> (symbol? "a")
#f
  • integer?
> (integer? 10)
#t
> (integer? "10")
#f
> (integer? '10)
#t
  • char?
> (char? #\a)
#t
> (char? 'a)
#f
  • string?
> (string? "abc")
#t
> (string? 'abc)
#f
  • pair?
> (define c (cons 1 2))
ok
> (pair? c)
#t
  • procedure?
> (procedure? +)
#t
> (procedure? procedure?)
#t
  • number->string
  • string->number
> (number->string 10)
"10"
> (number->string 123456789)
"123456789"
> (string->number "123456789")
123456789
> (string->number "0123")
123
  • symbol->string
  • string->symbol
> (symbol->string 'abc)
"abc"
> (string->symbol "abc")
abc
  • char->integer
  • integer->char
> (char->integer #\a)
97
> (integer->char 97)
#\a
  • +
  • -
  • *
> (+ 1 2 3 4 5)
15
> (- 10 4 3)
3
> (* 1 2 3 4)
24
  • quotient
  • remainder
> (quotient 10 3)
3
> (remainder 10 3)
1
  • =
  • <
  • >
> (= 10 10)
#t
> (> 20 10)
#t
> (< 3 5)
#t
  • cons
  • car
  • cdr
  • set-car!
  • set-cdr!
> (define c (cons 10 20))
ok
> (car c)
10
> (cdr c)
20
> (set-car! c 100)
ok
> (set-cdr! c 200)
ok
> c
(100 . 200)
> 
  • list
> (list 1 2 3)
(1 2 3)
  • eq?
> (define o1 10)
ok
> (define o2 10)
ok
> (eq? o1 o2)
#t
  • begin
> (begin 1 2)
2
  • cond
> (cond (#f 'false) (else 'true))
true
  • let
> (let ((x (+ 1 1))
        (y (- 5 2)))
       (+ x y))
5
  • and
  • or
> (and 1 2 #f 3)
#f
>  (or #f #f 3 #f)
#t
  • apply
> (apply + '(1 2 3))
6
  • eval
> (define env (environment))
ok
> (eval '(define a 250) env)
ok
> (eval 'a env)
250