Title: CS 1321
 1CS 1321
- Focus Lecture Wonders of Scheme 
- Spring 2003
2Outline
- Introduction and Whos Who 
- Whats hard about designing programs? 
- Why arent we learning language X? 
- Why Scheme is special 
3This recitation isnt really a conventional 
recitation
- One lecture a week 
- Required 
- Pop quizzes may occur 
- Focus on a critical aspect of programming, but a 
 little off the beaten path
- Example Today well talk about why Scheme is a 
 useful language for design
- Syllabus will be covered in main lecture 
- 2nd hour of recitation will be with TA 
- One goal of this recitation is to know you a bit 
 better
4Now, lets introduce ourselves
- Who I am 
- Ron Ferguson, Asst. Professor, College of 
 Computing
- Office hours Monday, 1-3 pm, CCB 162 
 (pied-a-terre in the Deans area of CCB)
- Email rwf_at_cc 
- Who you are (photos) 
- Need one volunteer
5Lets use some instant demographics to get to 
know the class a bit better
- Raise your hand if 
- Your major is 
- CS, EE, ME, AE, Psych  
- Youve written a computer program (longer than 10 
 lines).
- Pascal C 
- C Java 
- HTML XML 
- Others? 
- Have designed something? 
- Your own web page 
- Carpentry 
- Music 
- A play or skit 
- An engine or other mechanism 
- Which brings us to our next issue
6Outline
- Introduction and Whos Who 
- Whats hard about designing programs? 
- Why arent we learning language X? 
- Why Scheme is special 
7In design, finding a way to formulate your 
problem is half the battle
- Composer 
- The first few minutes are the hardestbefore I 
 find a theme to play with
- Architect 
- Initial theme, followed by a number of 
 elaborations
- Computer programmer 
- Describing the problem 
- Breaking it down into parts 
- Abstracting those parts in an effective way 
- Which brings us to why were using Scheme
8In 1321, the goal is to teach you how to 
problem-solve using computer programs
- Not about learning esoteric aspects of a 
 particular language
- You will learn the syntax of Scheme 
- Yet, our goal is not to teach you about Schemes 
 syntax as such
- Analogy Teaching someone tennis 
- Hitting a ball within the boundary is important 
- Goal, however, is to teach you how to interact 
 with the ball
- Learning how to serve  swing for the parking 
 lot!
- By analogy, Scheme will allow you to focus on the 
 truly difficult issues in programming
9Outline
- Introduction and Whos Who 
- Whats hard about designing programs? 
- Why arent we learning language X? 
- Why Scheme is special 
10Why arent we learning Language X?
- Where X  Java, C, Matlab, etc. 
- Language of choice changes frequently 
- 1980 FORTRAN, COBOL, Assembler 
- 1985 Pascal 
- 1990 C 
- 1995 C 
- 2000 Java 
- 2005 ??? 
- Other languages Perl, Smalltalk, Python, LISP, 
 Lingo, C
- Trend is toward more powerful languages with 
 better abstraction abilities
- Even more true for applied domains AutoCAD LISP, 
 Director Lingo, others
11Scheme  A Golden Oldie?
- Whats ironic about Scheme is thats its been 
 around awhile
- First specification in 1975 
- FYI Top hit in 1975 Love Will Keep Us Together 
 The Captain  Tennille
- Based on LISP, which goes back to the 50s 
- LISP is almost as old as FORTRAN 
- LISP is still in common use in AI applications, 
 along with complex data handling
- Orbitz and YahooStores both use LISP
12Scheme  Everything Old is New Again
- So why is Scheme important now? 
- Faster hardware 
- Better interpreters and compilers 
- People are more expensive, and MIPS and memory 
 are much, much cheaper.
- Save six person/months of development  30K 
- Code easier to maintain 
- Despite its age, LISP and Scheme introduced a 
 number of programming concepts that werent in
 common use until recently
- Automatic memory management (garbage collection) 
- Functional programming style 
- Nested symbolic descriptions of data (Hello, 
 XML!)
- Late binding (non-static types) 
- Let me say a little more about these special 
 features of Scheme
13Outline
- Introduction and Whos Who 
- Whats hard about designing programs? 
- Why arent we learning language X? 
- Why Scheme is special 
14Two classes of information included in a program
- Data Bookkeeping Keeping track of the size and 
 types of the information resources needed by the
 program
- Pretty mundane, but important 
- Algorithm design How those information resources 
 are processed to solve a problem
- Includes issues like computational complexity 
- Harder  key to good programming 
- Scheme lets us focus on the second class of 
 information.
15Managing memory
- Hello, World program. 
- Puts a single label on the screen at a particular 
 X,Y position
- Need three pieces of information 
- X coordinate of label 
- Y coordinate of label 
- Label text
16Allocating memory
Memory is then allocated for each of those 
items X position 1 byte Y position 1 byte 
 Label string 1 byte per character. In many 
languages, we must explicitly tell the system to 
allocate the memory, and then to release the 
memory when it is done. Bugs occur when this is 
not done properly - If memory is not 
released, then the program may have a memory 
leak. 
 17How Scheme handles memory management for you
- In Scheme, memory is allocated automatically as 
 data is created and used
- Allocates chunks of memory 
- Creates pointers to parts of that memory 
- Make sure that the pointers dont point to the 
 wrong things (e.g., pointer arithmetic)
- Let go of the memory chunks when youre done 
 (e.g., avoid memory leaks)
- Scheme handles releasing memory by keeping track 
 of which values are referenced
- When data is no longer referenced, it is released 
 automatically (garbage collection).
- Garbage collection is much more reliable than 
 handling memory automatically, though it can also
 be slower
18How Scheme handles variable types for you
- In many languages, we have to explicitly decide 
 on that values will be stored in a variable
- Integer values are different from floating point 
 values are different from strings
- Integer position-x, position-y 
- String label 
- Scheme is much more flexible about handling types 
- Types are a characteristic of the data value 
 rather than the variable
- Handled via boxing of values (including type 
 information with the data)
- Result Variables can point at data of any type 
 at any time
- Of course, with this much rope, you can also hang 
 yourself
- Divide a string by another string 
- Still, much more flexible than other languages
19Schemes simplified syntax
- Most languages have a complex syntax 
- Lots of punctuation ,.,-gt,,,(),. 
- Most common error in my old Pascal class syntax 
 error
- But learning to program is not about learning how 
 to avoid syntax errors!
- Scheme  Parentheses uber alles 
- If its an expression, its delimited by 
 parentheses, period.
- The first item past the left paren is always the 
 operator, the rest is always the arguments.
20Schemes use of parentheses might be compared to 
HTML or XML
- In HTML, everything is controlled by matching 
 labels
- ltheadgt 
-  lttitlegtMy web sitelt/titlegt 
- ltheadgt 
- ltbodygt 
- Welcome to my web page! 
- lt/bodygt 
- This simple syntax makes HTML easy to learn, and 
 easy to extend
- Parsers for HTML (properly written) are also 
 easy.
- XML takes this lesson to heart 
-  ltLinkSet name"Working Pages"gt 
-  ltSubPage name"Audio" url"audio.htm"/gt 
-  ltSubPage name"Ariel" url"Service/Ariel20Ser
 vice20Log.htm"/gt
-  ltSubPage name"Clio" url"Service/Clio20Servi
 ce20Log.htm"/gt
-  ltSubPage name"Diversions" url"diversions.htm
 "/gt
-  lt/LinkSetgt 
- Parentheses in Scheme work just like this, except 
 that Scheme it is more succinct and more powerful.
21Translating XML or HTML to Scheme is easy!
- HTML to Scheme translation 
- lttaggt  lt/taggt ? (tag ) 
- Now, lets translate something 
- ltheadgt 
-  lttitlegtMy web sitelt/titlegt 
- ltheadgt 
- ltbodygt 
- Welcome to my web page! 
- lt/bodygt 
- In Scheme, we would write this as 
- (head (title My web site)) 
- (body Welcome to my web page!) 
- By the way, this is why Scheme and LISP are great 
 AI languages  its easy to write complex
 representations in them. Whats being done in XML
 now was done in LISP in the 60s!
22Outline
- Introduction and Whos Who 
- Whats hard about designing programs? 
- Why arent we learning language X? 
- Why Scheme is special 
23Summary
- Scheme is an oldie but goodie 
- Scheme lets you focus on algorithm design instead 
 of data bookkeeping
- Automatic memory management 
- Data types handled automatically (neednt be 
 pre-defined)
- Syntax is simple and extensible