Simple examples: Difference between revisions

Jump to navigation Jump to search
4 bytes added ,  13:44, 23 April 2020
m
→‎Text processing: Nesting level of Parenthesis nesting level headers
m (→‎Text processing: Nesting level of Parenthesis nesting level headers)
Line 132: Line 132:
Ken was showing some slides — and one of his slides had something on it that I was later to learn was an APL one-liner. And he tossed this off as an example of the expressiveness of the APL notation. I believe the one-liner was one of the standard ones for indicating the nesting level of the parentheses in an algebraic expression. But the one-liner was very short — ten characters, something like that — and having been involved with programming things like that for a long time and realizing that it took a reasonable amount of code to do, I looked at it and said, “My God, there must be something in this language.” Bauer, on my left, didn’t see that. What he saw or heard was Ken’s remark that APL is an extremely appropriate language for teaching algebra, and he muttered under his breath to me, in words I will never forget, “As long as I am alive, APL will never be used in Munich.” And Dijkstra, who was sitting on my other side, leaned toward Bauer and said, “Nor in Holland.” The three of us were listening to the same lecture, but we obviously heard different things."|[[Alan Perlis]]. ''[https://www.jsoftware.com/papers/perlis78.htm Almost Perfect Artifacts Improve only in Small Ways: APL is more French than English]'' at [[APL78]].}}
Ken was showing some slides — and one of his slides had something on it that I was later to learn was an APL one-liner. And he tossed this off as an example of the expressiveness of the APL notation. I believe the one-liner was one of the standard ones for indicating the nesting level of the parentheses in an algebraic expression. But the one-liner was very short — ten characters, something like that — and having been involved with programming things like that for a long time and realizing that it took a reasonable amount of code to do, I looked at it and said, “My God, there must be something in this language.” Bauer, on my left, didn’t see that. What he saw or heard was Ken’s remark that APL is an extremely appropriate language for teaching algebra, and he muttered under his breath to me, in words I will never forget, “As long as I am alive, APL will never be used in Munich.” And Dijkstra, who was sitting on my other side, leaned toward Bauer and said, “Nor in Holland.” The three of us were listening to the same lecture, but we obviously heard different things."|[[Alan Perlis]]. ''[https://www.jsoftware.com/papers/perlis78.htm Almost Perfect Artifacts Improve only in Small Ways: APL is more French than English]'' at [[APL78]].}}
What was the one-liner for the nesting level of parentheses? It would take a bit of work to figure out, because at the time of the meeting Perlis described, no APL implementation existed. Two possibilities are explained here.
What was the one-liner for the nesting level of parentheses? It would take a bit of work to figure out, because at the time of the meeting Perlis described, no APL implementation existed. Two possibilities are explained here.
=== Method A ===
==== Method A ====
For this more complex computation, we can expand on the previous example's use of <source lang=apl inline>∘.=</source>. First we compare all characters to the opening and closing characters;
For this more complex computation, we can expand on the previous example's use of <source lang=apl inline>∘.=</source>. First we compare all characters to the opening and closing characters;
<source lang=apl>
<source lang=apl>
Line 150: Line 150:
</source>
</source>
{{Works in|all APLs}}
{{Works in|all APLs}}
=== Method B ===
==== Method B ====
Alternatively, we can utilise that if the [Index Of]] function <source lang=apl inline>⍳</source> doesn't find what it is looking for, it returns the next index after the last element in the the lookup array:
Alternatively, we can utilise that if the [Index Of]] function <source lang=apl inline>⍳</source> doesn't find what it is looking for, it returns the next index after the last element in the the lookup array:
<source lang=apl>
<source lang=apl>

Navigation menu