Google Gruppi non supporta più i nuovi post o le nuove iscrizioni Usenet. I contenuti storici continuano a essere visibili.

an idle question: returning from a nested call

6 visualizzazioni
Passa al primo messaggio da leggere

David Storrs

da leggere,
12 giu 2003, 18:06:4612/06/03
a The Perl6 Language List
So, as I sweat here in the salt mines of C++, longing for the
cleansing joy that Perl(5 or 6, I'd even take 4) is, I find myself
with the following problem:

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

Austin Hastings

da leggere,
12 giu 2003, 18:12:3212/06/03
a David Storrs, The Perl6 Language List

--- David Storrs <dst...@dstorrs.com> wrote:
> So, as I sweat here in the salt mines of C++, longing for the
> cleansing joy that Perl(5 or 6, I'd even take 4) is, I find myself
> with the following problem:
>
> 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);
>
> ...
> }
>

sub Ficp400::SaveRow(Int $p_row)
{
return if IsDeleted($p_row);
}


Austin Hastings

da leggere,
12 giu 2003, 18:13:3412/06/03
a Austin_...@yahoo.com, David Storrs, The Perl6 Language List

But if you really need to make a function out of it, see the C<leave>
keyword.

=Austin

David Storrs

da leggere,
12 giu 2003, 18:38:3612/06/03
a The Perl6 Language List
On Thu, Jun 12, 2003 at 03:12:32PM -0700, Austin Hastings wrote:
>
> sub Ficp400::SaveRow(Int $p_row)
> {
> return if IsDeleted($p_row);
> }


*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

Piers Cawley

da leggere,
16 giu 2003, 12:01:4416/06/03
a The Perl6 Language List
David Storrs <dst...@dstorrs.com> writes:

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

0 nuovi messaggi