Modules, Concatenation, and Better Solutions

Shijun He hax.sfo at gmail.com
Fri Oct 19 05:41:52 PDT 2012


On Wed, Oct 17, 2012 at 10:10 AM, David Herman <dherman at mozilla.com> wrote:
> Concrete example: Even and Odd modules refer to each other, but the import statements occur after some initialization:
>
>     module Odd {
>         export let odd = function(x) {
>             return x === 0 ? false : !even(x - 1);
>         }
>         import even from Even; // force execution of Even here, if it hasn't already
>         export let b = odd(17);
>     }
>     module Even {
>         export let even = function(x) {
>             return x === 0 || !odd(x - 1);
>         }
>         import odd from Odd; // force execution of Odd here, if it hasn't already
>         export let b = even(17);
>     }
>     console.log(Odd.b);
>

What about this?

     module Odd {
         import even from Even; // force execution of Even here, if it
hasn't already
         export let odd = function(x) {
             return x === 0 ? false : !even(x - 1);
         }
         export let b = odd(17);
     }
     module Even {
         import odd from Odd; // force execution of Odd here, if it
hasn't already
         export let even = function(x) {
             return x === 0 || !odd(x - 1);
         }
         export let b = even(17);
     }
     console.log(Odd.b);

I guess this doesn't work...


More information about the es-discuss mailing list