UA CSC 520 - Scheme (9 pages)

Previewing pages 1, 2, 3 of 9 page document View the full content.
View Full Document

Scheme



Previewing pages 1, 2, 3 of actual document.

View the full content.
View Full Document
View Full Document

Scheme

34 views


Pages:
9
School:
University of Arizona
Course:
Csc 520 - Principles of Programming Languages
Principles of Programming Languages Documents

Unformatted text preview:

CSc 520 Principles of Programming Languages 3 Scheme Introduction Christian Collberg Department of Computer Science University of Arizona collberg cs arizona edu Copyright c 2005 Christian Collberg April 22 2005 1 Background Scheme is based on LISP which was developed by John McCarthy in the mid 50s LISP stands for LISt Processing not Lots of Irritating Silly Parentheses Functions and data share the same representation S Expressions A basic LISP implementation needs six functions cons car cdr equal atom cond Scheme was developed by Sussman and Steele in 1975 2 S Expressions An S Expression is a balanced list of parentheses More formally an S expression is 1 a literal i e number boolean symbol character string or empty list 2 a list of s expressions Literals are sometimes called atoms 3 S Expressions Examples Legal 66 4 5 5 4 5 6 7 Illegal 5 4 5 1 4 S Expressions as Trees An S expression can be seen as a linear representation of tree structure 2 2 6 3 4 3 6 4 2 3 4 5 6 7 2 4 3 7 5 6 5 S Expressions as Function Calls A special case of an S expression is when the first element of a list is a function name Such an expression can be evaluated 4 5 9 add five to my argument 20 25 draw a circle 20 45 t 6 S Expressions as Functions As we will see function definitions are also S expressions define farenheit 2 celsius f f 32 5 9 So Scheme really only has one syntactic structure the S expression and that is used as a data structure to represent lists trees etc as function definitions and as function calls 7 Function Application In general a function application is written like this operator arg1 arg2 argn The evaluation proceeds as follows 2 1 Evaluate operator The result should be a function F 2 Evaluate arg1 arg2 argn to get val1 val2 valn 3 Apply F to val1 val2 valn 8 Function Application Examples 4 5 9 5 6 3 14 7 7 4 5 6 eval 4 is not a function t t 9 Atoms Numbers Scheme has Fractions 5 9 Integers 5435 Complex numbers 5 2i Inexact reals i3 14159265 5 4 9 5 4 3 23 5 9 4 6 1



View Full Document

Access the best Study Guides, Lecture Notes and Practice Exams

Loading Unlocking...
Login

Join to view Scheme and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Scheme and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?