I think the cast lfun interface has to be expanded a bit as well. If we do (A)B then the cast method in B should get the program A as second argument, I think. Further, if B has no cast method, should some ``cast (or even create) in A be called? Example: (Gmp.mpz)5 would then result in Gmp.mpz(5).
/ Martin Nilsson (lambda)
Previous text:
2003-05-06 15:42: Subject: Re: Implicit class construction, _cast() and `=()
On Tue, May 06, 2003 at 03:00:06PM +0200, Martin Nilsson (lambda) @ Pike (-) developers forum wrote:
You are wrong. (SomeType)something; doesn't call SomeType with someting.
It does:
Pike v7.4 release 10 running Hilfe v3.5 (Incremental Pike Frontend)
class SomeType { void create(mixed ... args) { write("SomeType(%O)\n", args); } void _cast(mixed ... args) { write("SomeType_cast(%O)\n", args); } }; int x = 5; string y = "13"; (SomeType)x;
SomeType(({ /* 1 element */ 5 })) (1) Result: HilfeInput()->SomeType()
(SomeType)y;
SomeType(({ /* 1 element */ "13" })) (2) Result: HilfeInput()->SomeType()
(SomeType)(x);
SomeType(({ /* 1 element */ 5 })) (3) Result: HilfeInput()->SomeType()
(SomeType)(y);
SomeType(({ /* 1 element */ "13" })) (4) Result: HilfeInput()->SomeType()
So I am right :)
(SomeType)(something) however does.
As you can see - both do.
If it was possible to cast things into arbitrtary types, how would you know if (SomeType)(something) really means SomeType(something) or (SomeType)something?
I know because (TypeName) is a typecast operator. Type (class) name by itself is not used. So, the construct (SomeType)someobj must actually call someobj->_cast("SomeType") (as it does in case of simple types).
At least, this is logical. Or? :)
Regards, /Al
/ Brevbäraren