Moritz Lenz wrote:
Kevan Benson wrote:
Should there not be a way to define object constructors with custom signatures that can be usefully invoked like a normal constructor?

Currently, defining a BUILD method for a class with a specific signature doesn't seem to allow for the object to be invoked by new with that signature and be correctly passed to the right BUILD method. It seems a whole chain of new -> bless -> BUILDALL -> BUILD would need to be defined with specific signatures just to get a custom constructor.

No. It's enough to write a method .new that calls bless, which in turn
calls BUILDALL (which re-dispatches to BUILD) (sorry if I got the order
wrong in that IRC conversation).

Let's assume we define default new() method with signature (*...@p, *%n)
that passes positional arguments to BUILD as BUILD(|@p, |%n), then we
might not be able to call BUILD submethods from superclasses (because
they don't expect any positional parameters), so you basically loose
compatibility with any super classes by introducing positional
parameters. Not a good idea.

It seems much more sane as it is now, that is to modify only the
signature of new new() methods, not of BUILD methods.

Okay, I can accept that. Most of my objections seemed to stem from misunderstanding what can be done in .new (or stated more succinctly, what can be done *easily* in .new). I was under the impression that since it was before bless, operations like calling methods on the object might be harder to do, but it's nothing that can't be worked around.

That said, I submit that it's a very confusing part of the language as defined currently, and I haven't seen a very thorough explanation of the purpose of each method in the chain the instantiates a new object. S12 touches upon them slightly, but not in enough detail that I was able to work out where I should be adding code to appropriately make alternate constructors.


-Kevan Benson
-A-1 Networks

Reply via email to