From: Christian Neukirchen Date: 2005-05-29T18:50:48+09:00 Subject: Re: Useless hack of the saturday morning gabriele renzi writes: > Hi gurus and nubys, > > this morning I stumbled across the Autrijus Tang journal[1], > which was showing this nifty piece of code: > > > say [~] (-> @c is copy {gather { > while @c[0] { for @c -> > {take(.shift)} } } > }(['Joec','utrk','shle','te6r',' r .','a h.','nPa.'].map:{[split "",$_]})); > > in perl6 the [] is the reduce metaoperator, and -> is the > equivalent of "proc". > The hard thing was understanding what gather/take are supposed to do. > A little investigation yielded explanation[2], they seem to be some > kind of accumulating construct a-la inject. In the tradition of the > perl6->ruby port such as junctions, .= operator and so on I tried > implement it. That's very nice and useful (I often wished for it), but goo already had it for a long time. :-) It is called "packing" there, see http://people.csail.mit.edu/jrb/goo/manual.46/goomanual_29.html I think the implementation with instance_eval can be a bit surprising, maybe [Dynamic Variables][1] could do that better. [1]: http://chneukirchen.org/blog/archive/2005/04/dynamic-variables-in-ruby.html -- Christian Neukirchen http://chneukirchen.org