On Thu, Oct 27, 2005 at 01:30:44PM -0600, Luke Palmer wrote: : On 10/27/05, Yiyi Hu <[EMAIL PROTECTED]> wrote: : > What I want to do, is a bit like... : > : > class A { : > has $.b; : > method show { "$.b".say }; : > }; : > : > A( b => 5 ).show;` : : Yes, I definitely want this to be the way that case type instances are : created: all those .news everywhere could get annoying.
On the other hand, it potentially makes these mean very different things: A @x A(@x) and that's a problem. Semantically, it would certainly be possible to teach any "kind" to respond to .() and attempt to clone or bless itself into a new object, but syntactically if we introduce A as a list operator we can never use it as a bare type mark on a variable like @x without some declarator out front. So either we rule out bare "A $x" as a coercion or cast, or we rule out bare "A" as a list operator, which would make the parens required. But even with parens, we can't easily make A([EMAIL PROTECTED]) mean both of these simultaneously: @args[0].as(A) A.new([EMAIL PROTECTED]) Well, okay, maybe if we're really sneaky about our MMD, we could make that work most of the time. But it kind of loses the distinction of making a new A out of something else vs making the current thing look like an A without necessarily cloning it. That probably needs syntactic relief anyway. Maybe A! is a hard cast and A? is a soft cast. Needs more waffling. Er, more thought. : Anyway, assuming that class and sub namespaces are separate, which may : be a dubious assumption: : : our &A ::= &A::new.assuming(A); The "variables" are separate in the symbol table, but both of them try to warp the grammar to recognize a bare 'A'. It's not clear what will happen in that case. If the original ^A is really ^*A, then defining &A will likely just hide the outer meaning of A. On the other hand, with our definition of package aliasing, the global name includes version and author, and the current scope has an A alias to that long name, and that might collide with the A name of &A in the current scope. : Or, more explicitly (and more readably IMO): : : sub A (\$x) { A.new(*$x) } Sorry, &A is introduced immediately, so you've just written a nice infinite recursion. I'd suggest sub A (\$x) { ::A.new(*$x) } Larry