From 493e14692e155587bf992eee2b4130d74f414711 Mon Sep 17 00:00:00 2001 From: Emin Arslan Date: Thu, 23 Jan 2025 19:27:34 +0300 Subject: [PATCH] Update section 2.4.3 --- sec-2-4-3-data-directed.lisp | 43 ++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/sec-2-4-3-data-directed.lisp b/sec-2-4-3-data-directed.lisp index 403ae49..3713b66 100644 --- a/sec-2-4-3-data-directed.lisp +++ b/sec-2-4-3-data-directed.lisp @@ -143,3 +143,46 @@ (let ((rec (get-employee name i))) (if (employee-contents rec) (return rec))))) + + +;; finally, message passing stuff. +;; 2.75 +(defun make-from-mag-ang (mag ang) + (lambda (op) + (cond + ((eql op 'real-part) (* mag (cos ang))) + ((eql op 'imag-part) (* mag (sin ang))) + ((eql op 'magnitude) mag) + ((eql op 'angle) ang) + (t (error "Unknown operation."))))) + +;; Ex 2.76 +;; This one's a flat question, so I'm just going to answer. +;; I'm also going to explain a little bit about how this relates +;; to my prior programming experience. +;; +;; Generic operations with explicit dispatch are not very good +;; for a system that must be constantly extended and changed. +;; adding a new type is difficult - all previous functions +;; must be changed to accommodate the new type. +;; Adding a new function however, is comparatively easier +;; since the new function must only accommodate existing types, +;; and does not have to modify existing code. +;; I beleive this maps pretty easily to a procedural programm + +;; Message passing however, thinks in terms of objects. +;; so adding a new type to the table is easy and can be done +;; without modifying existing objects, however, adding a new +;; function is difficult, as existing objects must be modified to accommodate +;; the new function. + +;; a table-lookup, or the data directed style is most suited to +;; extremely extensible systems, as new functions can be added +;; by just adding them to the lookup table, and new types +;; can be defined by just adding new function/type combinations +;; to the table as well. + +;; Note: this problem is sometimes referred to as the "expression problem." + + +