From: Christoph (news_chr) Date: 2003-10-05T10:56:59+09:00 Subject: Re: Python syntax in Lisp and Scheme "Grzegorz Chrupa�,a" wrote: .... > > I don't really feel quite qualified discuss Ruby's design decisions wrt the > relation between methods, procedures and objects, but I don't think the > split between methods and objects is as deep as you claim: There is a huge difference between ``garden variety'' Ruby functions, usually called methods, ala def foo() end and Method objects like meth = "meth".method(:foo) The former really ``live'' outside of Ruby's object space, the latter are concrete living breathing objects - i.e. instances of the Method class. --- def enumerate_method_objects cnt = ObjectSpace.each_object(Method) {|mth| p mth } puts "There are #{cnt} Method objects\n\n" end class String def foo self + " hello" end end ## ary = [1,2] ruby = "Ruby" enumerate_method_objects() # no Method object exists ## create two Method objects ary_length = ary.method(:length) ruby_foo = ruby.method(:foo) enumerate_method_objects() # 2 Method object exists ## manipulate the objects ``ary'' and ``ruby'' a bit p ary << 3 # [1, 2, 3] p ruby << " says" # "Ruby says" ## use the method objects p ary_length[] # 3 p ruby_foo[] # "Ruby says hello" ## which is pretty much the same as writing p ary.length() # 3 p ruby.foo() # "Ruby says hello" --- resulting --- There are 0 Method objects # # There are 2 Method objects [1, 2, 3] "Ruby says" 3 "Ruby says hello" 3 "Ruby says hello" --- > I do tend to think that Ruby would be better off with a more unified > treatment of blocks, procedures and methods, but my understanding of the > issues involved is very incomplete. Perhaps Smalltalk experts would be more > qualified to comment on this. By not elevating function (methods) into real objects, you pretty much avoided the problem of users complaining about the lack of higher order function objects:-) /Christoph