notes45 - The define s that produce the individual shapes...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: The define s that produce the individual shapes look no different from before, but the results are different: Each shape is a function, not a list structure. So to get the area of the shape circle3 we invoke that shape with the proper message: (circle3 area) . That notation is a little awkward so we provide a little syntactic sugar that allows us to say (area circle3) as in the past: ;;;;; In file cs61a/lectures/2.4/msg.scm (define (operate op obj) (obj op)) (define (area shape) (operate area shape)) (define (perimeter shape) (operate perimeter shape)) Message passing may seem like an overly complicated way to handle this problem of shapes, but well see next week that its one of the key ideas in creating object-oriented programming. Message passing becomes much more powerful when combined with the idea of local state that well learn next week. We seem to have abandoned tagged data; every shape type is just some function, and its hard to tell which type of shape a given function represents. We could combine message passing with tagged data, if desired,type of shape a given function represents....
View Full Document

This note was uploaded on 02/17/2010 for the course COMPUTER S 26275 taught by Professor Harvey,b during the Spring '10 term at University of California, Berkeley.

Ask a homework question - tutors are online