min/max operator #66

Closed
satyr opened this Issue Jun 14, 2011 · 4 comments

Projects

None yet

2 participants

@satyr
Owner
satyr commented Jun 14, 2011

http://perlgeek.de/blog-en/perl-5-to-6/27-common-idioms.html#Numbers

<? for min, >? for max (or inverse?)

a <? b  # if a < b then a else b
a >? b  # if a > b then a else b

inRange = lower >? x <? upper

x >?= 0
x <?= 10
assert 0 <= x <= 10
@troyhen
troyhen commented Jun 14, 2011

Why wouldn't you just use more standard, mathematical expressions for in-range comparisons?
in_range = min_exclusive < x < max_exclusive
in_range = min_inclusive <= x < max_exclusive
in_range = min_exclusive < x <= max_inclusive
in_range = min_inclusive <= x <= max_inclusive

@satyr
Owner
satyr commented Jun 14, 2011

Why wouldn't you just use more standard, mathematical expressions for in-range comparisons?
in_range = min_exclusive < x < max_exclusive
...

Those are already working as chained comparisons.

@troyhen
troyhen commented Jun 14, 2011

Good. I thought I read that. I was just commenting on the in-range line.

inRange = lower >? x <? upper

Then what is the purpose of this syntax and how does it differ from this:

inRange = lower < x < upper
@satyr
Owner
satyr commented Jun 14, 2011

what is the purpose of this syntax

Read the Perl 6 article and/or the rest of sample code above?

@satyr satyr closed this in 6bbde55 Jun 15, 2011
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment