Sign in using Google or Yahoo! id.  

Scheme Language Tutorial

 Comments Share:   Twitter   Reddit   HackerNews   Facebook 

Installing scheme in Ubuntu:

$ sudo apt-get install mit-scheme

Starting scheme:

$ scheme

Notes

  • Extension of scheme files: .scm
  • Comments in scheme start with ;
  • Wikipedia entry

Lecture I

http://www.youtube.com/watch?v=zmYqShvVDh4

;; The first expression inside () is the function name:
(+ 1 2 3 4 5) ; + is the function name
(+ (+ 1 2) (+ 3 4)) ; parameters can also be expressions

;; Define a value:
(define pi 3.14)
(+ 5 pi)

;; Define function:
(define (square x)(* x x))
(square 5)

Lecture II

http://www.youtube.com/watch?v=HFxGVf3KAto

(define (opposite w)
  (cond
    ((equal? w 'like) 'hate)
    ((equal? w 'hate) 'like)
    ((equal? w 'wonderful) 'terrible)
    ((equal? w 'terrible) 'wonderful)
    ((equal? w 'great) 'awful)
    ((equal? w 'awful) 'great)
    ((equal? w 'terrific) 'yucky)
    ((equal? w 'yucky) 'terrific)
    (else w)
  )
)
Posted on March 16, 2010 09:06 AM by Subhash Chandran
programming scheme
blog comments powered by Disqus