3 questions on FD.distribute generic

Yonet eracar at comcast.net
Tue Dec 14 14:17:45 CET 2004


Can I get external data into the selection function via a port as well as 
sending data?

Thank you for the answers..
Yonet


"Raphael Collet" <raph at info.ucl.ac.be> wrote in message 
news:mailman.625.1103011109.9839.mozart-users at ps.uni-sb.de...
> Yonet wrote:
>>
>> I like to customize the behavior of FD.distribute using the generic 
>> option.
>> I like to implement my own value selection function. The following 
>> function
>> works as it is.
>>
>> {FD.distribute generic(order:   size
>>     filter:  undet
>>     select:  id
>>     value:   fun {$ V}
>>          DomSize = {FD.reflect.size V}
>>          CurDomain = {FD.reflect.domList V}
>>          Ref = {List.nth CurDomain 1}
>>          Sel
>> %         LStdOut = {New Open.file init(name:stdout
>> %     flags:[write append]
>> %     mode: mode(owner: [read write]
>> %         group: [read write]))}
>>       in
>>
>> %         {LStdOut write(vs:"DomSize: "#DomSize#"\n")}
>>          if DomSize > 1 then
>>              Sel = {FD.reflect.nextLarger V Ref}
>>          else
>>              Sel = {FD.reflect.min V}
>>          end
>> %         {LStdOut write(vs:"Sel: "#Sel#"\n")}
>> %         {LStdOut close}
>>          Sel
>>       end
>>     procedure: unit)
>>    Start}
>
> Side remark: have you noticed that your function can be simplified, and
> defined (without debugging) as
>
>   fun {GetValue V}
>      {FD.reflect.nextLarger V {FD.reflect.min V}}
>   end
>
>> Here are my questions:
>>
>> 1) Whenever, I want to call a function inside this selection function the
>> execution stalls when the search starts. Does it mean that I cannot use 
>> any
>> global variables (local to the .OZ file) in this function?
>
> Your function is called inside a computation space (because of search).
> Side effects are normally forbidden inside computation spaces.  Writing
> to a file is a side effect.  However there is one exception to the rule:
> you can send data on a port outside the space.  The procedure Show
> internally uses a port, so you can print debugging information with
> Show.
>
>> 2) Why does the OZ debugger stop inside this function, although the 
>> debugger
>> does not complain when I set breakpoints?
>
> Ozcar does not interrupt code inside computation spaces.
>
>> 3) Why does the function stall when I un-comment the lines to display 
>> what
>> is going on inside the function (like printf s in C)? Since the 
>> breakpoint
>> do not work, I wanted to print local variables.
>
> The same reason as above (side effects).  Actually you should get an
> execution error.  Use Show instead.
>
>
> Cheers,
>
> raph 





More information about the mozart-users mailing list