|
4.22.4 Commands for user defined types
User defined types are normal data types (which do not belong to a ring,
even if they have ring dependent parts), so they can be passed as argument
to procedures, and recieved as result from procedures.
In order to apply kernel commands to these types (like string , + ),
provide a usual procedure (say proc p ..) for that task and
install it via system("install", user_type , kernel_command ,p, number_of_args ); .
The user_type and kernel_command have to be given as strings.
Example:
| newstruct("nt","int a,poly b,string c");
nt A;
A;
==> c=
==> b=??
==> a=0
ring r;
// a pretty print routine for nt:
proc pretty_print(nt A)
{
"nt with string c:"+A.c+" and poly:"+string(A.b);
}
system("install","nt","print",pretty_print,1); // default printing uses print
A;
==> nt with string c: and poly:0
==>
// a custem add for nt:
proc nt_add(nt A,nt B)
{
nt C;
C.a=A.a+B.a; C.b=A.b+B.b; C.c=A.c+B.c;
return(C);
}
system("install","nt","+",nt_add,2);
A.b=x;
nt B; B.c="B"; B.b=y;
A+B;
==> nt with string c:B and poly:x+y
==>
|
|