On 01/10/2008 09:42 AM, Martin Rubey wrote: > Dear Gaby, > > I saw you implemented map!$Stack as follows: > > map!(f: S -> S, s: %) == -- from HOAGG > map!(f, deref s)$List(S) > s > > I have two questions: > > 1) why didn't you say > > map!(f: S -> S, s: %) == ref map!(f, deref s)$List(S) > > 2) isn't > > map!(f: S -> S, s: %) == -- from HOAGG > map!(f, deref s)$List(S) > s > > assuming that map! stores its result in s? I'm not sure whether this is > ok:
Unfortunately 1) and 2) are not equivalent with the current implementation of the Reference domain. In boolean.spad.pamphlet one finds Reference(S:Type): Type with ref : S -> % ++ ref(n) creates a pointer (reference) to the object n. ... == add Rep := Record(value: S) p = q == EQ(p, q)$Lisp ref v == [v] ... That looks to me like that for a: Reference Integer := ref 1; b: Reference Integer := ref deref a; it does not hold a = b so 1) would create a new memory location whereas 2) would not. I hope my SPAD understanding is correct. > (14) -> l := [1,16,81,1] > > (14) [1,16,81,1] > Type: List PositiveInteger > (15) -> sort! l > > (15) [1,1,16,81] > Type: List PositiveInteger > (16) -> l > > (16) [1,16,81] > Type: List PositiveInteger > > > comments? Yes. Whenever you call a destructive function on something, you should be *very* careful. Where is it documented that after calling sort!(l) the variable l still has a proper value. It could well be that sort! leaves l in a state like, for example, [1, <pointer outside the data segment>, ... It could happen that after a destructive function there is no NIL at the last entry of the list, but rather a pointer to a wild place in memory that still holds something nice but will be reclaimed the next time the garbage collector runs. That said ... *Don't use l after you have called sort!(l) unless you say l:=sort!(l).* Ralf ------------------------------------------------------------------------- Check out the new SourceForge.net Marketplace. It's the best place to buy or sell services for just about anything Open Source. http://ad.doubleclick.net/clk;164216239;13503038;w?http://sf.net/marketplace _______________________________________________ open-axiom-devel mailing list open-axiom-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/open-axiom-devel