It's possible to know a name of a codeblock ? - Clipper
This is a discussion on It's possible to know a name of a codeblock ? - Clipper ; It's possible to know a name of a codeblock ?
Example:
Codeblock1 : = {|| ..........}
Codeblock2 := {||................................}
Test(codeblock1)
Test(codeblock2)
Function test (cblock)
If cblock = "codeblock1" ?????? <-------- How to know the name ?????
.........
Endif
Franz...
-
It's possible to know a name of a codeblock ?
It's possible to know a name of a codeblock ?
Example:
Codeblock1 : = {|| ..........}
Codeblock2 := {||................................}
Test(codeblock1)
Test(codeblock2)
Function test (cblock)
If cblock = "codeblock1" ?????? <-------- How to know the name ?????
.........
Endif
Franz
-
Re: It's possible to know a name of a codeblock ?
Dear albert:
On May 3, 5:11 am, "albert" <alberto.pecchi...@inwind.it> wrote:
> It's possible to know a name of a codeblock ?
>
> Example:
>
> Codeblock1 : = {|| ..........}
> Codeblock2 := {||................................}
>
> Test(codeblock1)
Test("codeblock1")
.... watch for scoping .... must be available to function "Test"
> Test(codeblock2)
Test("codeblock2")
> Function test (cblock)
Not sure if you need a "&cblock" here to force execution...
> If cblock = "codeblock1" ?????? <-------- How to know the name ?????
> .........
> Endif
An alternative would be to access the list of all defined variables,
and compare the codeblock received with the contents of the variable.
Could be slow, inventing your own debugger almost.
David A. Smith
-
Re: It's possible to know a name of a codeblock ?
Hello,
"albert" schreef in bericht
news:4639ee51$0$26322$834e42db@reader.greatnowhere.com...
> It's possible to know a name of a codeblock ?
>
> Example:
>
> Codeblock1 : = {|| ..........}
> Codeblock2 := {||................................}
>
> Test(codeblock1)
> Test(codeblock2)
>
> Function test (cblock)
> If cblock = "codeblock1" ?????? <-------- How to know the name ?????
> .........
> Endif
Consider using an array of codeblocks and work with
its subscript
hth
frank
-
Re: It's possible to know a name of a codeblock ?
Albert
If you wrote the code then you can do whatever you want to test it.
If you didn't write the code then you'll need to explain more about what your trying to achieve.
Eg
> Test( 'CB1', codeblock1)
> Test( 'CB2', codeblock1)
FUNCTION Test( cName, cb )
DO CASE
CASE cName = 'CB!'
x := Eval( cb, /* any required parameters */ )
CASE etc....
--
CYA
Steve
-
Re: It's possible to know a name of a codeblock ?
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
however you can simply agree on what the identifer will be and so long as
everybody abides by the rules that's it's "name." Again as Steve's example
demonstrates you can pass the name along as a parameter.
The other side of the argument is "why would you want to know the name?".
The whole point behind codeblocks is that the code is passed to a routine
that needs to execute it. It shouldn't really be trying to decide what to
do but rather should simply EVAL the codeblock it was handed.
I don't have a direct link but if you drop by: http://www.leylan.com/ and
select the Clipper link and then the "They're Code Blocks" link it will
bring you to an article I wrote in an earlier century on the subject.
Perhaps it can help.
Tom
"albert" <alberto.pecchioni@inwind.it> wrote...
> It's possible to know a name of a codeblock ?
>
> Example:
>
> Codeblock1 : = {|| ..........}
> Codeblock2 := {||................................}
>
> Test(codeblock1)
>
> Test(codeblock2)
>
>
> Function test (cblock)
>
> If cblock = "codeblock1" ?????? <-------- How to know the name ?????
> .........
> Endif
>
> Franz
-
Re: It's possible to know a name of a codeblock ?
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)
---------------------------------------------------
-
Re: It's possible to know a name of a codeblock ?
> 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
-
Re: It's possible to know a name of a codeblock ?
On May 3, 7:11 am, "albert" <alberto.pecchi...@inwind.it> wrote:
> It's possible to know a name of a codeblock ?
>
> Example:
>
> Codeblock1 : = {|| ..........}
> Codeblock2 := {||................................}
>
> Test(codeblock1)
>
> Test(codeblock2)
>
> Function test (cblock)
>
> If cblock = "codeblock1" ?????? <-------- How to know the name ?????
> .........
> Endif
>
> Franz
Well, as far as I can see, what you are asking is simply to know the
NAME of an actual ARGUMENT variable.
But you can research with the following hint: a codeblock is an OBJECT
of the CLASS BLOCK, i. e.
?codeblock:classname() ---------> "BLOCK"
Try with Class(y)'s CSYINSPECT().
Regards,
Marco
Similar Threads
-
By Application Development in forum Clipper
Replies: 24
Last Post: 06-22-2007, 10:54 AM
-
By Application Development in forum xharbour
Replies: 1
Last Post: 06-04-2007, 02:36 AM
-
By Application Development in forum xharbour
Replies: 4
Last Post: 05-21-2007, 02:36 AM
-
By Application Development in forum xharbour
Replies: 0
Last Post: 05-20-2007, 10:44 PM
-
By Application Development in forum xharbour
Replies: 4
Last Post: 05-04-2007, 11:34 AM