14

Writing Code to Be Spoken (2019)

 4 years ago
source link: https://www.sacrideo.us/writing-code-to-be-spoken/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

apl

Writing code to be spoken

  • Aaron W. Hsu

    I'm an Orthodox Christian; I believe in the beauty of the careful, considered thought. Computing and education are two of my passions. I'm changing the way people think about computing.

    More posts by Aaron W. Hsu.

Aaron W. Hsu

29 Oct 2019 1 min read

A personal favorite design element that APL allows me to explore is the "lyricality" of a given piece of code. I ask myself how much the natural language description of what a piece of code does would map directly to the code. This is a sort of discussion that simply doesn't come up in other general purpose programming languages very often. Here's an example from my compiler.

Pass Overview: Count the Rank of Indexing Expressions

Description #1: Store the count of the rank of indexing expressions in the n field of each indexing expression.

Description #2: Store in the n field of each indexing expression the number of children it has.

Description #3: For each child whose parent is an indexing expression increment the parent's n field by 1.

Description #4: For nodes whose parent is an expression of index kind increment the parent's n field by 1.

Description #5: Increment the n field of the parent for nodes whose parent is of type 2 and kind 3 for each node by 1.

Each of these descriptions becomes more an more precise until it is precisely describing what needs to be done. Now, let's look at a version of the code

n[p⌿⍨(t[p]=2)∧k[p]=3]+←1

Now let's see how that code maps to the description:

n[                    p⌿⍨                           (t[p]=2)
Increment the n field of the parents for nodes whose parents are type 2

∧   k[p]=3 ]+←           1
and kind 3 for each node by 1

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK