views:

345

answers:

6
  1. Does any programming language use =/= for not-equal?
  2. Are there any lexical difficulties for scanners to recognize such an operator? Or was it the case historically?

[Note: this is NOT a homework question. I'm just curious.]

A: 

A google code search for =/= doesn't turn up anything obvious, so I would say nothing mainstream.

There wouldn't be any issues with any operator you want, the computer would simply look for =/= instead of != or <> or whatever your language uses.

There are some really weird languages out there like BrainFuck language (link)

++++++++++[>+++++++>++++++++++>+++>+<<<<-]>++.>+.+++++++..+++.>++.<<+++++++++++++++.>.+++.——.——–.>+.>.

That is code for "Hello World".

SLC
Actually by Google code search I figured out that Erlang has it. It has /= for not equal to, and =/= exactly not equal to.
M.S.
Great, I'm glad the link I provided produced an answer... not sure the negative vote was necessary!
SLC
A: 
  1. None that I know of
  2. Not much harder than any other operator like +=, ??, etc.

However, it's very cumbersome to type such an operator. Even != will be simpler.

Anton Gogolev
+1  A: 
  1. Not one of the mainstream ones. One could easily create such a language, however.
    • (As others have mentioned, Erlang and a few other languages do have it already)
  2. Nope. Unless you have a really weird language, there's nothing special about this operator in terms of lexical analysis.

By the way, Java has:

  • > (greater than)
  • >> (signed right shift)
  • >>= (signed right shift compound assignment)
  • >>> (unsigned right shift)
  • >>>= (unsigned right shift compound assignment)
  • > (closing generic type parameter, nestable)
    • >>, >>>, >>>>, ...

and they all work just fine.

Related question

polygenelubricants
RE: 2. I think I got what you mean by "really weird language": some syntax that would make it ambiguous to recognize =/=, e.g. allowing = or / as literals or something. Has to be quite weird. And thanks for the Java example.
M.S.
IIRC, that specific java example introduces ambiguity. For example, `LinkedList<LinkedList<Integer>>`. The trailing `>>` could either be two nested closing generics, or the right shift operator. I don't know how it figures this out, but I'm pretty sure it's not context free. C++ doesn't allow this (you have to put a space between the two closing template thingies).
rmeador
@rmeador: It works just fine in Java; the parser has a special rule to allow it without space. I'll pull up the reference. Looking for it...
polygenelubricants
I know it works fine. That's not what I'm saying. I'm saying it can't be decided in a context-free way, thus it introduces ambiguity into the grammar, which was something the OP mentioned in the above comment.
rmeador
@rmeador: ...and my point is that the problem is solvable, so it practically doesn't pose any "lexical difficulties". The answer on the question I linked to also mentions that C++ is going to "fix" this soon-ish. It's not a real problem.
polygenelubricants
+14  A: 

Erlang uses it to denote exactly not equal.

Also generally there shouldn't be any difficulties for scanners to recognize such a token (proof by example: Erlang ;-)

Bytecode Ninja
+2  A: 

Yes, Erlang uses this symbol as one of its representations for "not equal".

Erlang is a language with strong support for concurrency, originally designed within Ericsson and used for writing software for telephone exchanges, but now gaining significant popularity outside.

psmears
+6  A: 

In Erlang =/=, as noted by Bytecode Ninja means "exactly not equal to". The notation of Erlang is strongly influenced by Prolog so it should come as no surprise that Prolog uses that operator too. There are several languages which make defining operators trivial. Haskell would be one such. =/= isn't defined in the Haskell standard, but defining it would be trivial:

(=/=) x y = ....

This could then be used in function call-like syntax:

(=/=) 5 6

Or as an inline operator:

5 =/= 6

The semantics would depend on the implementation, of course.

I think that Common Lisp weenies users could write some kind of reader macro that used that sequence too, but I'm not positive.

JUST MY correct OPINION
Thanks for the Prolog link. I can see the similarity between Erlang's operators and Prolog.
M.S.
The better you know either language, the more familiar the other will look (but **not** behave!).
JUST MY correct OPINION
Vatine
I just figured a reader macro was closest in conception to an "operator" in Common Lisp.
JUST MY correct OPINION