6.8

Assignment 11

home work!

Programming Language BSL+

Due Date Thurs 2/23 at 11:59pm

Possible Points 20

Purpose To begin thinking about abstraction.

Graded Exercises

Every new piece of data requires the four steps of the design recipe for new data.

Every new function requires the four steps of the design recipe for functions.

; An SP (simple program) is one of:
; - Number
; - (list 'add1 SP)
; - (list 'sub1 SP)
; - (list '-    SP)
; and represents a simple program with adding one, subtracting one, or negating a number

Those last three lines look awfully similar. As we saw in class, when things are incredibly similar, it is best to abstract them. So, instead of the data definition used above, we will use the one below:

; An SP (simple program) is one of:
; - Number
; - (list UnOp SP)
; and represents a simple program with unary operations on numbers
 
(define SP-0 0)
(define SP-BIG '(add1 (sub1 (- (add1 (add1 3))))))
 
; A UnOp (unary operation) is one of:
; - 'add1
; - 'sub1
; - '-
; and represents adding one to, subtracting one from, or negating a number, respectively

Exercise 1 Design a function eval that evaluates a simple program to a number.

Notice that our second example for simple programs looks a lot like code we write in BSL. Interesting...