From 5e81613ac137c5641675ceb792ca105d345d98c6 Mon Sep 17 00:00:00 2001 From: Marshall Lochbaum Date: Thu, 14 Jul 2022 21:02:14 -0400 Subject: Handle transitive dependencies in REPL link code --- docs/doc/quick.html | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) (limited to 'docs/doc/quick.html') diff --git a/docs/doc/quick.html b/docs/doc/quick.html index af70a7b7..cbda94a9 100644 --- a/docs/doc/quick.html +++ b/docs/doc/quick.html @@ -138,7 +138,7 @@
hw case.Upper(¨)
 

This statement consists of the name hw just defined, a compound function, and then the new character . This is another form of assignment, like , but it changes the value of an existing variable instead of defining a new one. There's also some special syntax here: the expression val Fn is shorthand for val Fn val, avoiding the need to write the name hw twice (and val Fn arg means val val Fn arg, like += and so on from C). So we are modifying hw by applying this function case.Upper(¨).

-↗️
    hw  <˘ 2  "helloworld"
+↗️
    hw  <˘ 2  "helloworld"
 
     case.Upper(¨) hw
 ⟨ "Hello" "World" ⟩
@@ -147,14 +147,14 @@
 ⟨ "Hello" "World" ⟩
 

That converts the first character of each string to uppercase! case.Upper is the case conversion function defined before, so that part makes sense. The rest of the function, (¨), would be pronounced "Under the First of Each", which… pretty much makes sense too? The First Each function extracts the first element of each list in hw, the part that used to be "hw" but is now "HW".

-↗️
    ¨ hw
+↗️
    ¨ hw
 "HW"
 
     case.Upper "hw"
 "HW"
 

The Under modifier keeps track of where that string came from and puts it back, to produce a new, altered array. It's kind of special, like Undo, but works on all sorts of fancy selections. It's also worth pointing out that case.Upper applies to a string here, not an individual character. That's because arithmetic is pervasive, so that functions made of arithmetic naturally work on arrays. Although in this case it wasn't really necessary, because it's also possible to map over the two strings and uppercase the first character of each separately:

-↗️
    case.Upper¨ "hello""world"
+↗️
    case.Upper¨ "hello""world"
 ⟨ "Hello" "World" ⟩
 

Modifiers are applied from left to right, opposite to functions (1-modifiers also take the operand on the left while prefix functions have the argument on the right). So case.Upper¨ means (case.Upper)¨.

@@ -163,14 +163,14 @@
•Out hw   ⥊⍉ [hw, ", ""!"]  # Hello, World!
 

None of these functions have a subject to the left, so they're all evaluated as prefix functions. But first, we have the array notation []. This syntax forms an array from its major cells hw and ", ""!" (another strand, a list of two strings). Because the major cells are both lists, we have another rank 2 array.

-↗️
    [hw, ", ""!"]
+↗️
    [hw, ", ""!"]
 ┌─                 
 ╵ "Hello" "World"  
   ", "    "!"      
                   ┘
 

The reason for forming this array is to interleave the elements, or we might say to read down the columns rather than across the rows. This ordering is done with a Transpose to exchange the two axes, then a Deshape to flatten it out, giving a list.

-↗️
     [hw, ", ""!"]
+↗️
     [hw, ", ""!"]
 ┌─              
 ╵ "Hello" ", "  
   "World" "!"   
@@ -180,7 +180,7 @@
 ⟨ "Hello" ", " "World" "!" ⟩
 

Finally, Join combines this list of strings into a single string.

-↗️
    hw   ⥊⍉ [hw, ", ""!"]
+↗️
    hw   ⥊⍉ [hw, ", ""!"]
     hw
 "Hello, World!"
 
@@ -249,7 +249,7 @@ (¨ GV ˜ ·+`GS) r

The first line here applies Proc to each character and the one before it, using ' ' as the character "before" the first. Proc{»𝔽¨} 𝕩 is a fancy way to write (»𝕩) Proc¨ 𝕩, which we'll explain in a moment. First, here's what the Nudge function » does.

-↗️
    hw
+↗️
    hw
 "Hello, World!"
     »hw
 " Hello, World"
@@ -257,7 +257,7 @@
 

It moves its argument forward by one, adding a space character (the array's fill) but keeping the same length. This gives the previous characters that we want to use for Proc's left argument. Here Each is used with two arguments, so that it iterates over them simultaneously, like a "zip" in some languages.

What about the fancy syntax Proc{»𝔽¨} 𝕩? The block {»𝔽¨} is an immediate 1-modifier because it uses 𝔽 for an operand but not the arguments 𝕨 or 𝕩. This means it acts on Proc only, giving »Proc¨, which is a train because it ends in a function . Following the rules for a 3-train, (»Proc¨)𝕩 expands to (»𝕩) Proc¨ (𝕩), and since is the identity function, 𝕩 is 𝕩.

Since a display of lots of namespaces isn't too enlightening, we'll skip ahead and show what the results of GV and GS on those lists would be. GV turns each character into a string, except it makes a space into the empty string. GS has a 1 in the places where we want to split the string.

-↗️
    sp  ' '=hw
+↗️
    sp  ' '=hw
     gv  (1-sp) ¨ hw
     gs  sp  »= hw
 
@@ -312,18 +312,18 @@
 
 
 

There are actually three train groupings here: from right to left, ·+`GS, GV ˜ , and ¨ . Two of them are 2-trains, which apply one function to the result of another, but the one with is a 3-train, applying a function to two results. In the end, functions GS and GV are applied to r. In fact, to evaluate the entire train we can replace these two functions with their results, giving ¨ (GV r) ˜ ·+`(GS r).

-↗️
    ¨ gv ˜ ·+`gs
+↗️
    ¨ gv ˜ ·+`gs
 ⟨ "Hel" "lo," "World!" ⟩
 

In this expression, Nothing can be removed without changing the meaning. It's used in the train to force +` to apply to GS as a 2-train instead of also taking ˜ as a left argument. The Scan +` is a prefix sum, progressively adding up the numbers in gs.

-↗️
    gs
+↗️
    gs
 ⟨ 0 0 0 1 0 0 1 0 0 0 0 0 0 ⟩
 
     +`gs
 ⟨ 0 0 0 1 1 1 2 2 2 2 2 2 2 ⟩
 

The next bit uses Swap to switch the order: gv ˜ +`gs is (+`gs) gv, but sometimes the different order can read better (here it was mostly to squeeze Nothing into the program, I'll admit). Group then splits gv up based on the indices given: the first three elements become element 0 of the result, the next three element 1, and the rest element 2.

-↗️
    (+`gs)  gv
+↗️
    (+`gs)  gv
 ┌─                                                                
 · ⟨ "H" "e" "l" ⟩ ⟨ "l" "o" "," ⟩ ⟨ ⟨⟩ "W" "o" "r" "l" "d" "!" ⟩  
                                                                  ┘
-- 
cgit v1.2.3