Frequently, I find myself writing stuff like this:
void Ficp400::SaveRow(long p_row)
{
// if p_row is marked as deleted, return
if (GetStatus(row) & FLX_ROW_DELETE) { return; }
...
}
As a general rule, I don't like comments. When I see a comment, I
want to turn it into a function name. So, I keep wanting to be able
to write the above code like so:
void Ficp400::SaveRow(long p_row)
{
Return_If_Is_Deleted(p_row);
...
}
Now, in C++ (or P6, FTM), I could make this work via a macro, but
that's ugly. In P6, I could make it work by passing the current
continuation down to Return_If_Is_Deleted and call the continuation if
the row is in fact deleted, but that will require an extra param. Is
there a way to make it work as written? I'm thinking maybe the
C<caller> object would have something that would allow me to jump to
the right point (i.e., caller[2]).
Just an idle thought,
--Dks
sub Ficp400::SaveRow(Int $p_row)
{
return if IsDeleted($p_row);
}
But if you really need to make a function out of it, see the C<leave>
keyword.
=Austin
*laugh* Well, yes, there is always the obvious way. I had wanted
something that would be reusable between multiple function, though
(sorry, should have said that explicitly).
I guess I got too caught up in the specific example; what I was really
curious about is if there was a way to skip up the stack on return.
And the answer, I see, is yes. Thanks for pointing me at C<leave>.
Yeesh. Looks like I need to go back and reread A6 for a third time.
I obviously didn't understand it well enough.
--Dks
Something in Damian's talk this morning reminded me that:
void Ficp400::SaveRow(long p_row) {
when row_is_deleted { }
...
}
Will do a magic return. I do wonder if it'll simply return from
SaveRow, or from the innermost enclosing C<given>
--
Piers