Home > Archive > Clipper > May 2007 > Re: It's possible to know a name of a codeblock ?
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Re: It's possible to know a name of a codeblock ?
|
|
| diogenes 2007-05-04, 9:55 pm |
| On May 4, 4:30 pm, "Tom Leylan" <tley...@nospam.net> wrote:
> Hi Albert uhh, Franz :-)
>
> Codeblocks are also known as "anonymous methods" which my definition means
> they have no name. So the answer is "no". As Steve Quinn points out . . .
I think that is correct. The answer is no.
I have wanted to do this, and it doesn't work:
I believe that code blocks are "reference variables"
in the same sense that arrays are. If you write:
bBlock1 := { | whatever | whatever . . . }
then write:
bBlock2 := bBlock1
then does this create a second copy of the
code block in the second variable? Or do we
simply have two variables pointing to the
same code block? I have always assumed
the latter -- that we have two variables pointing
to the same place. After all, arrays work that way.
And if you pass a code block as an argument to
a function, does it actually make a copy of the
code block, or just pass a reference? Again,
I assume it just passes a reference.
Now, here is what I tried to do once: I wanted
to know if two variables "contained" (that is,
pointed to) the same code block or to different
code blocks. So I tried:
if ( bBlock1 = bBlock2 ) ..........
and found that this does NOT work. When
I try to compare two variables that both
contain code blocks, I get a run-time error.
This happens whether the two variables in
fact are the same code block or not. I did
not find a way to make this work, other than
to simply keep track separately of what
code block was where and rely on that.
-- J. J. (diogenes)
---------------------------------------------------
| |
| Ron Pinkas 2007-05-05, 6:55 pm |
| > I believe that code blocks are "reference variables"
> in the same sense that arrays are. If you write:
> bBlock1 := { | whatever | whatever . . . }
> then write:
> bBlock2 := bBlock1
> then does this create a second copy of the
> code block in the second variable?
No.
> Or do we
> simply have two variables pointing to the
> same code block?
Yes.
> I have always assumed
> the latter -- that we have two variables pointing
> to the same place. After all, arrays work that way.
> And if you pass a code block as an argument to
> a function, does it actually make a copy of the
> code block, or just pass a reference?
It's a copy of the variable, which points to the same codeblock value. It's
not really a refernce variable, in that that changes to the named argument
will NOT be projected to the caller.
> Again,
> I assume it just passes a reference.
>
> Now, here is what I tried to do once: I wanted
> to know if two variables "contained" (that is,
> pointed to) the same code block or to different
> code blocks. So I tried:
> if ( bBlock1 = bBlock2 ) ..........
> and found that this does NOT work. When
> I try to compare two variables that both
> contain code blocks, I get a run-time error.
> This happens whether the two variables in
> fact are the same code block or not. I did
> not find a way to make this work, other than
> to simply keep track separately of what
> code block was where and rely on that.
In xHarbour we extended == operator to support Codeblocks. I believe it was
a simple omission in Clipper.
Ron
|
|
|
|
|