Does any language use "=/=" for denoting the not-equal operator
- Does any programming language use
=/=
for not-equal? - 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.]
Erlang uses it to denote exactly not equal to.
Also generally there shouldn't be any difficulties for scanners to recognize such a token (proof by example: Erlang ;-)
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.
- 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)
- 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
- What trick does Java use to avoid spaces in >> ?
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.
You may want to check out Fortress Introductory Slides. Fortess uses =/= for checking inequality. I suppose you look for readability in languages. If that's the case then I can tell that Fortess code can be rendered into very neat looking TeX.
Project Fortress Old Site (moved to java.net)
- None that I know of
- Not much harder than any other operator like
+=
,??
, etc.
However, it's very cumbersome to type such an operator. Even !=
will be simpler.
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".
精彩评论