[plt-scheme] self-referential data structures

From: Thomas Chust (chust at web.de)
Date: Fri Mar 6 05:45:06 EST 2009

2009-03-06 Stephen Bloch <sbloch at adelphi.edu>:
> [...]
> In partial answer to your previous question, no, self-referential data types
> are not limited to functional programming, and in fact people have been
> building lists and trees in C, Pascal, Ada, C++, etc. for decades.  Some of
> the problems they encounter can be eliminated by making the data structures
> "immutable", i.e. creating a little safe island of functional programming
> within the terrifying ocean of mutation and imperativity. :-)  In Java and
> C++, for example, you can largely achieve this by providing getters, but no
> setters, for your class fields.
> [...]


on a sidenote, if you want truly immutable fields, you should declare
them final in Java or const in C++. In C++ this doesn't guarantee that
the field is kept constant, but it makes "accidental" mutation a lot
less likely. In Java it does guarantee that the field keeps its value
assigned by the constructor and it also makes the garbage collector
happier :-)


When C++ is your hammer, every problem looks like your thumb.

Posted on the users mailing list.