Kilian Sprotte wrote:
Hi,

I am rather an Oz newbie and I am having a little problem with the Space hierarchy. I have written a function that returns some data (a list of FS constants...) to be used in a search script - I have implemented this function using a dictionary for memoization, because I was hoping to access the desired data inside the search script without being forced to precompute it explicitly beforehand. (Since outside the search script, I dont really know what my args to this function are...)

I am getting an error that states I cannot do Dictionary.put from a local Space.

Indeed, computation spaces normally cannot have side effects. Basically if the arguments of your function are not chunks, you can store the dictionary outside the space, using the technique you mention:

Wanted to ask you, if redesigning this memoized functions as an Active Service using a port would probably solve the problem?

Imagine that F is the (unary) function that actually computes a result. The function MemoF below returns the same results as F, and memoizes them. MemoF can be used in subspaces if its argument is a number, or an atom.

local
   Memo={NewDictionary}
   S P={NewPort S}
in
   thread
      for X#Y in S do
         if {Not {Dictionary.isMember Memo X}}
         then Y=Memo.X
         else Y={F X} Memo.X:=Y
         end
      end
   end
   fun {MemoF X}
      Y in {Port.sendRecv P X Y} Y
   end
end

If you want to use more complex arguments, you'll need to either map them to integers, or use a something more sophisticated than a dictionary for the memo table.

Cheers,
raph

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

Reply via email to