From 2afb23928e1984d475cc460e1672e8f6fa0e4dbe Mon Sep 17 00:00:00 2001 From: Marshall Lochbaum Date: Wed, 11 Aug 2021 17:21:31 -0400 Subject: Allow clicking on header to get fragment link --- docs/tutorial/variable.html | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'docs/tutorial/variable.html') diff --git a/docs/tutorial/variable.html b/docs/tutorial/variable.html index 33f1e48c..e8a1f06e 100644 --- a/docs/tutorial/variable.html +++ b/docs/tutorial/variable.html @@ -4,7 +4,7 @@ BQN Tutorial: Variables -

Tutorial: Variables

+

Tutorial: Variables

To take a proud denizen of the eternal cosmos of values, held for a fleeting instant by the course of code, and bind it. Tie it down with a name, failing always to alter its inner nature but allowing context to reform its outer appearance. So labelled, perhaps through the progress of time it will know escape, or else find itself passed through one bond to another, ever tethered. It's a task to be approached only with respect.

↗️
    hey  "Hi there"
 
@@ -12,7 +12,7 @@
 "Hi there, World!"
 

Like that.

-

Defining variables

+

Defining variables

BQN uses the left-pointing arrow to define variables, as shown above. Most of the time it's best to use it in a plain way, with just the name and its definition, but it's also possible to define multiple variables using list notation, or to define a variable as part of a larger expression that continues to the left (in terms of precedence, behaves like a function, but it isn't one—it's a part of syntax).

↗️
    pieten   π, 1, 10 
 ⟨ 3.141592653589793 2.718281828459045 10 ⟩
@@ -40,7 +40,7 @@ ERROR
 ERROR
 

It's an odd distinction to have when your program is just one long sequence of statements, because there's only ever one arrow you can use: it just changes annoyingly after you define the variable for the first time. With multiple scopes this isn't the case: if you start a new scope inside another, then you'll still be able to use variables from the outside scope. Then lets you change the value of one of these variables while allows you to define your own. If you're coming from a typical curly-brace language, you'd say that both declares and assigns a variable, while only assigns it.

-

Variable roles

+

Variable roles

↗️
    BQN  "[many pages of specification]"
 ERROR
 
@@ -104,7 +104,7 @@ ERROR ↗️
    1_000_000
 1000000
 
-

Function assignment

+

Function assignment

While you could build up a script by computing values and assigning them names, the main way to use assignment in tacit programming is to give names to functions, not data. For example, we might name the base-2 conversion function from our last tutorial:

↗️
    Base2  +(2×)´
 
@@ -130,7 +130,7 @@ ERROR
     Base2 6
 16
 
-

Modifying part of an array

+

Modifying part of an array

You cannot modify part of an array. You can't modify an array: an array that differs a little bit from another array is a different array. And this isn't just a terminology choice: it has real effects on how BQN arrays behave and even which arrays are representable, as we'll discuss later.

But say I have a list, and I want to subtract one from one of the elements. With the understanding that the resulting list is different from the first one, BQN allows this!

↗️
    "BQN"            # A list of characters
@@ -252,7 +252,7 @@ ERROR
 "abcdEFgh"
 

(Here I've snuck in a train 2 4 to combine the two functions. As an exercise, you might try to write that function using combinators instead, and as an extra hard exercise you might then ponder why someone would want to add trains to a language).

-

Identity functions

+

Identity functions

@@ -282,7 +282,7 @@ ERROR "left"

They are not complicated functions: if you're confused it's because you don't understand why anyone would ever use them. Indeed, it's harder to see why these functions are useful than to see what they do. That is a fact.

-

Modified assignment

+

Modified assignment

Let's revisit our question about modifying an array. As we said, the answer to "how do I modify part of an array?" is simply that you can't, and that the question doesn't make sense. But there's a seemingly similar question with a very different answer: "how do I modify part of a variable whose value is an array?" This is because unlike an array, a variable isn't defined by the value it has, but by the name used to refer to it (and the scope it resides in). Here's how we would modify the variable a:

↗️
    a  4            # First it's a number
     a
-- 
cgit v1.2.3