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