CS 1102 Homework 6

How to Design Programs: An Introduction to Programming and Computing

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
CS 1102 Homework 6: Macros Due: October 4 (Thursday) at 11:59pm via turnin (assignment name hwk6 ). Assignment Goals To give you practice with macros The Assignment 1. Implementing Objects Through Macros Despite their syntactic differences, functional and object-oriented programs are more similar than you probably think they are. What do objects do? They group together data and functions into one piece of data, and you access methods by sending messages to objects. Whereas in functional programs, we might write ;; A dillo is a (make-dillo number boolean) (define-struct dillo (length dead?)) ;; longer-than? : dillo number -> boolean ;; is dillo longer than given length (define (longer-than? adillo len) (> (dillo-length adillo) len)) ;; run-over : dillo -> dillo ;; return dead dillo one unit longer than given dillo (define (run-over adillo) (make-dillo (+ (dillo-length adillo) 1) true)) We could also have written this in object-style in Scheme using functions to support messages: (define make-dillo-obj (lambda (length dead?) (lambda (message)
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

This homework help was uploaded on 02/06/2008 for the course CS 1102 taught by Professor Fisler during the Spring '07 term at WPI.

Page1 / 3

CS 1102 Homework 6 - CS 1102 Homework 6: Macros Due:...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online