[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Axiom-developer] "has" and "with" (was curious algebra failure)

From: Ralf Hemmecke
Subject: Re: [Axiom-developer] "has" and "with" (was curious algebra failure)
Date: Tue, 14 Aug 2007 12:27:28 +0200
User-agent: Thunderbird (X11/20070728)

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


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

woodpecker:~/scratch>aldor -grun -laldor -DNAMED
"", 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).


PS: Don't ask me why the compiler spits out the two "Nil"s (at compile time). Anybody from knows?

#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;
Dom: Cat D == add {
Dom: Cat SIG == add {
  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;

reply via email to

[Prev in Thread] Current Thread [Next in Thread]