Donald Knuth used an Erlang-like notation
videlalvaro.github.io
videlalvaro.github.io
Erlang's great though. Glad to see some irrational exuberance for it.
f [n] = [n]
f [m, n] = [m, n, 0, 1]
f [m, n, r, 1] = [m, n, mod m n, 2]
f [m, n, r, 2] = if r == 0 then [n] else [m, n, r, 3]
f [m, n, p, 3] = [n, p, p, 1]
It needs to be implemented with variable-length lists instead of fixed-length tuples, in order to satisfy the type system.
Do you think it is because other programming languages don't uses the semi-colon that way? Or that periods are usually used to access class members, but not to finish function declarations?
The two clauses separated by a semicolon are sentences; thus the semicolon is logically and grammatically equivalent to a full stop. (As long as you normalise the capitalisation). The difference is in nuance, flow, and other soft things.
So when do you use a semicolon instead of a full stop? Whenever you want to!
The really difficult punctuation mark in English is the full colon.
I've mostly wrote this joke since many Erlang beginners find the semi-colon/period syntax confusing, but then there you have it on an essential book about programming
In my experience, it is we programmers who care about syntax the most. Math folks seem to be happy if you can get the gist of something.
Still, you're right, the semicolon/period thing is troubling for Erlang beginners, but that part of the syntax really does come from Prolog.
One thing is for sure: just trying to read TAOCP will eventually make you better at math.
I agree with your second sentence, and, as a mathematician and a teacher, I think that I agree with the spirit of the first, but I think that it's probably not worded as you mean. Think of the same sentence with, say, 'baseball' in place of 'math': I think that most people would agree with the second sentence, but not the first. By the same token, there's no such thing as "being inherently good" (or, for that matter, inherently bad) "at math"; but I think that it would be silly to pretend that the effort and practice don't make you good (or at least better) at it.
A more precise title would be "Erlang uses math-like notation (and kudos)"
The semicolon-period statement separators/terminators are in the original and in natural languages, but newer languages proved them to be useless. Probably compilers in the 80s needed some help by the programmer to be fast.
Elixir fixed some of the worst offenders, kept others and added something. Examples: the <> is still there but at least we can interpolate strings Ruby like, the useless do at the end of almost every defsomething declarations (the compiler should get it by itself.)
But every languages has its wierdnesses, the contest is to have the least of them.
On the other hand, it's arguably true that Prolog has an over-reliance on a massive swath of operators. All of these operators represent some variation of the concept of equality: =, ==, =:=, =@=, #=, and "is". The differences make sense if you're deep into Prolog, and it's rich capacity for designing new operators is arguably a strength of the language, but it's clearly an obstacle to beginners.
I absolutely adore Prolog, but it's a real shame that development of logical programming basically stopped with it. It would be as if functional programming never properly progressed beyond early Lisps. Its a shame that Erlang borrowed so much of its syntax, when the syntax is clearly not its strongest suit (though it fits Prolog better than Erlang).
They make sense academically, but they only slow down language adoption.
Capitalized variables stand out from lower cased functions. I find that makes it easier to read than having everything lowercase. It's enforced so all the code has to follow that convention.
Semicolon at the end of a function clause indicates there is another function clause following it, that is a useful affordance when navigating code.
> The minuses that prefix the module and export statements
Well in natural language you use dashes to create an itemized list. Would # be better like in include statements in C/C++? Maybe the alternative is to introduce some "defun / fun / def / function" keyword to define functions and another keyword "directives"? But that is less ergonomic, I really like how function definitions don't have to start with an extra keyword and they are just function names starting on the left side of the page.
> the wierd =:= operator.
Yap that is a weird one. = is used for pattern matching so reusing it for equality / equivalence testing might be ambiguous.
> Basically everything that makes the source code less readable than the original:
The original has "remainder of _ divided by _". That looks ok in a small example but repeating that phrase throughout the program many times is probably not the best idea.
Overall, after reading large code bases of Erlang, Python, C++, C#, and Java. I would put Erlang right behind Python and readability and how ergonomic it is. The most important thing about it is it is small and self-consistent. Contrast that with a "modern" language like Javascript which looks "familiar" but is not very consistent and full of gotchas (see the famous wat video on that).
1990 Erlang is presented at ISS'90, which results in several new users, e.g Bellcore
Python was conceived in the late 1980s[1] and its implementation was started in December 1989
Both (and pretty much all languages other than the first ones) borrow heavily from languages that came before them.
You deem that syntax "weird" only because you're experience is with other families of languages. If we all grew up writing Prolog, we'd think the algol C-like languages looked weird.
History of Computing should be a required course for CS majors.
Perhaps its the eye of the developer "used to more modern languages" that has the problem?
The point is that languages generally got better syntaxes along the years. Restricting ourselves to a niche, it's not that Ruby, Python and JavaScript are young (20+) but Ruby got it almost right from the beginning, Python maybe (it has more oddities but it could be a matter of tastes) and JavaScript is evolving a better syntax. Even PHP is getting more readable.
Some of the popular languages got more sugar, but compared e.g. to Lisp are they really an improvement?
Heck, even Go is not that different than Algol-68.
If I were designing a programming language though (no worries, not going to happen), I'd probably still omit the semicolons because I feel (got nothing concrete) that most people don't like them.
On the other hand, I'm not sure how one would objectively eliminate the redundancy without hurting readability by humans and/or machines. Curious if there's some research about this.
That's actually one of the things I personally love about Elixir relative to other Ruby-like-syntax languages (including Ruby itself). Sure, it might technically be extraneous and unnecessary, but it's a nice bit of consistency. Why shouldn't def and defmodule and what have you not be ordinary statements that take a block as an argument?
This is, in fact, consistent with the 'def foo, do: bar' shorthand format in Elixir (and related shorthands like 'if foo, do: bar, else: baz'). No need to have a bunch of different statements that can start a new scope when it's just three more characters to throw a ' do' at the beginning of each of them. Consistent and clear.
Anyway, thanks for the article, it sparked some emotions in my brains :-)
But as Abraham Lincoln said - "don't believe everything you read on the Internet"In a sense it's derived from the way that some mathematical functions are expressed, e.g. i've seen the fibonacci sequence expressed in this manner a few times.
The only thing this excerpt from the book has to do with Erlang is that they both used the same (existing) idea.
>For me what's striking about Erlang syntax is the meaning of the semi-colon and the period, as function clause separator. Most of the rest is just vanilla FP lang syntax.
It's strikes me that everybody notices the pattern matching part, but not the way the clauses are separated, which AFAIK, it's something used by Erlang Syntax only.
And yeah, after working in Erlang and other FP langs for the past 6 years I kinda know this is called pattern matching ;-)
Well... and English syntax. In English, you can specify a list of things by separating each thing with a semicolon and then a sentence is terminated by a period. Example:
> Today I would like you to buy coffee; talk to Sarah about the party if you can, otherwise send her a text; drop off the kids; meet me at soccer practise.
You see how the sentence is terminated with a period, each individual item in the list is separated by a semicolon, and the comma is free to use inside each item to indicate related clauses. I've changed nothing about the structure of that list, except replaced the items with function definitions.
> Today I would like you to define f(m, n, r, 1) as f(m, n, remainder of m divided by n, 2); f(m, n, r, 2) as n if r is 0, otherwise as f (m, n, r, 3); f(m, n, p, 3) as f(n, p, p, 1).
It's the same thing, only we've replaced the mundane everyday tasks with function definitions. Now reformat the thing and we get
Today I would like you to define
f(m, n, r, 1) = f(m, n, remainder of m divided by n, 2);
f(m, n, r, 2) = n if r is 0,
f (m, n, r, 3) otherwise;
f(m, n, p, 3) = f(n, p, p, 1).
Sure, Erlang syntax happens to coincide with the syntax of English, and I'm not sure whether this was intentional or not, but it certainly has nothing to do with Knuth.BTW, newsflash: many languages use semi-colons inside sentences. Spanish for example, which could be argued to be older than English. So did Erlang copy Knuth, or Erlang actually copied El Cid Campeador? I think Erlang comes from El Cantar del Cid.
There are a million languages out there that resemble math notation (mostly functional languages), many of them resemble it much better than erlang does.
> Interesting curiosity, which proves that the Erlang Syntax is some sort of Platonic Language Ideal that predates all programming languages.
Because it supports definition by cases and an if-then-else construct? And because it uses the same punctuation marks that ordinary natural language sentences do? Give me a break.
Yes, the author, a known Erlang developer and a long time programmer really thought Knuth was using Erlang in this book, and, is now trying to convince you to rewrite every single program you wrote in Erlang as well. Geez...
In particular, Erlang's syntax is heavily derived from Prolog's, so it's natural to conclude that Prolog would be the closer relative to Knuth's syntax.
In reality, though, it's probably the other way around; Prolog's syntax is in turn more-or-less derived from the conventions in traditional math formulas (especially with the uppercase variables and such).
Nothing to see here.
The article is silly whimsy, you know that? Knowing the author from online presence, I can assure you the author doesn't really think Knuth was writing Erlang at that time.
> that other, more pure, functional programming languages
Maybe the author doesn't care about other more pure functional programming languages. They care about Erlang so they wrote about it.
Are you sure Knuth wasn't secretly programming in Erlang since the early 50's. He is considered one of the original inventors, it was just too controversial so it was covered up all this time.
I guess we need special whimsy and/or sarcasm tags so people don't take them too seriously...
Turns out there's plenty.
A good HN title is accurate, neutral, and close to the language of the original article. If anyone suggests a better title, we're always happy to change it again.
Misleading? Arguably, but I don't think it's much of a stretch from "Hacker News" to "news for hackers" to "anything that good hackers would find interesting", which is the mandate of the site (https://news.ycombinator.com/newsguidelines.html).
Linkbait? I doubt it, but I'm biased.
minimal-syntax languages tend to look similar.