CS 291 University of Puget Sound Spring, 2020
 
Programming Language Paradigms:
Explorations with Functional Problem Solving (supported by Scheme/Haskell)
and Declarative Prblem Solving (supported by Prolog)
 

Getting Started

Abstract

This reading provides a brief introduction to the history of the Scheme programming language and a few basics in running Chez Scheme, once it is installed. The lab also Scheme's read-eval-print loop and suggests some simple elements of Scheme.

More specifically, this lab discusses:


Notes on the History of Scheme

LISP (an acronym for LISt Processing) was invented in the late 1950's and early 1960's at M.I.T. by John McCarthy. LISP is based in part on the Lambda Calculus, a mathematical formalism developed by Alonzo Church (1903-1995).

LISP is the second-oldest language still in widespread use (the oldest is FORTRAN). Two dialects of LISP are widely used today: Scheme and Common LISP. Scheme is a small, uniform dialect that is good for teaching because of its simplicity. Common LISP is a large, "industrial-strength" dialect that is standardized and is available in several commercial versions. For most of this course, we will use an implementation of Scheme called Chez Scheme .

Most programming languages require learning the syntax of many different kinds of statements. In contrast, Scheme (and LISP) syntax is simple and uniform. Much of the work in learning Scheme is learning the names and effects of the system functions that form the core of the language. This component of CS 291 presents the system functions and covers other functions that are present in Common LISP.

Historically, LISP has been used especially for work in artificial intelligence and scripting applications. Today, LISP is used in a wide range of applications, including the GNOME window system and the the emacs editor.

Running Scheme with Chez Scheme

Several Scheme programming environments are widely available for a range of computers, including Linux, Mac OS X and Windows platforms. For this course, we will use a simple programming environment, called Chez Scheme. Many of the fundamental ideas of computer science are best learned by reading, writing, and executing small computer programs that illustrate them; and Chez Scheme is particularly helpful in making this type of programming interaction easy.

To utilize Scheme, you will need to install scheme and work within a terminal window.

Once installed as described in the installation instructions, Chez Scheme can be started by opening a terminal window and entering the command "scheme".

Chez Scheme language options

Chez Scheme can handle Standard Scheme, as well as several extensions. In order to be consistent with various Scheme environments, we'll focus on Standard Scheme, as various extensions may only work in one Scheme implementation or another.

Exiting from Chez Scheme

When you finished running Scheme, simply type (exit) in the terminal window.


Working within Scheme

  1. We will begin our processing in Scheme by typing expressions directly into the terminal window that is running Chez Scheme. After each expression is entered, Scheme

    This read-eval-print cycle forms the basis for all processing within Scheme.

    For example, if we type (sqrt 1024) into Scheme, the environment identifies sqrt as an operation to be applied to the number 1024. The computer then evaluates this expression, and concludes by printing the number 32 at the end.

  2. Numbers are expressions, whose value or meaning is the number itself. Scheme recognizes several types of numbers, including the following:

  3. Numeric Procedures: As illustrated above, in Scheme we apply operations to data using a prefix notation with parentheses. For example, the function f(x) would be written (f x). Some common numeric operations follow.

        (+ 27 3.1415926535)
        (- 27 3)
        (/ 17 2)
        (/ 17 -2)
        (* 17 2.0)
        (sqrt 4)
        (sin 0.5)
        (sqrt -2)
        (+ (* 3 2) (/ 8 4))
    

    Do any of your results from these experiments suggest other types of numbers that are available within Scheme (beyond integers, rational numbers, and floating-point numbers)? Explain briefly.

  4. Symbols are Scheme's analog of words; symbols are sequences of characters, such as

        TwoBeOrNot2Be
        This-is-a-symbol.
    

    In Scheme, symbols may act as variable names, but they do not have a value until we give them one.

  5. Binding: We may give a [global] symbol a value using a define operation. For example, we might give the symbol pi the value 3.141592 as follows:

         (define pi 3.141592)
      
    1. Now enter pi into Scheme and determine what happens.
    2. Check if work with symbols within Chez Scheme is case sensitive. What happens if you type Pi or PI.
  6. Check whether Scheme allows you to redefine the value of a symbol. For example, the 1897 Indiana House came close to declaring that the value of pi is about 3.2:

         (define pi 3.2)
    

    Now what happens if you type the symbol pi?

  7. Determine what happens if you make a typographical error. For example, try misspelling define or leaving out a left or right parentheses. In each case, make a note describing what happens.

Similarly, we can give the symbol radical-2 the value of the square root of two as follows:

     (define radical-2 (sqrt 2))

When using define, the symbol is given the current value of the expression that follows.

  1. Binding: Consider the following sequence of definitions:

       (define a 4)
       (define b 5)
       (define c 1)
       (define discriminant 
             (- (* b b) (* 4 (* a c))))
       (define root1
             (/ (+ (- b) (sqrt discriminant))
                (* 2 a)))
       (define root2
             (/ (- (- b) (sqrt discriminant))
                (* 2 a)))
    

    Determine the values for a, b, c, discriminant, root1, and root2 .

  2. Continue the previous problem by changing the values of a, b, and c. Are the values of discriminant, root1 and root2 changed immediately, or do these symbols have their earlier values?


created 29 December 1996 by John David Stone
revised 18 January 2009 by Henry M. Walkere
revised November-December 2019 by Henry M. Walker
Valid HTML 4.01! Valid CSS!
For more information, please contact Henry M. Walker at walker@cs.grinnell.edu.