Re: an idle question: returning from a nested call

2003-06-16 Thread Piers Cawley
David Storrs [EMAIL PROTECTED] writes:

 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
 Ccaller object would have something that would allow me to jump to
 the right point (i.e., caller[2]).

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 Cgiven

-- 
Piers


an idle question: returning from a nested call

2003-06-12 Thread David Storrs
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
Ccaller object would have something that would allow me to jump to
the right point (i.e., caller[2]).

Just an idle thought,

--Dks


Re: an idle question: returning from a nested call

2003-06-12 Thread Austin Hastings

--- David Storrs [EMAIL PROTECTED] 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);
}




Re: an idle question: returning from a nested call

2003-06-12 Thread Austin Hastings

--- Austin Hastings [EMAIL PROTECTED] wrote:
 
 --- David Storrs [EMAIL PROTECTED] 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);
 }

But if you really need to make a function out of it, see the Cleave
keyword.

=Austin



Re: an idle question: returning from a nested call

2003-06-12 Thread David Storrs
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 Cleave.

Yeesh.  Looks like I need to go back and reread A6 for a third time.
I obviously didn't understand it well enough.


--Dks