Class 3: Getting Started with Scheme
Held: Wednesday, 25 January 2017
We begin your exploration of the Scheme programming language and the environment in which you will be devleoping algorithms in Scheme.
Preliminaries
Overview
- Why use programming languages?
- Scheme history
- Scheme basics
- Using DrRacket
Related Pages
-
Reading: Beginning Scheme
-
Reading: The DrRacket Programming Environment
Updates
News / Etc.
- Please take a card and sit at the corresponding computer!
- I am no longer distributing labs in physical form. You should be
able to read the lab on the computer.
- If you need a physical copy, let me know, and I can make a few.
- The self checks in each reading are for your benefit. You should do them (and I may ask you at the start of class what you figured out), but you need not turn anything in.
- We will have a quiz on Friday (as we will every Friday). This
week’s topics include
- The parts of an algorithm.
- Very basic Scheme (things from today’s lab).
- Course policies.
- I added a “Book an appointment” link to the “Primary” menu on the course.
- You should be able to view the “live” version of each eboard by clicking on the “Source” link in the list of eboards. (I’m working on making this cleaner.)
- The CS department maintains a mailing list of events and opportunities (and other things of potential interest).
- Starting this week, I will be in 3813 from 9:00-9:50 a.m. every
Thursday to answer questions. I wouldn’t quite call it a review
session, but it serves that kind of purpose.
- Yes, I’ll still post an eboard.
- Starting next week, we will have mentor sessions on Wednesday and Thursday evenings from 8:00-9:00 p.m. Wednesdays will be more Q&A, Thursdays will include sample quizzes.
- We have tutors available Sunday through Thursday evening from 7-10 p.m. in Science 3813/15.
Upcoming Work
- Assignment 2. Due next Tuesday!
- Reading: Numbers in Scheme
- Reading: Symbolic values in Scheme
Extra credit (Academic/Artistic)
- Rosenfield MLK day talk TONIGHT at 7pm, JRC 101
- Thursday extras, Thursday, 4:15 p.m., Science 3821: Summer Research Opportunities in CS
- One of the Camille A Brown events
- Dialogue/Conversation: Arts & Activism. Friday January 27 4:15-5:15PM, BCA 152
- Master Class (Open to All): A Journey through Juba and Other Social Dances. Saturday January 28, 11-12:30PM, Bucksbaum Dance Studio
- Performance: Black Girl A Linguistics Play. Saturday January 28, 7:30PM Roberts Theatre.
Extra credit (Peer)
- Open practice for Ritalin Test Squad, 2-4 Saturday in the Wall.
- Swim meet next weekend.
Good things to do
- Still trying to come up with some beyond the extra credit activities.
Lab
- You will learn Scheme better by trying than by listening, so I’m just going to have you work on the lab.
- I hope to spend a few minutes at the end of class giving you a chance to reflect on your first real experiences with Scheme.
The need for formality
- Computer scientists often express their algorithms in programming
languages, languages designed by other computer scientists to
express algorithms.
- Most programming languages can also be “understood” by computers.
- More precisely, we can use a program to automatically translate programs written in these languages into instructions the computer can follows.
- In this class, you will express your algorithms in the programming language Scheme.
- In Scheme, as in most languages, you will explore the syntax (the structure of the things we write) and the semantics (what meaning we assign to the things we write).
- Some people wonder why we need artificial languages like Scheme, Pascal,
C, Java, Python, and the ilk, given that we should be able to write algorithms
in English.
- In part, it’s probably because the computer elite want to maintain their sense of superiority over the masses.
- In greater part, it’s because English and other “natural” languages
can be ambiguous. At the very least, they have many similar structures
that are interpreted very differently. Consider the classic pair of
phrases.
- Time flies like an arrow.
- Fruit flies like a banana.
- Remember: Computers are sentient and malicious.
- From the programmer’s perspective, it often seems that they’ll do their best to misinterpret whatever it is you write.
A short history of Scheme
- Scheme is a variant of Lisp (the List processing language).
- Lisp is one of the oldest high-level programming languages in
active use
- It’s from the late 1950’s.
- That is, it’s from about the time of the invention of Cobol and only a few years after the invention of Fortran.
- It predates C, C++, C#, Basic, and almost every other language used.
- John McCarthy (of MIT and then Stanford) designed Lisp to provide a
language for programming in artificial intelligence.
- At the time, many people believed that intelligence was grounded in symbolic processing.
- Lisp added many things to languages of the day:
- Symbolic values
- Dynamic lists as built-in data structures
- Automatic memory management for those built-in data structures
- Functions as values (we’ll return to this in a few weeks)
- In later reflection, McCarthy indicated that some of these things
were just luck. For example, the
lambdathat you’ll learn about soon was just a “hmmm … that sounds interesting, I’ll put it in” fluke. - Scheme was designed in the 1970’s as
a variant of Lisp more appropriate for teaching computer science
(and doing many other things; it’s more elegant).
- Scheme has a slightly clearer semantics than Lisp (and a formal semantics, which is important).
- Scheme adds some nifty features for advanced programmers.
- But, at least for 151, you’re doing Lisp-like programming.
- A variant of Scheme called Script-Fu was added to the Gimp in its early development, so it is tightly integrated with the Gimp.
- We’ve built a friendlier version of Script-Fu.
Scheme basics
- Scheme is generally used in an interactive environment:
You type syntactically valid expressions and Scheme returns
their values.
- Later this semester, we may explore how to use Scheme in different environments.
- Scheme’s syntax is fairly simple: Since almost everything in
Scheme involves the application of a function (a.k.a. operation, a.k.a.
procedure) to some arguments (a.k.a. parameters),
you write:
- an open parenthesis;
- the name of the function;
- a space;
- the arguments to the function (separated by spaces); and
- a close parenthesis.
- For example,
- If you remember this basic syntactic structure, you’ll rarely get syntactic errors from Scheme.
- And if you believe that claim, I have a bridge to sell you.
Some procedures you should know
+: Sum its parameters.*: Compute the product of its parameters.-: Subtract the second parameter from the first.(sqrt *val*): Compute the square root of val.(expt *v* *p*): Compute vp.(abs *v*): Compute the absolute value of v.(max *v1* *v2* ... *vn*): Determine the largest of the given values.(min *v1* *v2* ... *vn*): Determine the smallest of the given values.