Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Python vs Ruby holy war thread

Name: Christy McJesus !DcbLlAZi7U 2005-04-12 13:11

Last week I learned Python. It's not perfect but it's pretty damn cool.
This week I'm starting on Ruby. I've just encountered blocks and I would approve if someone would answer this: are blocks merely an ugly kludge because the author did not know about lambda expressions, or can they do something lambdas can't?

Name: Anonymous 2005-04-13 7:42

It looks somewhat like an absolute value but has no place there
the notation comes from smalltalk, where |variable| denotes a local variable afaik.

Does this mean you can't have more than one block as a parameter to a ruby function?
seems like it, though i haven't bothered much with research. i consider blocks syntactic sugar:

open "file" do |file_obj|
puts file_obj.read
end
instead of, say,
open("file", proc {|f| puts f.read})
or something. of course, there may be more to it but if you really want to find out, ask on the ruby-ml or search the archives: http://blade.nagaokaut.ac.jp/ruby/ruby-talk/index.shtml
ruby/tk objects for example evaluate blocks in the instance's context which i found fairly convenient.
lf = TkLabelFrame.new(top_frame) do text "labelframe" end

if you *do* want to pass more than that, you can still use lambdas. they're called "proc" (or it's synonym "lambda") in ruby-speak.
blafunc = proc {|x,y,z| puts x,y,z; puts "hello"} # { ... } can be replaced with do ... end
blafunc.call "x", "y", "z"
process_file(file, proc {|f| somecode()}, another_proc_obj)
essentially the same as in python/lisp i assume.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List