Call With Result


My new version of the Scene Beans animation framework has a design inspired by functional programming: it represents animations as immutable data structures, which facilitates the coordination of concurrent animation and rendering and provides other benefits. Very elegant in principle, but I occasionally need to construct circular structures of objects to represent repeating behaviours. The semantics of Java make it impossible to compose circular structures of immutable objects. What I really need is a Java implementation of call-with-result, a primitive of HScheme that "allows you to call a function with an argument that contains the result of the function". That's right, in HScheme you can pass the result of a function call as an argument to the very call that calculates that result! How frustrating: what I would normally consider an intriguing but esoteric language mechanism is exactly what I need but don't have.

Update: O'Caml provides exactly what I need as well: the let rec statement let's one create circular immutable data structures. Perhaps Java will provide something similar in some future version but, judging by how limited Java's generics are compared to those of O'Caml and other languages, I don't hold much hope.

Copyright © 2004 Nat Pryce. Posted 2004-03-01. Share it.