From aaac31f1668fe5516902ee7d2034e5c0e41667a6 Mon Sep 17 00:00:00 2001 From: Marshall Lochbaum Date: Wed, 13 Jul 2022 16:37:06 -0400 Subject: Support line breaks inside brackets in markdown BQN evaluation --- docs/doc/oop.html | 42 +++++++++++++++++++++--------------------- 1 file changed, 21 insertions(+), 21 deletions(-) (limited to 'docs/doc/oop.html') diff --git a/docs/doc/oop.html b/docs/doc/oop.html index 5915f033..4102ddc1 100644 --- a/docs/doc/oop.html +++ b/docs/doc/oop.html @@ -66,39 +66,39 @@

Objects

An object in BQN is simply a namespace: its fields and methods are variables in the namespace, and a variable can be accessed outside of the namespace with dot syntax if it's exported with . Unexported variables are instance-private in OOP parlance, meaning that they're only visible to the object containing them. They could be utilities, or hold state for the object. As an example, the object below implements the Tower of Hanoi puzzle with five disks. You can view the state (a list of disks occupying each of the three rods) with towerOfHanoi.View, or move the top disk from one rod to another with towerOfHanoi.Move.

-
towerOfHanoi  {
-  l  ¨500
-  View  {𝕤
-    l
-  }
-  Move  {fromto:
-    l  Transfer´(𝕩)(´𝕩) l
-  }
-  # Move a disk from 𝕨 to 𝕩
-  Transfer  {
-    "No disk to move"!0<≠𝕨
-    "Can't place larger disk on smaller one"!(0<≠)1,𝕨<⊑⊢𝕩
-    1𝕨, 𝕨𝕩
-  }
-}
+↗️
    towerOfHanoi  {
+      l  ¨500
+      View  {𝕤
+        l
+      }
+      Move  {fromto:
+        l  Transfer´(𝕩)(´𝕩) l
+      }
+      # Move a disk from 𝕨 to 𝕩
+      Transfer  {
+        "No disk to move"!0<≠𝕨
+        "Can't place larger disk on smaller one"!(0<≠)1,𝕨<⊑⊢𝕩
+        1𝕨, 𝕨𝕩
+      }
+    }
 

Two variables l and Transfer aren't exported, for two different reasons. l encodes the state of the tower, but it's only exposed with the function View, which allows the internal representation to be changed freely. Transfer is just a utility function. While it's not dangerous to use outside of the object, there's no reason to expose it through towerOfHanoi's interface. If it's wanted in another place it should be moved to a common location.

Here are the results of a few applications of these functions.

-
    t  towerOfHanoi
+↗️
    t  towerOfHanoi
     t.View@
-  0 1 2 3 4  ⟨⟩ ⟨⟩ 
+⟨ ⟨ 0 1 2 3 4 ⟩ ⟨⟩ ⟨⟩ ⟩
 
     t.Move 02
-  1 2 3 4  ⟨⟩  0  
+⟨ ⟨ 1 2 3 4 ⟩ ⟨⟩ ⟨ 0 ⟩ ⟩
 
     t.Move 12
-! "No disk to move"
+Error: No disk to move
 
     t.Move 01
-  2 3 4   1   0  
+⟨ ⟨ 2 3 4 ⟩ ⟨ 1 ⟩ ⟨ 0 ⟩ ⟩
 
     t.Move 21
-  2 3 4   0 1  ⟨⟩ 
+⟨ ⟨ 2 3 4 ⟩ ⟨ 0 1 ⟩ ⟨⟩ ⟩
 

Classes

The object above is a singleton: there's just one of it, at least in the scope it occupies. It's often more useful to have a class that can be used to create objects. What we'll call a "class" is a namespace function, that is, a function that contains and so returns a namespace. It's very easy to convert a singleton object to a class: just add a no-op 𝕤 line to force it to be a function, and call it with @ when needed.

-- cgit v1.2.3