George
2/14/2007 1:42:00 AM
On 2/13/07, Edwin Fine <efine145-nospam01@usa.net> wrote:
> Here's the C code for proc_eq (in eval.c). It seems that the procs have
> to either be the same object, or failing that have the same type
> (T_DATA), class, body, variables, scope, in-block local variables
> (dyna_vars), and flags.
>
> static VALUE
> proc_eq(self, other)
> VALUE self, other;
> {
> struct BLOCK *data, *data2;
>
> if (self == other) return Qtrue;
> if (TYPE(other) != T_DATA) return Qfalse;
> if (RDATA(other)->dmark != (RUBY_DATA_FUNC)blk_mark) return Qfalse;
> if (CLASS_OF(self) != CLASS_OF(other)) return Qfalse;
> Data_Get_Struct(self, struct BLOCK, data);
> Data_Get_Struct(other, struct BLOCK, data2);
> if (data->body != data2->body) return Qfalse;
> if (data->var != data2->var) return Qfalse;
> if (data->scope != data2->scope) return Qfalse;
> if (data->dyna_vars != data2->dyna_vars) return Qfalse;
> if (data->flags != data2->flags) return Qfalse;
>
> return Qtrue;
> }
Hmm, so my earlier comment about empty blocks was wrong. You can
actually have unequal empty blocks if you define them in different
contexts...:
def foo(x)
lambda{}
end
lambda{} == foo(1) #=> false
... or with different flags. The return semantics (Proc.new vs.
lambda) is stored as a flag, hence (as Gary noted):
Proc.new{} == lambda{} #=> false
As you pointed out in your other post, body, vars, and dyna_vars seem
to be NULL for empty blocks.
Regards,
George.