Good solution!

You can simplify it a bit with a function like this (not tested):

fun {LinkWith File Args}
   Function = {Pickle.load File}
   Functor Mod
in
   {Procedure.apply Function {Append Args [Functor]}}
   [Mod] = {Module.apply [Functor]}
   Mod
end


A1={LinkWith "A.ozf" [", so greetings"]}
B1={LinkWith "B.ozf" [A1 System]}


Cheers,
  Wolfgang



On Thu, Jul 29, 2010 at 7:42 AM, Lyle Kopnicky <[email protected]> wrote:
> Thanks, Wolfgang and Torsten! I see that although functors are not allowed
> to take parameters in Oz (as they can in ML), there are several workarounds.
> On Wed, Jul 28, 2010 at 4:42 PM, Wolfgang Meyer
> <[email protected]> wrote:
>>
>> Hi,
>>
>> I think that definition of "functor" on pp. 221 of CTM might be
>> intended as a general, language-independent definition.
>>
>> In Oz, the only direct way (that I know of) to have a parametrized
>> functor is to use values from the lexical environment, as suggested by
>> Torsten.
>> This will not work with functors in a different compilation unit
>> (which are loaded from a .ozf file).
>
> Well, you can put any values in an .ozf file, but you can only use an import
> statement on a functor.
>
>>
>> Another indirect possibility is to set a functor-level value AFTER the
>> functor has been loaded or applied, as in this example:
>> http://www.mail-archive.com/[email protected]/msg01784.html
>
> Yes, I thought of that. The only problem is that once you bind the variable,
> that's it. You can't have two different instantiations of the module.
>
>>
>> A third possibility is to use a Module.manager instance directly and
>> register modules at URLs.
>
> Yes, that was also an interesting way to do it. Here's what I settled on:
> A.oz:
> fun {$ SuppText}
>    functor
>    export
>       testA:TestA
>    define
>       fun {TestA}
>          "welcome to A"#SuppText
>       end
>    end
> end
> B.oz:
> fun {$ A System}
>    functor
>    define
>       {System.showInfo {A.testA}}
>    end
> end
> Main.oz:
> functor
> import
>    Application
>    Module
>    Pickle
>    System
> define
>    [A1]={Module.apply [{{Pickle.load "A.ozf"} ", so greetings"}]}
>    [A2]={Module.apply [{{Pickle.load "A.ozf"} ", not at all"}]}
>    [B1]={Module.apply [{{Pickle.load "B.ozf"} A1 System}]}
>    [B2]={Module.apply [{{Pickle.load "B.ozf"} A2 System}]}
>    {Application.exit 0}
> end
> Basically I wanted to instantiate the modules in different ways and link
> them together externally. You can do this by running:
> ozc -c A
> ozc -c B
> ozc -x Main
> ...although the latter command complains about only using B1 and B2 once,
> it's harmless. The program works as intended. The output is:
> welcome to A, so greetings
> welcome to A, not at all
> - Lyle
> _________________________________________________________________________________
> 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