Michael Lazzaro wrote:
On Sunday, January 19, 2003, at 09:51  PM, Luke Palmer wrote:

From: "Sean O'Rourke" <[EMAIL PROTECTED]>
On Sat, 18 Jan 2003, Michael Lazzaro wrote:

So 'if' and friends are just (native) subroutines with prototypes like:
IIRC it's not that pretty, unfortunately, if you want to support this:
That is not a problem:
<snipped>

Yeah, a three-argument form would easily allow chaining. But of course it still doesn't do the appropriate syntax checking (C<else> outside of C<if>, etc.). (It's only speculation on our part, of course, but Damian's response was quite intriguing -- he seemed to imply they had a solution that would work.)
Would this work?

class True is Bool is singleton {
  method isTrue(&block) { &block.apply(); };
  method isFalse(&block) { };
}

class False is Bool is singleton {
  method isTrue(&block) { };
  method isFalse(&block) { &block.apply(); };
}

class ElseCode is Code {};

our True true is builtin;
our False false is builtin;

sub if (Bool $test, Code $block) { $test.isTrue($block); };
sub if (Bool $test, Code $ifblock, ElseCode $elseblock)
  { $test.ifTrue($ifblock); $test.ifFalse($elseblock); };
sub unless (Bool $test, Code $block) {$test.isFalse($block);};
sub unless (Bool $test, Code $ifblock, ElseCode $elseblock)
  { $test.ifFalse($ifblock); $test.ifTrue($elseblock); };

sub else (Code $block) returns ElseBlock { $block };
sub elseif (Bool $test is lazy, Code $block)
  { if $test, $block; };
sub elseif (Bool $test is lazy, Code $block, ElseCode $elseblock)
  {if $test, $block, $elseblock;};

etc...




Reply via email to