Thedefines 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 shapecircle3we invoke thatshape 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 we’ll seenext week that it’s one of the key ideas in creating object-oriented programming. Message passing becomesmuch more powerful when combined with the idea oflocal statethat we’ll learn next week.We seem to have abandoned tagged data; every shape type is just some function, and it’s hard to tell whichtype of shape a given function represents. We could combine message passing with tagged data, if desired,
This is the end of the preview.
access the rest of the document.