[% setvar title Operators: Multiway comparisons %]

This file is part of the Perl 6 Archive

Note: these documents may be out of date. Do not use as reference!

To see what is currently happening visit http://www.perl6.org/


Operators: Multiway comparisons


  Maintainer: Damian Conway <damian@conway.org>
  Date: 4 Aug 2000
  Last Modified: 18 Sep 2000
  Mailing List: perl6-language@perl.org
  Number: 25
  Version: 2
  Status: Frozen


This RFC proposes that multiway comparisons such as:

	if ( 0 <= $x < 10 ) {
		print "digit"

should do what the user means.


It is proposed that expressions involving multiple chained comparisons should be automagically expanded to the equivalent binary conjunction. That is:

	0 <= $x < 10

is DWIMmed to:

	0 <= $x && $x < 10

Furthermore, it is proposed that any operations, function calls, or subroutine invocations should only be performed once in such expansions and that such expansions should short-circuit on failure. That is:

	$min < nextval() < $x+$y < length $string

should become:

	do {
		my $tmp1, $tmp2;
		$min < do{$tmp1=nextval} &&
		$tmp1 < do{$tmp2=$x+$y} &&
		$tmp2 < length $string;


As described above