On 01/10/2008 01:15 PM, Martin Rubey wrote: > Ralf Hemmecke <[EMAIL PROTECTED]> writes: > >> 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 > > Quite possible. But I wouldn't need that in map! anyway, would I? > > the doc to map! only says > > map!(f,u) destructively replaces each element x of u by \axiom{f(x)}. > > and I think that should be interpreted as: > > the result of map!(f,u) is obtained by replacing each element x of u > by > f(x). In this process, u may be destroyed. > > I think that would allow the implementation > > map!(f: S -> S, s: %) == ref map!(f, deref s)$List(S) > > but *not* > > map!(f: S -> S, s: %) == -- from HOAGG > map!(f, deref s)$List(S) > s > >> That said ... >> >> *Don't use l after you have called sort!(l) unless you say l:=sort!(l).* > > That's exactly what I'm thinking. (for sort! it is obvious, but not that much > for map!, that's why I asked)
Aha! Now I understand. And you are quite right. map!(f: S -> S, s: %) == -- from HOAGG map!(f, deref s)$List(S) s Is dangerous if it is not documented that this map!(f,u) leaves u in a reasonable state. In fact, the documentation if % has shallowlyMutable then map_!: (S->S,%) -> % ++ map!(f,u) destructively replaces each element ++ x of u by \axiom{f(x)}. in aggcat.spad seems to suggest a good u, but, in fact, I don't think that it is the best API description. So what about map!(f: S -> S, s: %) == -- from HOAGG setref(s, map!(f, deref s)$List(S)) s ? With that definition we would have s: Stack Integer := [1,2,3] f: Integer -> Integer := ... t := map!(f, s) and s = t after the call, i.e. meaning that s is destructively modified, but *usable* afterwards. I now tend to be against 2) (the current implementation) since there Stack silently relies on the *implementation* (not the interface) of List. The interface of List *doesn't say explicitly* that the second argument of map! is still usable after the call. 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