[Aldor-l] [Axiom-developer] "has" and "with" (was curious algebra failure)
Ralf Hemmecke
ralf at hemmecke.de
Tue Aug 14 06:27:28 EDT 2007
> Ok. How do tell Aldor that I do not care about the name I am only
> interested in the anonymous body of a given category definition? I
> thought I understood this, but I guess not. The discussion of the
> 'define' keyword in the AUG lead me to believe that that was what was
> implied by it's use.
> If I pass a category as a parameter to a constructor, e.g.
>
> define D: Category == with
> f: % -> %
>
> C(X:Category):Category == with
> if Integer has X then
> ...
>
> A:C(D)
> does X represent the named category (D) or just it's category-value
> (with f: %-> %)? Does the meaning of X change if we omitted the
> 'define' keyword?
> Can you explain to me how I can use this? Or what to read? :-)
Oh, I would nearly have said, you got me. But here is how you can do it.
Anyway, your are right, that "define" needs some more clarification.
woodpecker:~/scratch>aldor -grun -laldor aaa.as
Nil
Nil
-1
-2
woodpecker:~/scratch>aldor -grun -laldor -DNAMED aaa.as
"aaa.as", line 27: stdout << (foo(d)::Integer) << newline;
.............^
[L27 C14] #1 (Error) There are no suitable meanings for the operator `foo'.
Add "-fasy" to the command line and investigate the .asy file. You will
see that indeed D will be tested in the "if" statement of Cat if you say
Dom: Cat D == add ...
I am not sure whether that makes you happy, but I haven't used such a
construction before (category in an argument + conditional in terms of
that category).
Ralf
PS: Don't ask me why the compiler spits out the two "Nil"s (at compile
time). Anybody from Aldor.org knows?
---BEGIN aaa.as
#include "aldor"
#include "aldorio"
macro SIG == with {-: % -> %}
define D: Category == SIG;
Cat(X: Category): Category == with {
if Integer has X then {foo: % -> %}
new: Integer -> %;
coerce: % -> Integer;
}
#if NAMED
Dom: Cat D == add {
#else
Dom: Cat SIG == add {
#endif
Rep == Integer;
import from Rep;
new(i: Integer): % == per i;
coerce(x: %): Integer == -rep(x);
foo(x: %): % == per(2*rep(x));
}
main():() == {
import from Integer, Dom;
d: Dom := new 1;
stdout << (d::Integer) << newline;
stdout << (foo(d)::Integer) << newline;
}
main();
---END aaa.as
More information about the Aldor-l
mailing list