Introduction to Scheme examples for CSci 4651

September 3, in class


(define first car)
(define rest cdr)
(define null '())
(define empty? null?)
(define x 5)
x
(define y 3)
(+ x y)
(+ 1 2 x)
;(define x 2)
(define (add5 x) (+ x 5))
(add5 1)
(add5 x)
(number? x)
(string? x)
(define (printNumber x)
 (if (number? x) "yes" 2))
(printNumber "yes")
;(+ 1 "yes")
(define colors (list "blue" "red" "yellow"))
colors
(define mylist (list "yes" 2 3.5 add5))
mylist
(first colors)
(rest colors)
(car colors)
(cdr colors)
(cadr colors)
(cdddr colors)
(append colors (list 1 2 5))
(length colors)
(empty? colors)
(empty? (cdddr colors))
(null? colors)
(equal? null (cdddr colors))
(equal? 3 "3")
(map string-length colors)
;(define (duplicate str) (string-append str str))
(map (lambda (str) (string-append str str)) colors)
(define duplicate (lambda (str) (string-append str str)))
(map duplicate colors)
(cons "red" null)
(cons "blue" (cons "red" null))
(cons 1 2)
(caddar (cons (list 1 2 3) (list 4 5)))

CSci 4651 home page.