


Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Solutions to the first lab of cs 3721: programming languages, focusing on the scheme language using drscheme. It covers interacting with the environment, creating atoms, building lists, using scheme syntax, declaring variables, and manipulating lists using cons, car, and cdr. Students will learn how to enter and save code, understand scheme's prefix notation, and work with variables and lists.
Typology: Lab Reports
1 / 4
This page cannot be seen from the preview
Don't miss anything!



CS 3721: Programming Languages Lab Lab #01 Solutions: Basic Scheme: learn a new language.
First, start the DrScheme programming environment. You can download various versions of DrScheme from http://www.drscheme.org or use the environment installed on the depart- ment Linux machines (by running \drscheme"). The web site, http://www.drscheme.org, has comprehensive documentation both about DrScheme and about the Scheme language itself. Various reference material for Scheme and Dr. Scheme can be found at http://download.plt-scheme.org/doc/; the Revised^5 Report on the Algorithmic Language Scheme is the ocial de nition of Scheme.
After the DrScheme environment starts, it will open a window with two panels: the top panel (called the de nition window) is for entering programs and saving commands to les; the bottom interactive window is for experimenting with Scheme commands without saving them. (Your commands in the interactive window can use de nitions in the de nition window.) You should periodically save your code in the de nition window into a le so that your work is not lost.
Dr. Scheme implements several variations of the Scheme language. For the purpose of our class, you should use the language level, \Teaching Languages: Intermediate Student with lambda." (You can choose the language level when you rst start \drscheme" or by clicking menu item \language:choose language").
Goals of this lab:
Interact with, write and debug programs in Dr. Scheme; Understand, read, and write simple expressions in Lisp/Scheme's pre x notation; Use the operator, de ne, to give symbolic names to expressions; Write numeric expressions using basic operators (e.g., +, -, /, sqrt, and =); Understand Lisp/Scheme lists and be able to use the cons, car, cdr, null?, and pair? operators.
You can work on the questions in small groups of 1-3 individuals each. However, you have to write up your solution on your own. Also, you should list the names of each individual in your group.
Due date: January 29, 3:30pm. At the beginning of the next recitation.
In this lab, we start with the most primitive concepts in Scheme.
5
for symbols:
'giants (quote @xy) 'a
'() ; empty list (quote ()) ; empty list '(a cs3721 3) ; a simple list of atoms (quote (a cs3721 3)) ; a simple list of atoms '(1 (a b) x (3 (z y) 4) c) ; nested list '(1 (a b)) ; nested list
p 2 + 7 3) ^ (5 > 3). Solution: Scheme expression for 1903 + 249 7 :8 :
(+ 1903 (/ 249 7.8))
Scheme expression for (
p 2 + 7 3) ^ (5 > 3) :
(and (<= (sqrt (+ 2 7)) 3) (> 5 3)) true
test operators are null? and pair?. null? tests whether the given list is empty or not. pair? tests whether the given list is a non-empty list or not. First, apply these predicates on an empty list. Then, apply them on the lists list1 and list2 that you built in question 5. Write down your Scheme expressions. Solution:
(null? '()) true (pair? '()) false (null? list1) false (pair? list1) true (null? list2) false (pair? list2) true