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/quick.html | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) (limited to 'docs/doc/quick.html') diff --git a/docs/doc/quick.html b/docs/doc/quick.html index 28ff1248..8a13379b 100644 --- a/docs/doc/quick.html +++ b/docs/doc/quick.html @@ -39,12 +39,13 @@

If you save it with the name hello.bqn and have BQN installed, the script can be run with $ bqn hello.bqn from a shell. Because of the #! line at the top, $ ./hello.bqn also works if bqn is in your path and hello.bqn is executable. It can also be run from another BQN file in the same directory, or REPL started there, using •Import "hello.bqn". Or just copy-paste it into the online REPL.

Now let's see how it works.

Case conversion

-
# Case conversion utilities
-case  {
-  diff  -´ "Aa"
-  Lower  -diff
-  Upper  Lower
-}
+↗️
    # Case conversion utilities
+Error: Empty program
+    case  {
+      diff  -´ "Aa"
+      Lower  -diff
+      Upper  Lower
+    }
 

This part of the code defines a namespace using braces {}, then assigns it to the name case. There are three assignments inside the namespace too. Since BQN uses lexical scoping, code outside the namespace can't access the variables diff, Lower, and Upper directly. Oh, and the first line is a comment.

The value diff is the result of applying a function -´ to the argument "Aa". Function application is always written just by placing a function next to its arguments like this—a prefix application if there's one argument, infix if there are two, and that's the most arguments you can have. This doesn't limit BQN's capabilities because it's easy to pass a list as an argument. In fact, "Aa" is a string, which means a list of characters. Characters are written with single quotes, so it's a list of 'A' and 'a'.

@@ -138,27 +139,26 @@
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"
-    Upper  -(-´"Aa")
+↗️
    hw  <˘ 2  "helloworld"
 
-    Upper(¨) hw
+    case.Upper(¨) hw
 ⟨ "Hello" "World" ⟩
 
-    hw Upper(¨)  # Sets new value for hw
+    hw case.Upper(¨)  # Sets new value for hw
 ⟨ "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"
 
-    Upper "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 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:

-↗️
    Upper¨ "hello""world"
+

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"
 ⟨ "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 Upper¨ means (Upper)¨.

+

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)¨.

Punctuation and printing

The variable hw is modified one more time, then printed, producing the output Hello, World!

•Out hw   ⥊⍉ [hw, ", ""!"]  # Hello, World!
-- 
cgit v1.2.3