History of not equal ("~=")

194 views
Skip to first unread message

Lars Müller

unread,
Apr 22, 2025, 1:29:28 PMApr 22
to lu...@googlegroups.com
Hi,

I recently stumbled upon a meme which claims that

> "not equal to" is "~=" in Lua because it's [sic!] creator was often
mistyping "!"

Now, from what I know about Lua's history, this doesn't pass the sniff
test, because Lua was designed by three people.
And I could not find any good source to back up this claim either.

I figured I have a chance of getting an authoritative answer (and maybe
some interesting anecdotes) on this list so here I am 🙂

What is the history behind the choice?

- Lars

Sainan

unread,
Apr 22, 2025, 1:48:03 PMApr 22
to lu...@googlegroups.com
My understanding is that ~= comes from mathematics (as you will e.g. find the same operator in Matlab) and some 40 years ago when the decision was made, it may have been most natural way to represent this operation.

-- Sainan

Francisco Olarte

unread,
Apr 22, 2025, 2:25:49 PMApr 22
to lu...@googlegroups.com
On Tue, 22 Apr 2025 at 19:48, 'Sainan' via lua-l <lu...@googlegroups.com> wrote:
> My understanding is that ~= comes from mathematics (as you will e.g. find the same operator in Matlab) and some 40 years ago when the decision was made, it may have been most natural way to represent this operation.

Doing math in paper / blackboard I normally saw slashed equal ( /
composed with = ) as not equal, and ~=, which my input method
unhelpfully ( for lua c) componses to ≃, as approximately equal (
which is not too mathy, is more when calculating engineering and other
things ). But it has been a long time, whiteboards where a novelty, we
used white chalk on black.

Francisco Olarte

Родион Горковенко

unread,
Apr 26, 2025, 3:20:27 AMApr 26
to lu...@googlegroups.com
I don't know the answer but it's pretty probable that the language was created when the
version with exclamation mark haven't yet become "mainstream". If you have a careful
look it is /= in erlang, haskell and later fortran, <> in pascal and basic. Lua's version is definitely
used by Matlab and Octave. Of course there were (and are) languages with text versions based on "NE" letters.

So it is not something "outstanding", just it happened that you know more languages inheriting C-style
operator.

However when I offered some problems to be solved in Lua to users on my website, I remember this was one
of the complaints :)

So while I suspect Lua won't going to add "alternative spelling" for this operator in some future version, still this
may be the small feature which make it more popular with newcomers.

sincerely yours,
Rodion

--
You received this message because you are subscribed to the Google Groups "lua-l" group.
To unsubscribe from this group and stop receiving emails from it, send an email to lua-l+un...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/lua-l/3b46442d-e922-4871-aab9-57a61c662121%40gmx.de.

Roberto Ierusalimschy

unread,
Apr 26, 2025, 10:48:08 AMApr 26
to 'Sainan' via lua-l
> My understanding is that ~= comes from mathematics (as you will e.g. find the same operator in Matlab) and some 40 years ago when the decision was made, it may have been most natural way to represent this operation.

Yes, "~" has some tradition of being used to denote negation in ASCII.
(Even in C, the bitwise NOT operator uses "~".) So, it was quite natural
to use "~=" for NOT EQUAL.

I must confess that even today I am still bewildered by an
exclamation mark meaning negation. In a more natural reading, "!="
should mean "of course they are equal". :-)

(An explanation was that "!= would look like a vertical stroke across an
equals sign if they were printed on top of each other.")

-- Roberto

sur-behoffski

unread,
Apr 26, 2025, 10:46:17 PMApr 26
to lu...@googlegroups.com
On 2025-04-27 00:18, Roberto Ierusalimschy wrote:
> [...]So, it was quite natural to use "~=" for NOT EQUAL. [...]

Apropos almost nothing, I downloaded the tarball for Lua 1.1, referenced
in:

SEMISH'94 paper
reprint from Proceedings of XXI Brazilian Seminar on Software
and Hardware (1994) 273–283.

The design and implementation of a language for extending
applications

by Luiz Henrique de Figueiredo, Roberto Ierusalimschy,
Waldemar Celes Filho

Version 1.1 came out in 1994.

The C-hand-coded lexer has "~=" as the token "NE" (Not Equal).

----

And, from the paper "The Evolution of Lua", HOPL, (9 June 2007):

Except for its procedural data-description constructs, Lua
introduced no new concepts: Lua was created for production
use, not as an academic language designed to support re-
search in programming languages. So, we simply borrowed
(even unconsciously) things that we had seen or read about
in other languages. We did not reread old papers to remem-
ber details of existing languages. We just started from
what we knew about other languages and reshaped that
according to our tastes and needs.

----

Cheers, b

Roberto Ierusalimschy

unread,
Apr 28, 2025, 12:11:05 PMApr 28
to lu...@googlegroups.com
> On 2025-04-27 00:18, Roberto Ierusalimschy wrote:
> > [...]So, it was quite natural to use "~=" for NOT EQUAL. [...]
>
> Apropos almost nothing, I downloaded the tarball for Lua 1.1, referenced
> in:
>
> [...]

Also, the manual for this version (dated May 27, 1994) is available at
Lua's website:

https://www.lua.org/ftp/refman-1.1.ps.gz

-- Roberto

sur-behoffski

unread,
Apr 28, 2025, 10:51:02 PMApr 28
to lu...@googlegroups.com
On 2025-04-29 01:40, Roberto Ierusalimschy wrote:
>> On 2025-04-27 00:18, Roberto Ierusalimschy wrote:
>>> [...]So, it was quite natural to use "~=" for NOT EQUAL. [...]
> Also, the manual for this version (dated May 27, 1994) is available> at Lua's website:
>
> https://www.lua.org/ftp/refman-1.1.ps.gz [...]
[Insert cheeky grin]
Excerpting from "cola.pdf" (The Evolution of Lua, continued)

[...] _Bitwise operations_
For bitwise operations, we adopted the C operations
and operators, except for the exclusive or, that is
denoted by ~ in Lua. [...]

So "~=" is polymorphic?/overloaded? "NOT EQUAL", but "~" is
integer bitwise XOR?!

And as you say yourselves, you're evolving the language as you go
[They're Making It Up As They Go Along!]:

[...] _6. Conclusion_

In these 30+ years, Lua has evolved to meet requirements
coming from outside, ones that we had not planned for or
even imagined. Our focus on keeping the language small and
its implementation portable has helped us meeting these
requirements. Lua has acquired several modern features
without losing its original character. We hope to continue
in this path. [...]

The introduction of integers, too, can be seen as mostly an
incremental change: Except for the bitwise operators,
integers brought remarkably little change in how
programmers use Lua. [...]

--

[In any case, keep up the fantastic work.]

sur-behoffski (Brenton Hoff)
programmer, Grouse Software
Reply all
Reply to author
Forward
0 new messages