On Fri, Jul 05, 2002 at 10:11:44AM +0100, Mark Fowler wrote: > I'd vote a yes for this as well. If we're going to be DWIM (i.e. by > turning it into a scalar) then we should also DWIM by allowing us to treat > it as a list.
That's a good rationale. You've convinced me. If we are going to surpise people then, well, we shouldn't surprise people. :-) But then, on second thoughts, if we do this for sort, then we should surely also do it for nsort, max, first, last, and any other list virtual method that an unsuspecting user might call. Perhaps better to add some fallback code in the stash that, if it fails to find a SCALAR_OP, looks for a LIST_OP and treats the scalar item as a single element list. Then, calling any list vmeth on a scalar would effectively promote it to a list. Yes, I like this. [tappety-tap] OK, I've implemented it. All tests pass including ones like: [% string.sort.join %] > As well as this patch we need both test patches and documentation patched. > I'd submit them myself but I can't work out where the virtual methods are > tested. t/vmeth.t [ sounds of Mark kicking himself ] > There seems to be a second experimental stash that may or may not need > patching to support the same methods as well (what's this for again?) Uhm, it supports some new stuff (for some definition of "new stuff" that eludes me at present) that Craig added, but may (or may not, I'm not sure if we ever benchmarked it) add some overhead that I wasn't keen to add to the regular stash until we were sure we wanted it. Yes, it does need patching. [tappety-tap] OK, I've changed it to copy all virtual methods from the regular Template::Stash. So now we can at least rest assured that the two won't get out of sync wrt virtual methods. And funnily enough, in reading the comments, I find that one of the ways in which it differs from the regular stash is this: # - allows list ops to be applied to scalars by promoting the scalars # to one-element arrays (like an implicit "array"). So you can # do things like SCALAR.size, SCALAR.join and get a useful result. What a good idea! :-) > Oh, and it'd be nice if someone else patched the C stash to add this kind > of thing in as a pure C operation, but it'll work without it. Yep, true. Er no wait, I need to patch the XS stash to do the item/list folding. Hang on. [tappety-tap] OK, I've done the XS stash too. And I've also documented it, checked it into CVS and built a new developer release... ...but I'm getting ahead of myself - that's for the next message. Cheers A
