Chr. Rippel [mailto:chr_news / gmx.net] wrote:

> <ntalbott / rolemodelsoft.com> wrote in
> ....
> > > Current implementation converts Proc <-> Block for each time,
> > > so that &var Proc is generated each time.  This might change 
> > > in the future, but I cannot ensure the hash (or identity)
equality.
> > 
> > This breaks POLS for me in a big way (but maybe not for you). I
expect 
> > the block to remain the same whether I pass it in through the 
> > arguments as an object, or whether I use & to associate it directly 
> > with the method call. I can see why, implementation-wise, it might
be 
> > easier to make them different, but I can't see from a user's 
> > perspective how the behavior makes sense.
>
> I guess by now I expect my POLS to be broken, in particular 
> when comes to issue of hashing.  

I guess it's not so much the hashing that surprises me... it's that
passing procs using & changes the procs. That, for me, is surprising. It
seems that it doesn't change their behavior, so it shouldn't change
their identity.


> > to go with a less attractive alternative, but I guess I'm looking 
> > either for more of an explanation or a fix. I'd submit an RCR for it

> > if you think it's worthwhile.
> 
> If it was me I would be trying to avoid envoking the 
> proc <-> conversion.

But that's one of the things I love most about Ruby! The 'method { block
}' syntax is very pleasing to me, so it makes me ask questions when it
doesn't work for my application. At this point, I'm just trying to
understand why the behavior is as it is, and not the way I expect.


> Of course there is some sort of fix - 
> which is likely very dangerous (you probably can improve 
> on it though)
> 
> ---
> P = proc {P}
> def bla(a, & b)
>    hsh = { a => 3}
>    p hsh[b]
> end
> 
> class Proc
>   def hash
>     inspect.sub(/^(#<Proc:)/){''}.sub(/(>)$/){''}.to_i(16)
>   end
>   def eql?(other)
>     unless other.instance_of? (type)
>       false
>     else
>       hash == other.hash
>     end
>   end
> end
> 
> bla (P,&P) # => 3

Ah, yes, I thought about this. I might end up doing it, or something
like it that uses a wrapper instead of modifying Proc itself. Is there a
more direct way to access the id than using a regular expression?

Thanks for your input/ideas.


Nathaniel

<:((><
+ - -
| RoleModel Software, Inc.
| EQUIP VI