An Unicode Experiment

Unicode Experiment

Hi all,

For a while I have being using symbols to show specific JavaScript functions and
operators[0], as a way to avoid making some mistakes that are (at least for me) really annoying.

Everything start because I was mixing asignment (​=) with equality (==),
probably a common mistake. By chance I saw a video about APL[1][2], and after some research I thought that maybe my problem was a notation problem[3].

What I am doing

Assignment

Because JavaScript uses the same symbol for assignment and comparison[4],
whenever I saw an assignment I was reading “x equals …”. It was my mistake,
but the notation wasn’t helping.

So now I use the symbol `←` (U+2190 Leftwards Arrow) to indicate an assignment

Comparison

The customary recommendation is use strict equality (​===),
but 3 symbols take too much space, so now I use the `≡` symbol (U+2261 Identical to)

switch and case

The switch statement looks like a list (to me), and I think is natural to use an arrow when enumerating, so I use the `🝘` (U+1F758 Alchemical symbol for pot ashes, the idea of this one come from the movie ‘bandersnatch’) and `➜` (U+279C Heavy round-typped rightwards arrow)

array push and pop

Push and pop, are somewhat difficult to parse, so I use `↧` (U+21A7 Downward Arrow from Bar) for push, and `↥` (U+21A5 Upwards Arrow from Bar) for pop.

array map

I alway use map, and `↦` (U+21A6 Rightwards Arrow from Bar ) is easier to spot than a word.

function

I think that `λ` (U+03BB Greek Small Letter Lamda ) is more easier to spot than the word function (and take less space)

return

My keyboard has the symbol `↲` (U+21B2 Downwards Arrow with Tip Leftwards) in the
return key, so it seems a good idea:

array filter and element

For array filter I use `σ’ (U+03C3 Greek Small Letter Sigma), and for element
`∈` (U+2208 Element Of)

  1. With an arrow function is more easier to parse

    The symbol for the arrow function is `⇒` (U+21D2 Rightwards Double Arrow)

A function example

An arrow function example

Conclusions

At least for me is easier to read symbols than words, I tried adding comments (function signatures) but is not the same (with symbols I can scan the code really fast).

The best part is, thanks to Emacs, this aesthetic change not have any effect in the source code(and I can turn on-off the changes fast).

Cheers and happy coding :slight_smile:

Reference:

[0] https://www.emacswiki.org/emacs/PrettySymbol

displaying sequences of characters as fancy characters or symbols

[1]

[2] https://en.wikipedia.org/wiki/APL_(programming_language)

[3] Notation as a tool of thought

http://www.jsoftware.com/papers/tot.htm

By relieving the brain of all unnecessary work, a good notation sets it free to concentrate on more advanced problems, and in effect increases the mental power of the race.
A.N. Whitehead

[4] assignment and comparison (JavaScript)

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Comparison_Operators

  • Equality (==)
  • Inequality (!=)
  • Identity / strict equality (​===)
  • Non-identity / strict inequality (!==)
  • Greater than or equal operator (>=)
  • Less than or equal operator (<=)

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Assignment_Operators

Very neat. Thanks for sharing!

1 Like

You are welcome :slight_smile:




Cheers and happy coding :slight_smile:

This is fantastic, thank you for sharing it. Pretty cryptic, though thinking about it I always use ligatures, so I can understand how I’d get used to extended usage of them very quickly. Only one I’m not quite sure about is using sigma. Anyway, I’d read that Iverson essay a while ago, I remember it being brilliant so going to have another read through now.

Have you seen this presentation (sorry, it’s in a wierd format, seems to have been uploaded via some MS Office suite thing)?

I’m not sure how I stumbled upon it, but it’s one of the best essays on programming that I’ve read in the last couple of years; there are a load of ideas described in it that really struck home and are applicable regardless of programming language.

This is really cool! Reminds me a lot of Fira Code, a monospace font with ligatures.

Youre welcome :slight_smile:

Yes, I saw that Aaron Hsu[0] presentation[1], but I hadn’t read that document. Thanks.

I think that you are right, and also makes me want to learn APL (it seems a really nice language) .

Thanks I didn’t know about that, I will add it to my references :slight_smile:

Cheers and happy coding :slight_smile:

Reference:

[0]

[1]

1 Like

Yeah, it made me want to play around with it (or J or K, the two successor languages); it looked fun. But it’s very single-purpose – just math, basically. Plus APL (rather than J/K) normally needs a special keyboard. Actual usecase seems to be primarily specific finance stuff (& IBM seem to have produced a fair few APL keyboards in the 70s/80s/90s, so I guess was quite popular in its very specialised niche). There was a guy in another forum I’m on who had a thread open for a couple of years where he posted stuff he was doing in it every so often, that was really cool (he was writing about what he was doing on APL mailing lists and stuff I think as well, and that got him headhunted by a wall street trading firm after a while)

My instant concern was how this would affect production code, but you state that with Emacs you can enable/disable these translations at will. With that concern aside, this looks like a fantastic way to write code that you can personally understand very quickly. Cool tip for others who might want to implement this!

I am testing the Emacs mode for gnu apl[0] and with the ‘APL-Z’ input mode
my keyboard is not that uncomfortable to use (the need of a dot [.] before
every symbol is awkward, but maybe it can be customized).

Yes, it seems a very specific language and with few users. If I can find the documentation of quad-gtk[1], I will try to write a [2d] roguelike or use it
like a game (most of the code seems like a fun puzzle to try).

Yes, is easy. You can create a key combination to switch it on/off ( and avoid all the alt+x prettify-symbols-mode [ret] thing).

if anyone is interested, this is my (Emacs) current configuration file:

I think that this is enough to make it works, but I didn’t tested it:

(require 'package) 
(add-to-list 'package-archives '("melpa" . "https://melpa.org/packages/"))
(package-initialize) 

;; This is only needed once, near the top of the file
(eval-when-compile
;; Following line is not needed if use-package.el is in ~/.emacs.d
;  (add-to-list 'load-path "<path where use-package is installed>")
(require 'use-package))

(global-prettify-symbols-mode 1) 

;; This is from stackoverflow, I need to add the url
(defun prettify-list (l &optional merge)
  "Takes two lists and interleaves the (optional) second between each element of the first.  Used to 
create multi-character sequences for use with prettify-symbols mode.  If not supplied, MERGE defaults
to '(Br . Bl)"
  (let ((merge (or merge '(Br . Bl)))
		(head (car l))
		(tail (cdr l)))
	(cond
	 ((not (consp l))    '())
	 ((not (consp tail))  (list head))
	 (t (cons head
			  (cons merge
					(prettify-list tail merge)))))))

;; This is from stackoverflow, I need to add the url
(defun prettify-string (s &optional merge)
  "Takes a string and an optional list, and returns a list of the string's characters with MERGE
interleaved between each character, for use with prettify-symbols mode.  If no MERGE is supplied,
uses the prettify-list default."
(prettify-list (append s nil) merge))

(defun prettify-set ()
  (setq prettify-symbols-alist
		`(
	      (".map"         . ,(prettify-string   " ↦ ")) 
		  (".assign"      . ,(prettify-string   " ↤ ")) 
		  (".pop"         . ,(prettify-string   " ↥ "))
		  (".push"        . ,(prettify-string   " ↧ ")) )))

;;; This js2-mode  (installed) to work 
(add-hook 'js-mode-hook  'prettify-set)
(add-to-list 'auto-mode-alist '("\\.js\\'"     .  js2-mode))

Cheers and happy coding :slight_smile:

Note

The apl gif looks like that because I had to open Emacs inside Emacs to use the screencast program.
I use EXWM (as window manager) and has troubles with the screencast program.

References:

[0] https://github.com/lokedhs/gnu-apl-mode

[1] https://www.gnu.org/software/apl/apl.html#Section-3_002e24

There is a reference to it in the documentation, but I can’t find anything.

1 Like

Thanks to all for discussion this…

I see people longing for the brevity and expressiveness of a good notation, such as APL.

Unfortunately APL got shoved to the side by the standardization of the graphical character set (ASCII), for good reasons.

But now we live in a time where most developers use insanely flexible rendering engines as code editors (Atom, VS Code) and even those of us who prefer simpler / faster alternatives (Vim, Sublime Text) are easily able to specify custom fonts and map symbols to keys through the use of plugins.

This all tells me that a modern APL is over due. We need to do what Clojure did for Lisp and what F# did for ML.

Here is my idea: take Co-dfns by Aaron Hsu, a self-hosting, open-source, modern APL compiler; learn how it works down to the smallest detail (I’m currently stuck in this phase, and I will be for a long time); write backends for the JVM, LLVM, CIL, and WASM bytecodes; extend the language with object-oriented constructs and whatever else is needed by those backends; and write language plugins for Atom and other editors.

Who’s with me?