axiom-developer
[Top][All Lists]
Advanced

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

Re: [Axiom-developer] RE: Types as values, and Re: Static versusDynamica


From: Ralf Hemmecke
Subject: Re: [Axiom-developer] RE: Types as values, and Re: Static versusDynamically typed(was:Philosophy... )
Date: Mon, 26 Sep 2005 17:39:37 +0200
User-agent: Mozilla Thunderbird 1.0 (X11/20041206)

William Sit wrote:
Ralf Hemmecke wrote:

[from www.aldor.org:]

Types and functions are first class entities allowing them to be
constructed and manipulated within Aldor programs just like any
other value.

Interesting. If that were so easy, it would be possible to ask a type
for the functions it implements.

Exactly. It has been a long standing (but lost) request (I believe from me) that
Axiom constructors (that include category, domain and packages, but not the
developers :-)) allow query of their arguments. It is useful, for example, to be
able to distinguish whether a field is a quotient field of some integral domain
or just a field to make codes more efficient. The request was not acted upon
because at the time (around 1990 +/- 3 years?), effort was concentrated on
developing the Aldor (A#) compiler, which promised to solve such problems.

I am not so sure whether I would really need that kind of reflection. In some cases it would be useful, for example, for the implementation of something like JUnit for Aldor. However, I somehow do not think that being able to query the structure of a type is a good idea. You gave a good reason, but isn't there a better way to achieve efficiency?

Aldor allows something like

#include "aldor"
#include "aldorio"
Dom: with {
  foo: % -> Boolean;
} == add {
  foo(x: %): Boolean == true;
}

import from Dom;
if Dom has with {foo: % -> Boolean} then {
       stdout << "foo is there" << newline;
} else {
       stdout << "foo is missing" << newline;
}

However, I cannot, for example, write a function that returns a list of
names of functions implemented in Dom. (That is the current knowledge I
have.)

In other words, if I understand the example, you can't list unless you already
know?

Exactly. Well, returning the list of function names would certainly be do-able, but the next thing a programmer would ask for is: How can I call the function with name "foo"? What is the input type? ...

Listing functions in a domain is not a simple question in Axiom. Functions can
be inherited from parent constructors or exported as new. It also depends on in
what form you want the list. Surely, by doing a ")show Dom" (this is in the
interpreter: I am not aware of any compiler equivalent) you get that list.

Same in "aldor -gloop". By saying then

#include "aldor"
#include "aldorinterp"
Integer

one gets

%1 >> #include "aldor"
                                           Comp: 110 msec, Interp: 0 msec
%2 >> #include "aldorinterp"
                                           Comp: 30 msec, Interp: 0 msec
%3 >> Integer
  () @ Join(
PrimitiveType with
        coerce: BInt -> %
        coerce: % -> BInt
    ==  add ()
,
IntegerType with export to IntegerSegment(%)
    ==  add ()
)
                                           Comp: 10 msec, Interp: 0 msec

But again, that is the interpreter. I cannot do anything useful with that output in a stand-alone program.

And, of course, I see no way of morphing the result of "foo" to
"false" without writing a new function.

That is what I was asking: code modification. Like you, I also interpret "first
class object as data" that way (but that need not be the "official"
interpretation).

I think I am happy that the Aldor code itself is not modifyable (as in Maple).

Ralf




reply via email to

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