Mutable objects in FOOP in development v.10.1.8

Started by Lutz, December 06, 2009, 06:46:14 AM

Previous topic - Next topic

m35

#15
Wow Lutz--you've been a big proponent of the functional/immutable approach for so long, I'm surprised and impressed you added mutable objects. I hope you don't feel like you're compromising on all us poor, industry brainwashed, OOP developers ;)

Lutz

#16
... actually, I think OO programming is a good paradigm. I just didn't want to put something into the language which didn't fit well. Now, built only with the colon operator :, the 'self' function and namespaces, FOOP has a good feel to it, is small and naturally fits into newLISP.

m i c h a e l

#17
Quote from: "cormullion"Is this the best way to do this? It appears to work, but...


How about turning the problem around by leaving the method as is and simply copying the original?


> (setq xmas (Time 2009 12 25))
(Time 1261699200 0)
> (setq boxing-day (:shift (copy xmas) 1 'days))
(Time 1261785600 0)
> (:represent xmas)
"Friday December 25 2009 00:00:00"
> (:represent boxing-day)
"Saturday December 26 2009 00:00:00"
> _


copy creates a new object from its argument, and it's this new object that will be referenced by self within the method. As long as your method returns the modified object (as you were already doing), you can use it either way.



m i c h a e l

cormullion

#18
Thanks - that's probably the best solution...