CS 2135: Programming Language Concepts
Eval and Curly Data Definition FAQ


This page tries to provide answer to questions that have come up during the interpreter segment of the course.

General Questions


Creating the Curly Data Definition and Eval

Let's look at how to derive a data definition for Curly. We'll start with a simple Curly program:

  {define f {proc {y} {return y + 7}}}
  {f {7 * 2}}
Our data definition needs a structure to model each construct in this program. What constructs are there?

Keeping definitions separate from other expressions (programs we can run), this gives rise to the following two data definitions (with their define structs):

	An expr is one of
	  - number
	  - (make-var symbol)
	  - (make-proc symbol expr)
	  - (make-plus expr expr)
	  - (make-mult expr expr)
	  - (make-apply expr expr)

	A definition is a (make-def symbol expr)

        (define-struct var (name))
	(define-struct proc (param body))
	(define-struct plus (left right))
	(define-struct mult (left right))
	(define-struct apply (func arg))
	(define-struct def (name exp))

We now have a way to turn Curly programs into data so that we can manipulate the programs. Here are two examples:

  1.   {define f {proc {y} {return y + 7}}}
      {f {7 * 2}}
    
      (make-def f (make-proc 'y (make-plus (make-var 'y) 7)))
      (make-apply (make-var 'f) (make-mult 7 2))
    
  2.   {f (3 + {g {(2 + 8) * 5}})}
    
      (make-apply (make-var 'f)
                  (make-plus 3 (make-apply (make-var 'g)
                                           (make-mult (make-plus 2 8) 5))))
    

Now, we're in a position to write eval, which takes an expr (representing a Curly program) and returns the result we would get from running that program. See the code for eval as of class on Friday, Sept 21.


Questions about the Curly Data Definition and Eval

These answers refer to the Curly data definition and the code for eval.


This page maintained by Kathi Fisler
Department of Computer Science Worcester Polytechnic Institute