login  home  contents  what's new  discussion  bug reports     help  links  subscribe  changes  refresh  edit

Edit detail for SandBox Reflection in Aldor revision 1 of 4

1 2 3 4
Editor: 127.0.0.1
Time: 2007/11/11 11:41:35 GMT-8
Note: transferred from axiom-developer

changed:
-
On July 28, 2006 3:21 AM Christian Aistleitner wrote:

  Actually, I do not like your code, as this does not give you the kind of  
information you would like to have with a reflection framework (e.g.:  
Using proper types for types and functions, Getting parameter types), and  
will cause you lots of problems  -- but maybe I am too early thinking  
about such issues. However, besides the parsing part, the extensions and  
all the other issues, if it's the way you choose, let me help you getting  
it to compile and run. The following piece of code works:
\begin{aldor}
#include "axiom"

macro T == Category;
macro yieldT( expt ) == { yield ( expt@T ) }

EXPORT0: T == with {add2:(%,%)->%};
EXPORT1: T == with {sub2:(%,%)->%};
EXPORT2: T == with {neg: % -> %};

MyDom:  with {
     exports: () -> Generator T;
     EXPORT0;
     EXPORT1;
     EXPORT2;
} == add {
   import from Integer;
   Rep == Integer;

   exports(): Generator T == generate {
	yieldT EXPORT0;
	yieldT EXPORT1;
	yieldT EXPORT2;
   };

   add2(x:%,y:%):% == {
       per(rep(x) + rep(y))
   };

   sub2(x:%,y:%):% == {
       per(rep(x) - rep(y));
   };

   neg(x:%):% == {
       per(-rep(x));
   };

}

checkSign( Dom: with{}, sign: T ):Boolean == {
     Dom has sign;
}

main():List Boolean == {
  append([checkSign( Integer, sign ) for sign in exports()$MyDom ],
         [checkSign( MyDom, sign )   for sign in exports()$MyDom ])
}
\end{aldor}

\begin{axiom}
main()
)clear completely
\end{axiom}

What did I do to get the code working?

  I got rid of pile.
Piles are simply a pain to my eyes.

I turned exports into a function, as you'd probably want to call it more  
than once.

You yielded anonymous categories, created just within the yield clause.  
This looked dangerous to me, so I turned them into proper definitions  
within MyDom's add part. This however gave problems when checking by has  
(as the Categories where no longer anonymous), so I had to use them  
already in the with clause, and moved them to the top-level scope  
(EXPORT0, ...).

I use the macro yieldT instead of simply yield, to tell the compiler the  
yielded thing really is a Category. For some of my experiments this wasn't  
necessary -- for some it was.

I moved your "has" check in a separate function. It doesn't seem to work  
out well, if the Cat part of "Dom has Sig" is not constant in scope.

That's it.

<hr />
Bill Page wrote:

I am very pleased that your code compiles and runs in Aldor but ...

Pile Notation is Beautiful

  Why would anyone prefer to see all that redundant punctuation?
To my eyes the ;{} stuff looks old and ugly.

\begin{aldor}
#include "axiom"
#pile
+++
+++ Example domain with self-identifying declarations
+++
local EXPORT3: Category == with { +:(%,%)->% }
local EXPORT4: Category == with { -:(%,%)->% }
local EXPORT5: Category == with { -: % -> % }

MyDom2: with
   exports: List Category
   EXPORT3; EXPORT4; EXPORT5
 == add
   import from Integer
   Rep == Integer

   exports: List Category ==
     [ EXPORT3, EXPORT4, EXPORT5 ]
  
   +(x:%,y:%):% == per(rep(x) + rep(y))
   -(x:%,y:%):% == per(rep(x) - rep(y))
   -(x:%):%     == per(-rep(x))
+++
+++ Reflection abstraction layer
+++
Reflection( T: Type ): with
  exports: List Category
 == add
  if T has with{exports: List Category} then
     exports:List Category == exports$T
+++
+++ test
+++ 
main2():List Boolean ==

  import from List Category

  append([Integer has sig for sig:Category in exports$Reflection(MyDom2)],
         [MyDom2 has sig  for sig:Category in exports$Reflection(MyDom2)])

\end{aldor}

\begin{axiom}
main2()
\end{axiom}

Unfortunately Axiom apparently cannot access Aldor category values
\begin{axiom}
X := exports()$Reflection(MyDom2);
\end{axiom}



On July 28, 2006 3:21 AM Christian Aistleitner wrote:

Actually, I do not like your code, as this does not give you the kind of information you would like to have with a reflection framework (e.g.: Using proper types for types and functions, Getting parameter types), and will cause you lots of problems -- but maybe I am too early thinking about such issues. However, besides the parsing part, the extensions and all the other issues, if it's the way you choose, let me help you getting it to compile and run. The following piece of code works:

aldor
#include "axiom"
macro T == Category; macro yieldT( expt ) == { yield ( expt@T ) }
EXPORT0: T == with {add2:(%,%)->%}; EXPORT1: T == with {sub2:(%,%)->%}; EXPORT2: T == with {neg: % -> %};
MyDom: with { exports: () -> Generator T; EXPORT0; EXPORT1; EXPORT2; } == add { import from Integer; Rep == Integer;
exports(): Generator T == generate { yieldT EXPORT0; yieldT EXPORT1; yieldT EXPORT2; };
add2(x:%,y:%):% == { per(rep(x) + rep(y)) };
sub2(x:%,y:%):% == { per(rep(x) - rep(y)); };
neg(x:%):% == { per(-rep(x)); };
}
checkSign( Dom: with{}, sign: T ):Boolean == { Dom has sign; }
main():List Boolean == { append([checkSign( Integer, sign ) for sign in exports()$MyDom ], [checkSign( MyDom, sign ) for sign in exports()$MyDom ]) }
aldor
   Compiling FriCAS source code from file 
      /var/zope2/var/LatexWiki/639549157981478454-25px001.as using 
      AXIOM-XL compiler and options 
-O -Fasy -Fao -Flsp -laxiom -Mno-ALDOR_W_WillObsolete -DAxiom -Y $AXIOM/algebra -I $AXIOM/algebra
      Use the system command )set compiler args to change these 
      options.
   Compiling Lisp source code from file 
      ./639549157981478454-25px001.lsp
   Issuing )library command for 639549157981478454-25px001
   Reading /var/zope2/var/LatexWiki/639549157981478454-25px001.asy
   EXPORT0 is now explicitly exposed in frame initial 
   EXPORT0 will be automatically loaded when needed from 
      /var/zope2/var/LatexWiki/639549157981478454-25px001
   EXPORT1 is now explicitly exposed in frame initial 
   EXPORT1 will be automatically loaded when needed from 
      /var/zope2/var/LatexWiki/639549157981478454-25px001
   EXPORT2 is now explicitly exposed in frame initial 
   EXPORT2 will be automatically loaded when needed from 
      /var/zope2/var/LatexWiki/639549157981478454-25px001
   MyDom is now explicitly exposed in frame initial 
   MyDom will be automatically loaded when needed from 
      /var/zope2/var/LatexWiki/639549157981478454-25px001

axiom
main()
LatexWiki Image(1)
Type: List(Boolean)
axiom
)clear completely
All user variables and function definitions have been cleared. All )browse facility databases have been cleared. Internally cached functions and constructors have been cleared. )clear completely is finished.

What did I do to get the code working?

I got rid of pile. Piles are simply a pain to my eyes.

I turned exports into a function, as you'd probably want to call it more than once.

You yielded anonymous categories, created just within the yield clause. This looked dangerous to me, so I turned them into proper definitions within MyDom?'s add part. This however gave problems when checking by has (as the Categories where no longer anonymous), so I had to use them already in the with clause, and moved them to the top-level scope (EXPORT0, ...).

I use the macro yieldT instead of simply yield, to tell the compiler the yielded thing really is a Category. For some of my experiments this wasn't necessary -- for some it was.

I moved your "has" check in a separate function. It doesn't seem to work out well, if the Cat part of "Dom has Sig" is not constant in scope.

That's it.


Bill Page wrote:

I am very pleased that your code compiles and runs in Aldor but ...

Pile Notation is Beautiful

Why would anyone prefer to see all that redundant punctuation? To my eyes the ;{} stuff looks old and ugly.

aldor
#include "axiom"
#pile
+++
+++ Example domain with self-identifying declarations
+++
local EXPORT3: Category == with { +:(%,%)->% }
local EXPORT4: Category == with { -:(%,%)->% }
local EXPORT5: Category == with { -: % -> % }
MyDom2: with exports: List Category EXPORT3; EXPORT4; EXPORT5 == add import from Integer Rep == Integer
exports: List Category == [ EXPORT3, EXPORT4, EXPORT5 ]
+(x:%,y:%):% == per(rep(x) + rep(y)) -(x:%,y:%):% == per(rep(x) - rep(y)) -(x:%):% == per(-rep(x)) +++ +++ Reflection abstraction layer +++ Reflection( T: Type ): with exports: List Category == add if T has with{exports: List Category} then exports:List Category == exports$T +++ +++ test +++ main2():List Boolean ==
import from List Category
append([Integer has sig for sig:Category in exports$Reflection(MyDom2)], [MyDom2 has sig for sig:Category in exports$Reflection(MyDom2)])
aldor
   Compiling FriCAS source code from file 
      /var/zope2/var/LatexWiki/3329545849553873023-25px003.as using 
      AXIOM-XL compiler and options 
-O -Fasy -Fao -Flsp -laxiom -Mno-ALDOR_W_WillObsolete -DAxiom -Y $AXIOM/algebra -I $AXIOM/algebra
      Use the system command )set compiler args to change these 
      options.
   Compiling Lisp source code from file 
      ./3329545849553873023-25px003.lsp
   Issuing )library command for 3329545849553873023-25px003
   Reading /var/zope2/var/LatexWiki/3329545849553873023-25px003.asy
   MyDom2 is now explicitly exposed in frame initial 
>> System error: The value EXPORT5 is not of type LIST.

axiom
main2()
There are no library operations named main2 Use HyperDoc Browse or issue )what op main2 to learn if there is any operation containing " main2 " in its name.
Cannot find a no-argument definition or library operation named main2 .

Unfortunately Axiom apparently cannot access Aldor category values

axiom
X := exports()$Reflection(MyDom2);
There are no library operations named Reflection Use HyperDoc Browse or issue )what op Reflection to learn if there is any operation containing " Reflection " in its name.
Cannot find a definition or applicable library operation named Reflection with argument type(s) Domain
Perhaps you should use "@" to indicate the required return type, or "$" to specify which version of the function you need.