ok, it didn't look like nested methods. But I made to believe that
this:

sum<=square*deviation|a

is exactly the same as this:

sum<=(square*(deviation|(a)))

So if this is true, then still a question remains.

Here's the original context again:


module Functional

  def compose(f)
    if self.respond_to?(:arity) && self.arity == 1
      lambda { |*args| self[f[*args]] }
    else
      lambda {|*args| self[*f[*args]] }
    end
  end
  alias * compose


  def apply(enum)
    enum.map &self
  end
  alias | apply

  def reduce(enum)
    enum.inject &self
  end
  alias <= reduce

end

class Proc
  include Functional
end

#client code
a = [1,2,3]
sum = lambda { |x,y| x+y }
mean = (sum<=a)/a.size
deviation = lambda { |x| x-mean }
square = lambda { |x| x*x }
standardDeviation = Math.sqrt((sum<=square*deviation|a)/(a.size-1))

On the last line, this executes first:

deviation|a

this returns a new array of how far each of elements are from the
mean.

Then this array gets passed to * which is invoked on square (a lambda
object):

square*returned_array

That calls compose where f parameter is the returned array from above.
So then this line is returned by compose since the array object doesnt
respond to arity:

lambda {|*args| self[*f[*args]] }

So it appears the return value of compose is the lambda object. That
presents a problem because <= expects an enum argument.

sum<=this_should_be_an_enum


On Dec 23, 3:14 am, 7stud -- <li...@ruby-forum.com> wrote:
> In this method call:
>
> meth1(meth2(meth3))
>
> ...which value has has to be computed first so that meth1 can return?
>
> --
> Posted viahttp://www.ruby-forum.com/.

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to