Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Message from discussion Ruby: the non-awesome parts
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Andrew Grimm  
View profile  
 More options Jun 16 2011, 8:58 am
From: Andrew Grimm <andrew.j.gr...@gmail.com>
Date: Thu, 16 Jun 2011 22:58:05 +1000
Local: Thurs, Jun 16 2011 8:58 am
Subject: Re: [rails-oceania] Re: Ruby: the non-awesome parts

On Thu, Jun 16, 2011 at 8:20 PM, Mark Wotton <mwot...@gmail.com> wrote:

> On Thu, Jun 16, 2011 at 7:51 PM, Andrew Grimm <andrew.j.gr...@gmail.com>
> wrote:

>> On 15/06/2011, at 6:33 PM, Gregory McIntyre <bluep...@gmail.com> wrote:

>> > x = proc{|a| a*2 }; [1,2,3].map(&x) # explain why you can't call
>> > map(x).

>> I'd be curious about how you would handle Array.new(10, x) where x could
>> be either a proc or an object? (not to mention that procs are objects!)

> This is a bad argument. You should be able to treat functions just as normal
> values - the weird soup of procs, lambdas and "proper" functions that Ruby
> has is a bit of a hack.
> Languages that treat functions as unproblematic values collapse all this
> complexity down to almost nothing.

I'm not understanding what you're saying.

Given

x = proc {|a| a * 2}
[1,2,3].fancy_map(x)

you'd have to have

module Enumerable
  def fancy_map(x)
    result = []
    each do |element|
      result << x.call(element)
    end
    result
  end
end

that in of itself is fairly innocuous. but what about Array.new ?

There's three forms of Array.new currently:

Array.new(size=0, obj=nil)
Array.new(array)
Array.new(size) {|index| block }

For the purposes of this discussion, we don't have to worry about
Array.new() or Array.new(existing_array). Under the current syntax, we
can do the following:

x = proc {|a| a * 2}
Array.new(3, "close to deadline") # Works, gives ["close to deadline",
"close to deadline", "close to deadline"]
Array.new(3, &x) # Works, gives [0, 2, 4]
Array.new(3, x) # Less common but works, gives [a_proc_proc_here,
a_proc_proc_there, here_a_proc_there_a_proc_everywhere_a_proc_proc]

But what'd happen if you banned the lambda? You'd either not be able
to do the equivalent of Array.new(3, &x), or you wouldn't be able to
do the equivalent of Array.new(3, x)

I'm not sure what approach Haskell takes with this, however. Perhaps
it manages to handle this issue easily.

Andrew


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.