From: "Mauricio Fernández" Date: 2003-03-27T18:00:09+09:00 Subject: Re: What are the differences between Ruby's blocks and Python's lambdas? On Thu, Mar 27, 2003 at 05:17:47AM +0900, Paul Brannan wrote: > On Thu, Mar 27, 2003 at 04:40:40AM +0900, Mauricio Fern�ndez wrote: > > Do you know if any optimization is done on access to outer scope > > locals? That looks nice but apparently slow (construction of a dict, > > copying table of locals...) > > I don't know for sure, but I suspect that it's not much slower than > Ruby. Ruby does quite a lot behind the scenes when a Proc is > constructed. I had the feeling Ruby could be faster essentially *because* the work happens behind the scenes, ie at C speed :-). For instance ruby can transform variable names into symbols as it creates the AST (not really sure about this, but could be possible), whereas it seems in Python this must be done at run time, on each access to the table of locals. > I don't think the table of locals is copied; only the reference to the > table of locals should be copied. Believe you're right :) > > how do I call a Method object the same way as a lambda? > > l = lambda { |x| x + 42} > > def foo(x); return x + 42; end > m = Object.method(:foo) > > p l.call(42) #=> 84 > p m.call(42) #=> 84 ahah, I was thinking the other way around, sorry :-) Something like "how do I call a proc the same way as a method (downcase)?" ie., some way to do pp = proc { |x| x + 1 } .... MAGIC .... pp(1) -- _ _ | |__ __ _| |_ ___ _ __ ___ __ _ _ __ | '_ \ / _` | __/ __| '_ ` _ \ / _` | '_ \ | |_) | (_| | |_\__ \ | | | | | (_| | | | | |_.__/ \__,_|\__|___/_| |_| |_|\__,_|_| |_| Running Debian GNU/Linux Sid (unstable) batsman dot geo at yahoo dot com It's easy to get on the internet and forget you have a life -- Topic on #LinuxGER