|
4.21.5 Assignments for user defined types
By default, only objects of the same (user defined) type can be assigned,
there is no automatic type conversion as for the kernel data types.
But the operator = can be overidden in oder to write custom
constructors:
via system("install", user_type ,"=" ,p,1); .
The user_type has to be given as a string.
Example:
| newstruct("wrapping","poly p");
proc wrap(poly p)
{
wrapping w; w.p = p;
return (w);
}
system("install", "wrapping", "=", wrap, 1);
ring r = 0,x,dp;
wrapping w = x+1;
w;
==> p=x+1
w = int(1); // via conversion int->poly
w;
==> p=1
w=number(2); // via conversion number->poly
w;
==> p=2
|
|