Hi,

I've been pondering why using ! for indentation, \\ for empty and $
for sublist feels so alien to me, and today I finally found an answer,
when I looked into letter distributions[^1].

# Firstoff: The problem of brackets in lisp.

This has mostly been discussed to death, so I'll just write what I can
add to the discussion. 

1. Brackets are rare charakters in normal writing: about 0.2% of the
   charakters in normal text are brackets. So the code feels strange,
   because the distribution of letters is too different from normal
   text.

2. In lisp brackets are the first letter, but people tend to remember
   words by their first letter.

The second is fixed by neoteric expressions: You can now use the first
letter of the function you call as the first non-whitespace letter of
the line of code.

To fix the first, the use of brackets has to be reduced - or replaced
by letters which are more common in normal text.

# Common letters

I now took my list of letters and looked at the distribution of
letters which are suitable as control charakters (not used in normal
words). Then I grouped them such that the groups differ by roughly a
factor of two in occurrance frequency in normal text. My results were
this:

\n (linebreak)
., (1/2 of \n)
-()":' (1/2 again - interestingly we now have all the main control charakters 
in regular lisp, except for the comment-sign)
/*= (1/2)
<>?!\; (1/2)
% (1/2)

and here we have a gap of factor 4, so I will ignore the rest: they
are too uncommon to be used if we want to stay close to normal text.
(which is the fix for 1.)

This listing means that if we replace two brackets by one of /*= we
do not win anything.

To make this quantitative: Take the syntax needed to express
something. Divide the occurance frequency of each letter in the syntax
by the frequency of a normal letter. Then multiply the results. If
this is higher than the syntax we want to replace, then we win
something.

The mean occurance frequency for the 20 most frequent characters as about 5%:
import numpy
numpy.mean(numpy.array(numbers[:20])/ sum(numbers))

() is (0.2% / 5%)**2 = 0.0016
$ is 6.64e-5 / 0.05 = 0.0013

So by using a sublist with $ instead of a (b c), we actually make our
code less similar to normal text.

\\ is even worse: (1.05e-8 / 0.05)**2 = (2.1e-7)**2 = 4.4e-14

We replace (()) with it, which is 0.0016**2 = 2.56e-06, but it is
still a huge net loss of similarity to normal text.

! for indentation on the other hand is 0.00036 / 0.05 = 0.007 which is
  a net win of a factor of 4.6 over 2 brackets.

Without the ! it would be over 1/0.0016, though (but since it is
optional, I can live with it - just don't use it in code-examples
where it is not needed).

Essentially this all boils down to only using the most common special
characters when trying to improve the readability of lisp:

\n
.,
-()":'
/*=
<>?!\;
%

So, please rethink using \\ and $ for groups and sublist. Actually the most 
common available letters for that are:

,':

I left out the . for groups, because I found a usecase which it would
break: (let (((genvariable) name))). Also I left out the *, because it
is needed in curly infix.

But , ' and : on their own, not at the beginning of a line and
surrounded by whitespace have no meaning in lisp (to the best of my
knowledge).

Best wishes,
Arne

[^1]: I used letter distributions I generated for a keyboard optimization 
project. They are 70% german and 30% english and as representative of written 
text as we could get them (we = the neo-community from neo-layout.org): 
https://bitbucket.org/ArneBab/evolve-keyboard-layout/src/4ff5eaa359dba1cdea2236c1a51fc4b58fb104dc/1-gramme.arne.txt

import urllib
with 
urllib.request.urlopen("https://bitbucket.org/ArneBab/evolve-keyboard-layout/raw/4ff5eaa359dba1cdea2236c1a51fc4b58fb104dc/1-gramme.arne.txt";)
 as f:
  letters = f.read().splitlines()


numbers = [float(l.split()[0]) for l in letters if l]
print(numbers[0] / sum(numbers))
for i,l in enumerate(letters):
  if "(" in str(l):
    bracketindex = i


print(numbers[bracketindex] / sum(numbers))


------------------------------------------------------------------------------
Master HTML5, CSS3, ASP.NET, MVC, AJAX, Knockout.js, Web API and
much more. Get web development skills now with LearnDevNow -
350+ hours of step-by-step video tutorials by Microsoft MVPs and experts.
SALE $99.99 this month only -- learn more at:
http://p.sf.net/sfu/learnmore_122812
_______________________________________________
Readable-discuss mailing list
Readable-discuss@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/readable-discuss

Reply via email to