Mathematical Notation in Emacs
ekaschalk.github.io
ekaschalk.github.io
* "returns" being |--> is awkward and out-of-line with the meaning of that symbol. |--> is usually read as a transitive verb "maps to".
* Using the calligraphic F for "def" is extremely weird and unhelpful.
* Having None be the empty set symbol, which is not set(), is strange.
* Blackboard bold F for False is weird, usually that means a finite field.
* Blackboard bold S for string?
* The dissonance between what the blackboard bold characters mean is jarring. Sometimes it's a type, somethings it's a particular object.
* Whatever the notation is for list and dict types (fraktur) is extremely non-standard and overly frilly.
The Greek/AND/OR/comparisons/not-equal/etc stuff is pretty OK. It's actually truly in-line with their meaning in math.
I am only saying this because the author points out at the end in a serious fashion that it's a useful thing to do for readability.
Don't be fooled. Just because you can make your editor look kinda-sorta like math, doesn't mean it actually is math.
First of all, mathematicians don't really care that much about notation and notation isn't very fixed. There are some broad conventions, but fashions change all the time within a relatively short time span (relative to the history of mathematics). It wasn't that long ago that "_|" instead of "!" was used for the factorial, and you can find 20th century texts that use that notation.
Second of all, most mathematicians really really do not care about notation that much. Notation isn't what makes mathematics, because it's dictated by fashions, whims, and very often, even by jokes. It's completely incidental, to the point that we did mathematics for thousands of years with very little expressions that we would recognise today as "notation".
If you're writing computer code, I say it makes more sense to follow the fashions of code than to try to squeeze them into the fashions of mathematics. Too often I see programmers trying to emulate the style but not the substance of mathematical writing, in an attempt to invoke the favour of the ghosts of Euler and Gauss (who, by the way, would not recognise much of the notation that we use today).
It's just that people that are relative outsiders to the mathematical community give it way more importance than mathematicians do. This is particularly true of computer people, I think, because compilers and interpreters are very rigid about the syntax that they accept. Computer people pass these expectations into mathematics and assume that mathematical writing has some strict, rigid syntax that if not religiously followed nothing makes sense.
Terry Tao has something to say about these "compiler errors":
[1] http://stackoverflow.com/questions/3793838/which-is-the-firs...
^i.e. for all i \in int64, i \in \mathbb{Z}.
(However because UP TACK is a mathematical symbol, so Haskell parses it as an Operator and so it must be wrapped in brackets: `(⊥)`)
1. Context and readibility are user dependent. 2. Choices were made for semantic parsing first and correctness second.
The returns symbol was chosen as right arrow since I can set yield to left arrow.
I agree the def symbol can be jarring. But I have found it beneficial for nested functions and class methods - it takes up less space. I do note that some choices were 'aggressive', this being perhaps the most aggressive.
The times one writes set() vs None influenced the choice. The semantics are close enough.
The blackboards were again chosen for parsing semantics, not correctness. Unicode symbols stand out and take less space. I do agree on the dissonance and have since standardized use of blackboard/script/etc..
The mypy changes have benefited me immensely, it's so verbose otherwise.
Readability is to the eye of the beholder, where this approach excels since customization is dead-simple and the changes are entirely visual.
If one values an exact correspondence to mathematics, then just configure the symbols in that way. The post is indeed hyperbolic to illustrate the choices availible.
I do admit that being liberal with the notation makes cross-language configuration challenging. For other languages I only use the basic, correct symbols.
Thanks for the feedback.
In programming 'functions' can have side effects, 'variables' can be mutated, 'integers' have upper / lower bounds etc.
Although I agree that some notations are probably unhelpful, I still find nice that it can be done.
"In mathematics, the word null (from German: null meaning "zero", which is from Latin: nullus meaning "none")[1] means of or related to having zero members in a set or a value of zero. Sometimes the symbol ∅ is used to distinguish "null" from 0."
I guess symbols only exist in a context, anyway, right? They aren't immutable beings with a true meaning.
Prettifying an Emacs buffer does not change the text written to a file, so the user can also have a context for himself independent of whether he is collaborating with someone else or not.
Empty set could lead to ambiguities imho.
My point is that symbols only have meaning for those who see them. With Emacs pretty-mode, symbols are substituted visually and not ever saved to file.
>Don't be fooled. Just because you can make your editor look kinda-sorta like math, doesn't mean it actually is math.
So what? Doesn't make it wrong... this is just window dressing, which can be very helpful sometimes.
The objection was "the mathematical symbols are not being used correctly", not "it doesn't look right to me". Which makes a big difference if the point of putting math symbols into your code is to make it read like an equation , as the author is attempting to do.
Besides, python list comprehension isn't that far from the mathematical version. Compare:
{ x^2 : x in Z, x^2 > 10 }
with
[ x^2 for x in Z if x^2 > 10 ]
The main problem is that you can't have a list of all positive integers, so you're kind of forced to make it a generator instead. And the standard set notation clashes a bit with the notation of dictionaries, but on the whole it's not that bad.
$$any(code \notin api\_codes \forall code \in codes)$$
It's a fine theme.
Non-conventional notation strips away the benefit of shorthand notation in collaborative environment - nobody actually can tell what the meaning is just by looking at it without learning it first. If applied generally to software development, using an exotic notation just because it looks nice is risky and of questionable value. New notation is always a huge burden and should be taken into use only if there is some actual benefit other than aesthetics.
— The Ten Commandments for C Programmers (https://www.lysator.liu.se/c/ten-commandments.html)
The main problem I have with it is I want to edit the text, not some pretty rendering. I use some display rendering in emacs, in org-mode to be specific, but none at all in programming modes, even in Lisp where one doesn't need to edit S-expressions directly. I guess I've been bitten by software where the display doesn't equal the underlying data too many times.
(font-lock-add-keywords 'js2-mode '(
("=>" (0 `(face nil display "")))
(">=" (0 `(face nil display "≥")))
("<=" (0 `(face nil display "≤")))))
EDIT: It seems that HW doesn't really like U+27A1 ... :-)I don't even want to see what happens when you mark a region and call M-x align in a variable width font.