[OT] Should exist / does exist?

Andy Armstrong andy at hexten.net
Thu Dec 7 00:54:16 GMT 2006


On 7 Dec 2006, at 00:12, Joel Bernstein wrote:
> I've got code working which can do the earlier stuff you mentioned,
> except specific loop labels. I'm not so sure it couldn't do what  
> you're
> asking. I'll post it to the list if you want a look, it's basically
> using a lot of sugar around eval/die though, which as I understand it
> you have already got working... I have subs Next/Last/Redo which
> construct Iterator::Error objects which are trapped out of $@ and  
> acted
> on appropriately.

Yes, that's the way I'm gravitating. I might play with a module the  
exports methods called next, last and redo into the caller's  
namespace and has them construct unambiguous loop exit exceptions as  
you describe. I can nearly convince that plus helpers to assist in  
the classification of the exit exception might be worth having.

I guess the same module could expose optional sugar that'd use  
B::Disassembler / B::Assembler or B::Deparse to rewrite the closure  
transforming

    redo MYLABEL

into

    $my_obj->redo

although I'm not sure it's really worth it.

> My worry is that to add the kind of tree-walking
> behaviour you outline above you would have to bolt the sugar in so  
> close
> to the algorithm that you would end up with code that was less clear
> overall than when you started out...

Quite possibly :)

Although I think that in the tree walking example I posted it'd be  
easy enough - and useful - to bail out of the recursion if the loop  
closure called $tree_walker->last;

-- 
Andy Armstrong, hexten.net



More information about the london.pm mailing list