Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

junctions vs English negatives.

13 views
Skip to first unread message

Larry Wall

unread,
May 14, 2005, 12:31:29 PM5/14/05
to perl6-l...@perl.org
We have a bit of a problem with negative operators applied to junctions,
as illustrated recently on PerlMonks. To wit, when a native English
speaker writes

if $a != 1 | 2 | 3 {...}

they really mean one of:

if not $a == 1 | 2 | 3 {...}
if $a == none(1, 2, 3) {...}

or, expressed in current understanding of negated ops:

if $a != 1 & 2 & 3 {...}
if $a != all(1, 2, 3) {...}

They specifically do *not* mean

if $a != any(1,2,3) {...}

since that would always be true.

I don't think we can allow this situation to stand. Either we have
to make != and !~ and ne transform themselves via "not raising", or
we have to disallow negative comparisons on junctions entirely.

Opinions?

Larry

Jonathan Scott Duff

unread,
May 14, 2005, 12:48:14 PM5/14/05
to perl6-l...@perl.org
On Sat, May 14, 2005 at 09:31:29AM -0700, Larry Wall wrote:
> I don't think we can allow this situation to stand. Either we have
> to make != and !~ and ne transform themselves via "not raising", or
> we have to disallow negative comparisons on junctions entirely.

I'm of the opinion that disallowing negative comparison on junctions
is the best way to go. If I were better at this forensics stuff, I'd
have a cogent argument to backup my position, but as it is all I can
think of right now is this: if we make != comparison illegal on
junctions, perl can give the programmer a helpful message when they
forget whereas the other way, they just get unexpected behavior if
they forget that != does something different than usual.

-Scott
--
Jonathan Scott Duff
du...@pobox.com

Rod Adams

unread,
May 14, 2005, 2:09:04 PM5/14/05
to perl6-l...@perl.org
Larry Wall wrote:

>We have a bit of a problem with negative operators applied to junctions,
>as illustrated recently on PerlMonks. To wit, when a native English
>speaker writes
>
> if $a != 1 | 2 | 3 {...}
>
>they really mean one of:
>
> if not $a == 1 | 2 | 3 {...}
> if $a == none(1, 2, 3) {...}
>
>or, expressed in current understanding of negated ops:
>
> if $a != 1 & 2 & 3 {...}
> if $a != all(1, 2, 3) {...}
>
>They specifically do *not* mean
>
> if $a != any(1,2,3) {...}
>
>since that would always be true.
>
>

unless $a = none(1,2)

>I don't think we can allow this situation to stand. Either we have
>to make != and !~ and ne transform themselves via "not raising", or
>we have to disallow negative comparisons on junctions entirely.
>
>Opinions?
>
>

I go with option 2b: leave the syntax the way it is, but fire off a
warning, not an error when someone does this.

-- Rod Adams


Damian Conway

unread,
May 14, 2005, 6:32:18 PM5/14/05
to Larry Wall, perl6-l...@perl.org
Larry wrote:

> I don't think we can allow this situation to stand. Either we have
> to make != and !~ and ne transform themselves via "not raising", or
> we have to disallow negative comparisons on junctions entirely.
>
> Opinions?

Making them DWIM here would be a mistake, since the dwimmery would disappear
if anyone refactored:

if $note != $do | $re | $me {...}

to the supposedly identical:

if $note != $do || $note != $re || $note != $me {...}

That would be a bad outcome...pedagogically as well as from a maintainability
point-of-view.

I'd say we have to disallow negative comparisons against explicit
(compile-time) junctions. That is, against expressions that explicitly use
|/&/^ or any/all/one/none.

Negative comparisons against implicit (run-time) junctions:

if $note != $bad_note {...}

still have to be allowed.

Damian

Luke Palmer

unread,
May 15, 2005, 5:48:52 PM5/15/05
to Damian Conway, Larry Wall, perl6-l...@perl.org
On 5/14/05, Damian Conway <dam...@conway.org> wrote:
> Larry wrote:
>
> > I don't think we can allow this situation to stand. Either we have
> > to make != and !~ and ne transform themselves via "not raising", or
> > we have to disallow negative comparisons on junctions entirely.
> >
> > Opinions?
>
> Making them DWIM here would be a mistake, since the dwimmery would disappear
> if anyone refactored:
>
> if $note != $do | $re | $me {...}
>
> to the supposedly identical:
>
> if $note != $do || $note != $re || $note != $me {...}
>
> That would be a bad outcome...pedagogically as well as from a maintainability
> point-of-view.

Hmm. I'll just that if != is implemented like this:

multi sub infix:<!=> (Any|Junction $a, Any|Junction $b) {
!($a == $b);
}

Then it Just Works.

Luke

Ashley Winters

unread,
May 15, 2005, 6:55:57 PM5/15/05
to Perl6 Language List
On 5/15/05, Luke Palmer <lrpa...@gmail.com> wrote:
> multi sub infix:<!=> (Any|Junction $a, Any|Junction $b) {
> !($a == $b);
> }
>
> Then it Just Works.

Also, that's the right way to provide a working != for any object
which defines ==. We all want that, right?

Ashley Winters

Damian Conway

unread,
May 15, 2005, 8:37:13 PM5/15/05
to perl6-l...@perl.org
Luke wrote:

> Hmm. I'll just [mention] that if != is implemented like this:


>
> multi sub infix:<!=> (Any|Junction $a, Any|Junction $b) {
> !($a == $b);
> }
>
> Then it Just Works.

I'd be fine with the dwimmy version if that is the underlying rule, since then
the behaviour isn't a special case, and it's easy to explain that the magic of
the C<!=> is being applied before the magic of junctions.

Damian

Larry Wall

unread,
May 15, 2005, 9:11:18 PM5/15/05
to perl6-l...@perl.org

Heh, I knew if I waited long enough I'd see arguments for both sides.
Okay, let's go with the "not raising". Ain't lingristiks wunnerfle.

Larry

0 new messages