I am trying to set up a little simulation project, but I am running into some problems with FOOPS and pass by value...
I have a Plane class, which considers the engine RPM and the altitude of the airplane:
Code: Select all
(new Class 'Plane)
(define (Plane:Plane rpm alt)
(list 'Plane rpm alt))
Code: Select all
(define (Plane:firewall)
(setf (self 1) 2700))
Code: Select all
(setq aplane (Plane 1900 2000))
(println "Original: " aplane)
(:firewall aplane)
(println "Modified: " aplane)
Code: Select all
Original: (Plane 1900 2000)
Modified: (Plane 2700 2000)
Code: Select all
(setq
planes (list
(Plane 2700 0)
(Plane 2100 1250)
(Plane 1500 900)))
(println "Original: " planes)
(dolist (p planes) (:firewall p))
(println "Modified: " planes)
Code: Select all
Original: ((Plane 2700 0) (Plane 2100 1250) (Plane 1500 900))
Modified: ((Plane 2700 0) (Plane 2100 1250) (Plane 1500 900))
What is the best way to handle updating an object in a list of objects like this?
Also, for what it's worth, I have considered modifying :firewall to return self so I can do this:
Code: Select all
(dotimes (i (length planes))
(setf (planes i) (:firewall (planes i))))
Thanks!