[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Martin DeMello

3/27/2008 6:21:00 PM

http://www.voidspace.org.uk/python/weblog/arch_d7_2008_03_22....

Nice example of what you can do with generators. Is this sort of thing
doable efficiently in 1.9?

martin

7 Answers

Dave Thomas

3/27/2008 6:33:00 PM

0


On Mar 27, 2008, at 1:20 PM, Martin DeMello wrote:
> http://www.voidspace.org.uk/pyth...
> arch_d7_2008_03_22.shtml#e954
>
> Nice example of what you can do with generators. Is this sort of thing
> doable efficiently in 1.9?


Don't know if this meets the criteria, but

http://pragdave.blogs.pragprog.com/pragdave/2007/12/pipelines-...
http://pragdave.blogs.pragprog.com/pragdave/2008/01/pipelines-...

Cheers


Dave

Martin DeMello

3/27/2008 6:46:00 PM

0

On Thu, Mar 27, 2008 at 11:33 AM, Dave Thomas <dave@pragprog.com> wrote:
>
>
> Don't know if this meets the criteria, but
>
> http://pragdave.blogs.pragprog.com/pragdave/2007/12/pipelines-...
> http://pragdave.blogs.pragprog.com/pragdave/2008/01/pipelines-...

Yes, exactly what I had in mind. Very nice.

martin

Martin DeMello

3/27/2008 6:51:00 PM

0

On Thu, Mar 27, 2008 at 11:33 AM, Dave Thomas <dave@pragprog.com> wrote:
>
> http://pragdave.blogs.pragprog.com/pragdave/2007/12/pipelines-...
> http://pragdave.blogs.pragprog.com/pragdave/2008/01/pipelines-...

Tangentially, why did the trick of defining methods with the same name
as classes, to delegate to Class.new, fall out of favour?

tripler = Transformer.new {|val| val * 3}

would read more nicely as

tripler = Transformer {|val| val * 3}

with def Transformer(x); Transformer.new(x); end

I remember it being a commoner practice a few years ago.

martin

Daniel Berger

3/27/2008 7:55:00 PM

0



On Mar 27, 12:20=A0pm, "Martin DeMello" <martindeme...@gmail.com> wrote:
> http://www.voidspace.org.uk/python/weblog/arch_d7_2008_03_22....
>
> Nice example of what you can do with generators. Is this sort of thing
> doable efficiently in 1.9?

some_date.filter1.filter2.action

What is the advantage of data filters over method chaining in
practical terms? What am I missing?

Regards,

Dan

Joel VanderWerf

3/27/2008 8:23:00 PM

0

Daniel Berger wrote:
>
> On Mar 27, 12:20 pm, "Martin DeMello" <martindeme...@gmail.com> wrote:
>> http://www.voidspace.org.uk/python/weblog/arch_d7_2008_03_22....
>>
>> Nice example of what you can do with generators. Is this sort of thing
>> doable efficiently in 1.9?
>
> some_date.filter1.filter2.action
>
> What is the advantage of data filters over method chaining in
> practical terms? What am I missing?

Apparently, PragDave's filters read one entry at a time, on demand (like
unix pipes). Method chaining has to build a complete collection for each
step.

--
vjoel : Joel VanderWerf : path berkeley edu : 510 665 3407

Sean O'Halpin

3/27/2008 8:25:00 PM

0

On Thu, Mar 27, 2008 at 6:51 PM, Martin DeMello <martindemello@gmail.com> wrote:
>
> Tangentially, why did the trick of defining methods with the same name
> as classes, to delegate to Class.new, fall out of favour?
>
> tripler = Transformer.new {|val| val * 3}
>
> would read more nicely as
>
> tripler = Transformer {|val| val * 3}
>
> with def Transformer(x); Transformer.new(x); end
>
> I remember it being a commoner practice a few years ago.
>
> martin
>
Some of us oldies still use it. But I seem to remember some people
objected last time I suggested it (ruby-talk[160664]).

Regards,
Sean

Joel VanderWerf

3/27/2008 8:44:00 PM

0

Martin DeMello wrote:
> On Thu, Mar 27, 2008 at 11:33 AM, Dave Thomas <dave@pragprog.com> wrote:
>> http://pragdave.blogs.pragprog.com/pragdave/2007/12/pipelines-...
>> http://pragdave.blogs.pragprog.com/pragdave/2008/01/pipelines-...
>
> Tangentially, why did the trick of defining methods with the same name
> as classes, to delegate to Class.new, fall out of favour?
>
> tripler = Transformer.new {|val| val * 3}
>
> would read more nicely as
>
> tripler = Transformer {|val| val * 3}
>
> with def Transformer(x); Transformer.new(x); end
>
> I remember it being a commoner practice a few years ago.
>
> martin

It looks like a typo when there is no method name after (what looks
like) a constant name. There's also the cognitive load of deciding
whether "Transformer.meth" is "send :meth to the result of method
Transformer()" or "send :meth to the value of constant Transformer". My
brain knows it is the latter, but my eyes don't.

class T
def self.meth; "T.meth" end
def meth; "T#meth" end
end
def T; T.new; end

p T.meth
p T().meth
p T.new.meth

Quick, which one(s) are calling the class method, T#meth. But maybe
that's just me.

As long as we're playing in the global space, I'd define a lower case
method, #transformer. Saves a keystroke, too.

--
vjoel : Joel VanderWerf : path berkeley edu : 510 665 3407