|
From: | Christian Aistleitner |
Subject: | [Axiom-developer] Re: [Aldor-l] exports and constants |
Date: | Mon, 24 Jul 2006 09:37:52 +0200 |
User-agent: | Opera Mail/9.00 (Linux) |
Hello,On Sun, 23 Jul 2006 08:00:56 +0200, Bill Page <address@hidden> wrote:
---BEGIN aaa6.as #include "aldor" #include "aldorio" macro I == MachineInteger; define CatX: Category == with {foo: () -> I} A: CatX == add {foo(): I == 0;} B: CatX == add {foo(): I == 1;} import from MachineInteger; X: CatX == if odd? random(10) then A else B; main(): () == { import from X; stdout << foo() << newline; } main(); ---END aaa6.as woodpecker:~>aldor -fx -laldor aaa6.as woodpecker:~>aaa6 0 woodpecker:~>aaa6 0 woodpecker:~>aaa6 0 woodpecker:~>aaa6 0 woodpecker:~>aaa6 0 woodpecker:~>aaa6 1 woodpecker:~>aaa6 1 [...][...] main(): () == { import from X; stdout << foo() << newline; stdout << foo() << newline; stdout << foo() << newline; stdout << foo() << newline; stdout << foo() << newline; stdout << foo() << newline; } main(); You will see that each time you run the program you will only get one *constant* result (all 0's or all 1's). But if you run the same program repeatedly (as you did above), then sometimes you get one result and sometimes the other! Within a given runtime of the program, the result is constant and not variable as you might be expecting.
I'd strongly expect it to be constant at runtime! "==" gives a constant. So it should be constant.
What kind of concept is a modifyable constant? Maybe you want to refer to a macro instead of a constant?A assume that each time you start the program, odd? random(10) is evaluated exactly once.
Of course, your whole main function accounts for exactly one program start.
My conclusion is that Aldor must be sort of "faking" the compilation of the constants in the sense that they are not fully resolved at compile-time, yet they are indeed constant within any run of the program. There must be some kind of dynamic initialization phase at the start of the program.
I doubt that. The constant X is compiled to "if odd? random(10) then A else B;" and neither A nor B. That's not faking, that's just what's in the .as file. However, the value of a constant is (typically) determined only once, hence for the whole program execution X acts like either A or B.
-- Kind regards, Christian
[Prev in Thread] | Current Thread | [Next in Thread] |