Is "=!" ever legal?
November 13, 2007 11:02 AM   RSS feed for this thread Subscribe

Is there any programming language in which "=!" is a (or even the) correct way of testing for inequality? All the languages I know test for inequality using "!=" or something completely unrelated.
posted by caek to computers & internet (21 comments total) 1 user marked this as a favorite
IANAP, but a == !b (a is equal to not-b) is close and common in a lot of languages. The way you're describing doesn't really make a lot of sense to me syntactically. Could be just me though.
posted by Plug Dub In at 11:10 AM on November 13, 2007


exactly: =! would more likely be a negative assignment than anything else. mindestens, in the more than a few languages I know.

of course, you could always write your own interpreter/compiler atop an existing one; to provide this, er, functionality.

!(a==b) ftw
posted by dorian at 11:20 AM on November 13, 2007


A language with a "=" equality operator (Pascal) would accept a=!b, meaning a equals not b. Dang it, Pascal uses the word NOT instead of !. Maybe a BASIC variant could do it, since BASIC uses = for both equality and assignment.
posted by ALongDecember at 11:28 AM on November 13, 2007


Maybe a BASIC variant could do it, since BASIC uses = for both equality and assignment.

I'm pretty sure all BASIC variants use NOT instead of !, just as Pascal does.
posted by cerebus19 at 11:45 AM on November 13, 2007


I think =! is never used as a comparison. It's totally legal in C to say

int a, b;

a =! b;

but it assigns some crap to a.
posted by aubilenon at 11:55 AM on November 13, 2007


Not the answer, but I feel compelled to comment here that pre-ANSI versions of C sometimes recognized =+ as a synonym for +=. The unary + operator killed that.
posted by Nelson at 12:11 PM on November 13, 2007


I read that as "a equals not b", which means what we need to find here is an archaic, and preferably Shakespearean, language.

There is also <> and the rare (?) ><.
posted by rokusan at 12:24 PM on November 13, 2007


what we need to find here is an archaic, and preferably Shakespearean, language

I'm thinking it's more along the lines of how Yoda might program.
posted by cerebus19 at 12:43 PM on November 13, 2007 [2 favorites]


It's been a while, but I think thinking that Visual C++, VB, or PHP4 might allow it as a usability function. I could be wrong though, it's been a long time.
posted by TomMelee at 12:49 PM on November 13, 2007


If you consider whitespaces as optional a=!b could mean both assignment a= !b and comparison a =! b. That won't do.
posted by Free word order! at 12:49 PM on November 13, 2007


To get back to the actual question: I'm almost 100% certain there is no language in use today that has an operator "=!" meaning "not equal." Th reason for this can be expressed simply as this: The languages that have the "!=" operator typically also use "!" to mean "not," and, even if they don't, that's clearly the intended meaning when it's placed before the equals sign. So "!=" is easily parsed as "not equal to."

If talking about "<>=", and "<>", order matters less, because the two symbols are being OR-ed together. It is fairly clear that "><>", but not at all clear that "=!" has the same meaning as "!=". This would be true even if "=" didn't also have its other purpose as an assignment operator. If a language had an operator "!<", meaning "not less than," it wouldn't make sense to reverse it to "<!", because negation only makes sense before the thing being negated.
posted by cerebus19 at 12:50 PM on November 13, 2007


D'oh! I forgot about less than signs! Sorry. The first sentence in the second paragraph should read:

If talking about "<=", ">=", and "<>", order matters less, because the two symbols are being OR-ed together. It is fairly clear that "><" means the same thing as "<>", but not at all clear that "=!" has the same meaning as "!="
posted by cerebus19 at 12:53 PM on November 13, 2007


negation only makes sense before the thing being negated.

Does not.
posted by rokusan at 1:34 PM on November 13, 2007 [4 favorites]


I think for this purpose we should revert to the more usual meaning of "!". So =! should mean "equal but surprisingly so", ie:
ei*pi =! -1

posted by flug at 1:48 PM on November 13, 2007 [3 favorites]


Well if you let "!" mean factorial, this still works:

ei*pi = -1!
posted by null terminated at 3:14 PM on November 13, 2007


Well, wouldn't a Shakespearean try be:
2b || !2b
posted by MtDewd at 3:22 PM on November 13, 2007 [1 favorite]


In C++:

int x = 10;
int y = 9;

x =! y;

results in x == 0;
posted by trinity8-director at 4:07 PM on November 13, 2007


Adding to what Cerebus19 says, if the language uses ! for negation and = for assignment, =! will be tokenized as assignment followed by negation, instead of an inequality operator. So this hypothetical language would either have to drop ! as a unary negation operator (in which case =! becomes a weirder way to express a check for inequality), or not support assignment with =.
posted by Horselover Fat at 8:09 PM on November 13, 2007


C++?

On preview/reading carefully, what trinity8 said
posted by misterbrandt at 8:32 PM on November 13, 2007


This works as expected with moiftNums

#include
using namespace std;

class moiftNum
{
public:
moiftNum(const long val) : val(val) { }
bool operator=(const moiftNum& nm) const
{
return (nm.val != this->val);
}
moiftNum& operator!() { return *this; }
private:
long val;
};

int main(int, char**)
{
moiftNum a(9), b(9), c(10);
std::cout <> }

posted by moift at 8:13 AM on November 16, 2007


ah crap, I got foiled on the last line. it was supposed to print ((a =! b) ? "not equal" : "equal") and ((a =! c) ? "not equal" : "equal")
posted by moift at 8:14 AM on November 16, 2007


« Older My first ever laptop makes a s...   |   I'm getting an iPod for my 10 ... Newer »
This thread is closed to new comments.