I have been searching for a practical programming language that has no reserved keywords but I haven’t had any luck finding one.
I am working on a programming language for my own edification and entertainment and I haven’t needed to include any keywords yet, that is what led me to my search and the question:
I don’t see convenience to the compiler writer as being important to the end user of the language. Computers are powerful enough now days to be able to infer meanings from context. No more than a writer needs to label nouns, verbs and such when writing a novel, why should a programmer have to label functions and variables with function x() {}
or set x = 1
or var x = 1
etc; when I can infer from the context of the statements that it is a function declaration or an invocation or that a label is an assignment to a value or a reference to that labels value?
Here is a concrete example of what my current parser is doing, no need for reserved keywords to support common things that would normally have a bunch of noise like func
or function
or dec
or what not.
Function Declaration
sum3(a,b,c) -> a + b + c.
Function Invocation
x = sum3(1,2,3).
Anonymous Function Named x
x = (a,b,c) -> a + b + c.
y = x(1,2,3).
I would like to know why are keywords that important to a successful programming language?
17
MUMPS is highly successful, being widely used in insurance and healthcare and and has no reserved words. I’d say they help in terms of writing clearer code but they aren’t strictly necessary. APL is another example. APL sees use for one-off scripts in the Nuclear Industry amongst others. J, a member of the APL family also lacks keywords.
Keywords help compiler writers implement parsing more easily. APL is famously right associative. They also help reinforce conventions and improve readability. APL is not known for being hugely readable to most.
5
One well known language without keywords is Lisp. The closest thing it has to keywords are so called special forms – their number may vary between dialects – that get special treatment from the interpreter. Apart from that they are indistinguishable from regular functions in terms if how they are used, with the exception that they can’t be redefined (at least in Lisps i’m familiar with).
This results in a simple (but paren-heavy) syntax, and is one of the things that enabled Lisp to have such a powerful macro system. On the other hand, Lisp is often said to be hard to read. APL and MUMPS, even more so, I’ve seen both described as halfway to Brainf*ck. Keywords do help in this department and make reading code easier for us humans too.
So I wouldn’t say keywords are required for a successful language, but they sure help a language to become successful.
5
TCL has no key words, and indeed only 12 syntax rules. while its not as popular as it once was, it has its niche with expect and embedded in ECAD and routers so it certainly counts as a practical to my mind.
I also think it may show why lots of languages don’t go this route. Yes its perfectly possible to write a TCL parser (arguably easier than many other languages) however you can’t write a very useful BNF grammar for the language and many people seem to have trouble learning the language. I suspect this is at least partly because of lack of keywords.
2
Computers are powerful enough now days to be able to infer meanings
from context.
Does this mean you want a grammar that is not context free? Good luck.
It’s not a question about being powerful or not. There are eternal, unchanging rules about languages – mathematical ones. This, and the fact that a programming language should be syntactically easy will make CFGs rule for some decades to come.
Btw., in Haskell like syntax, you just write something like
f x y = (x+1)*(y-1)
to define a function. But observe that the “keyword” in this case is the ‘=’. If you miss it, terrible things will happen in the parser.
But this is a point where I agree with you, I find this much more intuitive than all the def, dcl, fun, fn, function or what-not keywords that introduce functions in other languages.
Yet, this grammar can be written in plain old LALR(1), no meaning is “inferred from the context” here.
11
You seem to be laboring under a false assumption, that keywords are there to make things easier for the compiler. While they do make things easier for the compiler, they have a much more important benefit: they make things easier for the person reading the code.
Yes, you could look at a bunch of context and figure out that you’re looking at a function declaration or a variable declaration, but depending on the context and on the complexity of the code involved, that could take a long time to figure out. Or, you could have a handy keyword there like function or var, and you know immediately what you’re looking at.
Yes, they make the code more complicated to write, but considering that programs spend a lot more time in maintenance than in production, and that their code is read, debugged and maintained a lot more than it is created, trying to design your language to make it easy to write instead of easy to read is a classic case of harmful premature optimization.
Also, don’t disdain concepts that make the compiler’s job easier. The easier it is to parse, the faster your code will compile, which means edit-build-debug cycles get faster, which means your productivity goes up.
When you have a large, complex codebase, that can amount to a non-trivial difference in productivity. For example, where I work we have a program at work that’s about 4 million lines of Delphi. We have another module that’s about 300,000 lines of C++. They both take about the same length of time to compile. (About 3 minutes.) If we had 4 million lines of C++, it could take an hour to build!
5
As far as I know, Smalltalk is the language that has least keywords (if I am not counting languages like Brainfuck). Smalltalk keywords are true
, false
, nil
, self
, super
and thisContext
.
I have designed a langage, inspired with smalltalk, that had no keywords. But after some time of using it I ended up adding a few keywords, mostly for syntactic sugar.
So, my opinion is that language without keywords is possible, but it is not very practical and that is the reason why all popular languages have keywords.
2
There are some rare examples.
APL uses only symbols — but a lot of them! You need a special keyboard to use the language.
See this wikipedia article
CORAL 66 — had keywords but only recognised them if they were quoted with single quotes.
PL/1 also had keywords — but you could also use them as variable or procedure names.
All in all though your question is a bit like asking “why do spoken languages have words?”.
1
The main reason is that it’s easier for both humans and computers to parse. Disambiguating a complex language without keywords would require many symbols as syntax, and it would be massively and unnecessarily confusing. It’s much easier to read function
than $!{}
. And context does not resolve all ambiguities.
7