Consider the following implementation:
Rep := Integer
n := 0
failed == (n := n + 1; n)
Is it allowed by Aldor?
Yes. (see below)
And the meaning would be that the value of failed is computed once (at
the time the *domain* is instantiated and never changed. While for a
definition failed() it would be evaluated every time failed() is called.
Aldor is *not* a functional language. Therefore constants and nullary
functions don't behave identically.
---rhxBEGIN const.as
#include "aldor"
#include "aldorio"
Foo: with {
foo: () -> Integer;
bar: Integer;
baz: Integer;
} == add {
n: Integer := 0;
foo(): Integer == {free n; n:=n+1}
bar: Integer == n:=n+1;
baz: Integer == n:=n+1;
}
main(): () == {
import from Foo;
a1: Integer := foo(); stdout << "a1 = " << a1 << newline;
a2: Integer := bar; stdout << "a2 = " << a2 << newline;
a3: Integer := baz; stdout << "a3 = " << a3 << newline;
a4: Integer := foo(); stdout << "a4 = " << a4 << newline;
a5: Integer := bar; stdout << "a5 = " << a5 << newline;
a6: Integer := baz; stdout << "a6 = " << a6 << newline;
}
main();
---rhxEND const.as
aldor -grun -laldor const.as
a1 = 3
a2 = 1
a3 = 2
a4 = 4
a5 = 1
a6 = 2
BTW, note that in Aldor the function body (actually the lambda
expression) creates a new scope while the body for constants does not.
That's the reason for the "free" above.
In fact, it's equivalent to the following definition for the constant foo.
foo: ()->Integer == ():Integer +-> {free n; n:=n+1}
BTW, Rep is not needed for the domain/package Foo, since I have no
reference to %.
Ralf
--
You received this message because you are subscribed to the Google Groups "FriCAS -
computer algebra system" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/fricas-devel?hl=en.