I don't see how your suggested change for the cast() operator to falling back to _sprintf would help anything in your example case.
It wasn't. I probably should have changed topics/subjects rather than just noting it as below, two or three posts up the thread:
(Dang. Wordy post, and almost completely unrelated to my proposal.)
In Pike, data type conversion is typically handled completely by whatever type of object is being converted to, with no help from the object being converted from. [...]
The above paragraph doesn't make any sense unless you swap "to" and "from" in the first sentence.
Not really, when we are talking about objects. With primitive types, you are right. Example: a Foo object gets converted to a Bar object;
Foo f = Foo(); Bar b = Bar( f );
Object Bar's create gets passed something used to initialize itself into whatever it knows how to deduce from the passed parameter. Bar gets no help from Foo, except possibly by casting Foo to primitive types of some sort. If we could get Foo's help, we would have
Bar b = (Bar)f;
calling f->cast, which would be delegated the work of creating a Bar object, based on its own state.
But I'm afraid I don't have any constructive thoughts on how to do something like that. I believe Nilsson tried skewing reality that way at one time, but largely didn't end up anywhere better than where we were and let it be as is instead (or was reverted, if it got further).
I unfortunately don't recall what the details were. Would something along the lines above be possible to do with today's type system with modest effort?