# Problem Set #4

### Objectives

During this activity, students should be able to:

• Modify the Lisp metacircular evaluator in order to extend its functionality.

This activity helps the student develop the following skills, values and attitudes: ability to analyze and synthesize, capacity for identifying and solving problems, and efficient use of computer systems.

## Activity Description

Individually or in pairs, modify the Lisp metacircular evaluator built in class in order to solve the following problems. All your code must be placed in a file called lisp.clj.

1. Add to the Lisp interpreter the dotimes special form, which has the following syntax:

$$\texttt{(dotimes}\texttt{ (}\mathit{var}\texttt{ }\mathit{count}\texttt{) } \mathit{body}\texttt{)}$$

where $$\mathit{var}$$ is a symbol, while $$\mathit{count}$$ and $$\mathit{body}$$ are expressions. This construct executes $$\mathit{body}$$ (which must perform some side effect operation, typically printing) once for each integer from 0 (inclusive) to $$\mathit{count}$$ (exclusive), binding the variable $$\mathit{var}$$ to the integer for the current iteration. This special form always returns nil.

Examples:

($eval '(dotimes (i (+ 2 2)) (println "Line" i)) {'println println, '+ +}) ($eval '(dotimes (x 10)
(pr x))
{'pr pr})


Output:

Line 0
Line 1
Line 2
Line 3

0123456789

2. Add to the Lisp interpreter the let special form, which has the following syntax:

$$\texttt{(let}\texttt{ (}\mathit{var}\texttt{ }\mathit{expr}\texttt{) } \mathit{body}\texttt{)}$$

where $$\mathit{var}$$ is a symbol, while $$\mathit{expr}$$ and $$\mathit{body}$$ are expressions. This construct evaluates and returns the result of $$\mathit{body}$$ using an extended environment where $$\mathit{var}$$ is bound with the result of evaluating $$\mathit{expr}$$. In other words, it's equivalent to:

$$\texttt{((lambda}\texttt{ (}\mathit{var}\texttt{) }\mathit{body}\texttt{) } \mathit{expr}\texttt{)}$$

Examples:

($eval '(let (x 6) (* 7 x)) {'* *}) => 42 ($eval '(let (x (* 2 5))
(let (y (+ 1 x))
(+ 1 (* y x))))
{'+ +
'* *})
=> 111


## Deliverables

The program source file must include at the top the authorsâ€™ personal information (name and student id) within comments. For example:

;----------------------------------------------------------
; Problem Set #4
; Date: March 22, 2019.
; Authors:
;          A01166611 Pepper Pots
;          A01160611 Anthony Stark
;----------------------------------------------------------

To deliver the lisp.clj file, please provide the following information:

Only one team member needs to upload the file.

Due date is Friday, March 22.

## Evaluation

This activity will be evaluated using the following criteria:

 -10 The program doesn't contain within comments the author's personal information. A docstring is missing in one or more functions. The program contains syntax errors. The program was plagiarized in whole or in part. Depending on the amount of exercises that were solved correctly.