------art_37612_15120926.1225471974095
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

On Fri, Oct 31, 2008 at 10:08 AM, David A. Black <dblack / rubypal.com> wrote:

> On Sat, 1 Nov 2008, Jacob Fugal wrote:
>
>  Thinking about it more, I realize that would make the ary.inject(:foo)
>> usage
>> inconsistent, as :foo would be interpreted as "initial" rather than
>> "block".
>> The error is basically saying: "You didn't provide a block, so I was going
>> to try using the first argument as a proc, but it wasn't a proc, nor was
>> it
>> a Symbol that I could convert into a proc." -- so it *was* complaining
>> about
>> a missing block parameter, but only implicitly.
>>
>> Perhaps rather than checking for a Symbol explicitly, just check for
>> #responds_to?(:to_proc)? If it does, call it and use the result as the
>> block. If not, the error message could say something like "TypeError: 0
>> cannot be converted to a Proc".
>>
>
> I thought that the idiom was (&:sym), not just (:sym). I certainly
> would expect a non-& argument to inject to be the initial value for
> the accumulator and not magically converted to something else. If
> there's no block I think I would expect this:
>
>  obj.inject(other_object)
>
> to mean this:
>
>  obj.enum_for(:inject, other_object)
>
> Special-casing symbols like that seems much too magic and restrictive
> to me.


I agree wholeheartedly.

I was not previously aware of a obj.inject(:sym) usage, but that's the only
sense I could make of the error. My original off-the-cuff hypothesis that
the error stemmed from inside Symbol#to_proc makes absolutely no sense on
second inspection, so it must be the inject method that's checking for a
symbol. Sure enough, the rdoc at
http://redmine.ruby-lang.org/repositories/entry/ruby-19/enum.c#L449indicates
such special treatment for Symbols as the sole argument and the
error raised stems from the call to rb_to_id that occurs at line 507.

Jacob Fugal

------art_37612_15120926.1225471974095
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

On Fri, Oct 31, 2008 at 10:08 AM, David A. Black <span dirtr">&lt;<a hrefailto:dblack / rubypal.com">dblack / rubypal.com</a>&gt;</span> wrote:<br><div classmail_quote"><blockquote classmail_quote" styleorder-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<div><div classj3C7c">On Sat, 1 Nov 2008, Jacob Fugal wrote:<br>
<br>
<blockquote classmail_quote" styleorder-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
Thinking about it more, I realize that would make the ary.inject(:foo) usage<br>
inconsistent, as :foo would be interpreted as &quot;initial&quot; rather than &quot;block&quot;.<br>
The error is basically saying: &quot;You didn&#39;t provide a block, so I was going<br>
to try using the first argument as a proc, but it wasn&#39;t a proc, nor was it<br>
a Symbol that I could convert into a proc.&quot; -- so it *was* complaining about<br>
a missing block parameter, but only implicitly.<br>
<br>
Perhaps rather than checking for a Symbol explicitly, just check for<br>
#responds_to?(:to_proc)? If it does, call it and use the result as the<br>
block. If not, the error message could say something like &quot;TypeError: 0<br>
cannot be converted to a Proc&quot;.<br>
</blockquote>
<br></div></div>
I thought that the idiom was (&amp;:sym), not just (:sym). I certainly<br>
would expect a non-&amp; argument to inject to be the initial value for<br>
the accumulator and not magically converted to something else. If<br>
there&#39;s no block I think I would expect this:<br>
<br>
 &nbsp;obj.inject(other_object)<br>
<br>
to mean this:<br>
<br>
 &nbsp;obj.enum_for(:inject, other_object)<br>
<br>
Special-casing symbols like that seems much too magic and restrictive<br>
to me.</blockquote></div><br>I agree wholeheartedly.<br><br>I was not previously aware of a obj.inject(:sym) usage, but that&#39;s the only sense I could make of the error. My original off-the-cuff hypothesis that the error stemmed from inside Symbol#to_proc makes absolutely no sense on second inspection, so it must be the inject method that&#39;s checking for a symbol. Sure enough, the rdoc at <a hrefttp://redmine.ruby-lang.org/repositories/entry/ruby-19/enum.c#L449">http://redmine.ruby-lang.org/repositories/entry/ruby-19/enum.c#L449</a> indicates such special treatment for Symbols as the sole argument and the error raised stems from the call to rb_to_id that occurs at line 507.<br>
<br>Jacob Fugal<br>

------art_37612_15120926.1225471974095--