Kevin's idea is sure to yield a more efficient solution, but take a look
at the code below, which does what you need.

Cheers,

Jorge.

-----------
declare
local
   fun {EqSearch L K V}
      case L of nil then false
      [] (K2#V2)|Rest then
         if {System.eq K K2} then
            V = V2
            true
         else
            {EqSearch Rest K V}
         end
      end
   end
   proc {CyclicMapAux R F Done V}
      if {EqSearch Done R V} then skip
      elseif {F R V} then skip else
         V = {Record.map R fun {$ V0}
                              {CyclicMapAux V0 F (R#V)|Done}
                           end}
      end
   end
in
   fun {CyclicMap R F}
      {CyclicMapAux R F nil}
   end
end

declare
proc {AccessIfCell C V Ok}
   Ok = {IsCell C}
   if Ok then V = @C end
end

declare
C = {NewCell 1}
X
R
R = b(R X)
X = a(C r:b(R X) C)

{Show {CyclicMap X AccessIfCell}}




Kevin Glynn escreveu:
>
>
> A quick idea.  Instead of storing cells directly in the data structure
> could you replace them with indices into a separate array instead? Of
> course you will need to change all your code that accesses/updates the
> cells.
>
> k
>
>
>
> Wolfgang Meyer writes:
>  > Dear all,
>  >
>  > I need some advice on how to pickle a recursive data structure that may
> contain cells.
>  > I know that the Pickle module only works for stateless data, so I
> thought I'd write a small conversion function that I call before the
> call to Pickle.save. And a similar function to apply after Pickle.load.
>  >
>  > The conversion function would look like this:
>  >
>  > declare
>  >
>  > CellMarker = 'unique-string-marking-cells'
>  >
>  > fun {ConvertToStateless D}
>  >    if {Record.is D} then
>  >       {Record.map D ConvertToStateless}
>  >    elseif {Cell.is D} then
>  >       CellMarker#{ConvertToStateless @D}
>  >    else
>  >       D
>  >    end
>  > end
>  >
>  >
>  > The problem is that this function diverges on cyclic records, like
>  >
>  >
>  > A = test(1:A)
>  > in
>  > {ConvertToStateless A}
>  >
>  >
>  > Any idea how I could make this work for such records?
>  >
>  > I guess I need to detect cycles in some way. Maybe there is some
> existing code in the standard library that can show me the way?
>  >
>  > Thank you for any hints,
>  >
>  > Wolfgang
>  >
>  > --
>  > Der GMX SmartSurfer hilft bis zu 70% Ihrer Onlinekosten zu sparen!
>  > Ideal für Modem und ISDN: http://www.gmx.net/de/go/smartsurfer
>  >
>  > 
> _________________________________________________________________________________
>  > mozart-users mailing list
> [email protected]
>  > http://www.mozart-oz.org/mailman/listinfo/mozart-users
>
> _________________________________________________________________________________
> mozart-users mailing list
> [email protected]
> http://www.mozart-oz.org/mailman/listinfo/mozart-users
>


Jorge M. Pelizzoni
ICMC - Universidade de São Paulo


_________________________________________________________________________________
mozart-users mailing list                               
[email protected]
http://www.mozart-oz.org/mailman/listinfo/mozart-users

Reply via email to