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)
(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"))
(define mylist (list "yes" 2 3.5 add5))
(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.

The views and opinions expressed in this page are strictly those of the page author. The contents of this page have not been reviewed or approved by the University of Minnesota.