Raph,

 

I got into trouble again. In the code snippet below, you used
{Module.load }. However, I am not able to see that method. I can see
{Module.link } or {Module.apply} in the documentation, but no "load". It
does compile though - however it appears to hang there when I try to
run. We typically use Module.link. But the problem that is I am facing
now is to call a function (that I get from the input file) inside the
module that I linked dynamically. Maybe something to do with handling
variables in Oz! Any help is much appreciated.

 

Define ConstraintFileName DirName

 

%% return the last N elements of list L

fun {LastN L N}

   {List.drop L {Max 0 {Length L}-N}}

end

 

%% return the first elements of L stripping out N

fun {FirstN L N}

   {List.take L {Max 0 {Length L}-N}}

end

 

%% return the last elements of List L stripping out L1

fun{LastRemain L L1}

  NewL = {List.drop L {Max 0 {Length L1}}}

  in NewL 

end

    

%% return the list of filenames in the given directory that end in
".ozf"

fun {ImportFiles DirName}

   Files = {OS.getDir DirName}

   % in that list, keep the filenames that end in ".ozf"

   OzfFiles = {Filter Files fun {$ F} {LastN F 4}==".ozf" end}

in

   % add DirName in front of all

   {Map OzfFiles fun {$ F} {Append DirName F} end}

end

 

%% load all those modules in generalized case

%Mods = {Module.link {ImportFiles DirName}             <--- does not
seem to work

 

%% get all files and link to work along with the rest of the code  (Lets
assume I just have one ozf file in that dir)

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

 

 <Later in the code>

 

                %% Restrict scheduler with problem specific domain
constraints

               if{HasFeature ProblemDescription
problemDomainConstraints} then

                {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 here / However works okay when I hardcode
like this -ConstaintFileName.testFunc

 

Ashis

________________________________

From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]
On Behalf Of Raphael Collet
Sent: Thursday, October 16, 2008 4:50 PM
To: Mozart users
Subject: Re: "import" ing ozf dynamically

 

Dear Ashis,

There are a few problems in your function ImportFiles.  First, dirName
is an atom, not a variable name!  Then you should filter the list of
files you get, to keep the ones ending in ".ozf".

%% return the list of filenames in the given directory that end in
".ozf"
fun {ImportFiles DirName}
   Files = {OS.getDir DirName}
   % in that list, keep the filenames that end in ".ozf"
   OzfFiles = {Filter Files fun {$ F} {Drop F {Length F}-4}==".ozf" end}
in
   % add DirName in front of all
   {Map OzfFiles fun {$ F} {Append DirName &\|F} end}
end

%% load all those modules
Mods = {Module.load {ImportFiles
"D:\\data\\amaity\\workspace\\Scheduler\\src\\ProgramSpecificConstraints
"}}

Cheers,
raph

On Thu, Oct 16, 2008 at 9:05 PM, Maity, Ashis K <[EMAIL PROTECTED]>
wrote:

Raph,

 

Thanks for your response. In fact that's the way I started with. May be
I am doing something else wrong. Just to make one point clear is that I
don't know the ozf file names before hand and only the directory where
they would be residing. So I want to check all the files in that
directory and dynamically link all the .ozf files either through
"import" or through the modules that you are suggesting. So the
following should work inside "define" block - right?

 

% Get the .ozf files from ProgramSpecificConstraint dir

    fun{ImportFiles dirName} 

     Files = {OS.getDir dirName}

     {ForAll Files proc{$ X} Y Z in

            {String.token X &. Y Z}

            if Z == "ozf" then 

                    %Files = X

                    {Browse 'linking file'#{String.toAtom Y}}

                else

                     {Browse 'did nothing'}

                end

     end

      } in Files  

  end

 

 [Sched] = {Module.link [ {ImportFiles
'D:\\data\\amaity\\workspace\\Scheduler\\src\\ProgramSpecificConstraints
'}]}

 

 

This does compile though. But getting some runtime issues.

 

Thanks,

 

Ashis

 

________________________________

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

 

Dear Ashis,

There is a simpler way to load a module from an .ozf file: Module.link.
It takes a list of urls (or file names) and returns a list of modules
(instantiated from the functors found in the files):

[ModuleFoo]={Module.link ['Foo.ozf']}

Cheers,
raph

On Thu, Oct 16, 2008 at 7:01 PM, Maity, Ashis K <[EMAIL PROTECTED]>
wrote:

Hello,

 

I am new to Mozart. I am trying the following piece of code where I am
trying to import .ozf files dynamically. Is it possible? Seems like I am
always getting the following error (tried "import" both at inside the
proc or calling it from outside) where I try to link the dynamically
obtained file name with a variable name e.g., Sched at X : syntax error,
unexpected T_VARIABLE, expecting T_OZATOM

 

% Get the .ozf files from ProgramSpecificConstraint dir

    proc{ImportFiles dirName ?File} Files in

      Files = {OS.getDir dirName}

      {ForAll Files proc{$ X} Y Z  in

                               {String.token X &. Y Z}

                               if Z == "ozf" then XX in

                                      functor XX

                                      import

                                         Sched at X

                                      end

                                     File = X

                               else

                                      {Browse 'did nothing'}

                               end

                            end

      }

   end

 

%import

   %Sched at {ImportFiles '.'}

 

Thanks so much,

 

Ashis

 


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

 

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

Reply via email to