Update section 2.4.3
This commit is contained in:
		@@ -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."
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user