I haven't seen any prepackaged way to do something like that, but I'm pretty sure that it wouldn't be too hard to implement in Julia... a "cached-sqrt" function could be written, with methods that take different types, so that each type can have it's own cache.
On Saturday, June 20, 2015 at 5:40:35 PM UTC-4, Laurent Bartholdi wrote: > > Dear Julia-list: > > I'm a quite heavy user of the computer algebra system GAP ( > www.gap-system.org), and wondered how some of its features could be > mapped to Julia. > > GAP is an object-oriented language, in which objects can acquire > attributes over time; and these attributes can be used by the method > selection to determine the most efficient method to be applied. For a > contrived example, integers could have a method "is_square" which returns > true if the argument is a perfect square. When the method is_square is > called, the result is stored in a cache (attached to the object). On the > second call to the same method, the value is just looked up in the cache. > Furthermore, the method "sqrt" for integers may test whether a cached value > is known for the method is_square, and look it up, and in case the argument > is a perfect square it may switch to a better square root algorithm. Even > better, the method dispatcher can do this behind the scenes, by calling > itself the square root algorithm for perfect squares in case the argument > is already known to be a square. > > (This is not really a GAP example; in GAP, only composed types (records, > lists) are allowed to store attributes. In the internals, each object has a > type and a bitlist storing its known attributes.) > > I read through the Julia manual, but did not see any features ressembling > those (caching results of methods, and allowing finer dispatching). I have > also read http://arxiv.org/pdf/1209.5145.pdf which says that "the type of > a value cannot change over its lifetime". > > Is there still a way to do similar things in Julia? > > Thanks in advance, and apologies if I missed this in the manual, > Laurent >
