Thanks so much for the help. The code is working great now and I am also
gradually getting hang of writing code in Oz. Really appreciate the
level of support from the Mozart-oz community.

 

Ashis

 

________________________________

From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]
On Behalf Of Raphael Collet
Sent: Tuesday, October 21, 2008 2:13 PM
To: Mozart users
Subject: Re: "import" ing ozf dynamically

 

Dear Ashis,

The "name" of a variable does not really exists at runtime.  But what
you can do is build a record M indexed by file names (converted to
atoms), such that, for instance, M.'foo.ozf' gives the module
corresponding to the file named 'foo.ozf'.

%% returns a record with the modules located in the given directory
fun {GetModules DirName}
   Mods = {ImportFiles DirName}
   fun {GetName File}
      {String.toAtom {FirstN {LastRemain File DirName} 4}}
   end
   fun {GetModule File}
      [M] = {Module.link [File]} in M
   end
   NMs = {Map Mods fun {$ File} {GetName File}#{GetModule File} end}
in
   {List.toRecord module NMs}
end

The list NMs is a list of pairs, the first element being the file name
(as an atom), the second one being the corresponding module.  The
function List.toRecord makes a record mapping the filenames in the list
to their corresponding module.  Look closely at how I use Map and the
other functions to build that record.  You'll see, it is not so
difficult.

Cheers,
raph

On Tue, Oct 21, 2008 at 7:52 PM, Maity, Ashis K <[EMAIL PROTECTED]>
wrote:

Raph,

 

Thanks so much again. Actually, the following one I did kind of realize
that I am reassigning the logic variable and hence not working. But how
can I make that variable dynamic so that takes the name of the Functor
file? However, I can live with that and not have the line that I
highlight in italics. 

 

{ForAll Mods

    proc{$ File} 

        ConstraintFileName = {FirstN {LastRemain File DirName} 4}

       {Browse 'do nothing'#{String.toAtom ConstraintFileName}}

       [ConstraintFileName] = {Module.link [File]}  

 

 

But how can I call a function from that module where the function name
came from Pdc below (second part of my question)?

 

{ForAll ProblemDescription.problemDomainConstraints

                 proc{$ Pdc} Constr SpecificConstraints in

                        if{HasFeature Pdc name} then

                           %Constr = {Append "ConstraintFileName."
Pdc.name}

                           Constr = {VirtualString.toString
"ConstraintFileName."#Pdc.name} 

                           {Browse  Constr}    <--- I build the Constr
okay

                           SpecificConstraints = {Constr
ProblemDescription}  

 

hangs at the last line  though works when I hard-code the Module and
function name e.g, {ConstraintFileName.testFunc ProblemDescription}

 

Ashis

________________________________

From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]
On Behalf Of Raphael Collet
Sent: Tuesday, October 21, 2008 1:25 PM


To: Mozart users
Subject: Re: "import" ing ozf dynamically

 

Dear Ashis,



About Module.load: you're right, I made a mistake, it's Module.link that
you should use.  Read carefully its documentation, you will understand
why nothing happens when you call that function: it loads modules *on
demand*.  So

Mods = {Module.link {ImportFiles DirName}}

binds Mods to a list of variables, but does not load modules yet.  You
can check that by running {Browse Mods}.  The variables in Mods will be
determined (and the corresponding modules loaded) once the program will
need their value.  A simple way to force the loading is to Wait on all
variables:

{ForAll Mods Wait}

Now, there are several mistakes in your code...

        local Mods  in

           Mods = {ImportFiles DirName}

           {ForAll Mods

            proc{$ File} 

                ConstraintFileName = {FirstN {LastRemain File DirName}
4}

               {Browse 'do nothing'#{String.toAtom ConstraintFileName}}

               [ConstraintFileName] = {Module.link [File]}
<-------------- Program appears to hang here / however works okay if I
remove the line above Browse

            end    

           }

        End

The program must fail after browsing the first filename.
ConstraintFileName is declared as a *global* variable, and you bind it
twice in the loop!  You cannot reassign logic variables; here you are
trying to assign it 2N values, where N is the number of files you load.
The first assignment (the result of FirstN) succeeds, but the second one
(the result of Module.link) fails, because it loads the module, and
tries to assign it to ConstraintFileName.  At that point, the program
should stop.


Cheers,
raph


________________________________________________________________________
_________
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

Reply via email to