From c5eef0418df2ae6a97c54839fa010ff60d96f78b Mon Sep 17 00:00:00 2001 From: Marshall Lochbaum Date: Sat, 8 Jan 2022 16:14:51 -0500 Subject: =?UTF-8?q?Add=20error=20messages=20to=20generated=20markdown=20do?= =?UTF-8?q?cs=20with=20=E2=80=A2CurrentError=20(fixes=20#22)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/tutorial/list.html | 2 +- docs/tutorial/variable.html | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) (limited to 'docs/tutorial') diff --git a/docs/tutorial/list.html b/docs/tutorial/list.html index 4df69829..35853585 100644 --- a/docs/tutorial/list.html +++ b/docs/tutorial/list.html @@ -338,7 +338,7 @@

Multiplication is harder, and if we try to multiply by the place value list directly it doesn't go so well.

↗️
    (2⋆↕8) × '0' -˜ "01001110""01100101""01110010""01100100""00100001"
-ERROR
+Error: ×: Expected equal shape prefix (⟨8⟩ ≡ ≢𝕨, ⟨5⟩ ≡ ≢𝕩)
 

This is because the list on the left has length 8 while the list on the right has length 5. The elements of the list on the right have length 8, but BQN can't be expected to know you want to connect the two arguments in that particular way. Especially considering that if you happen to have 8 characters then the right argument will have length 8!

There are a few ways to handle this. What we'll do is bind the place values to × using the 2-modifier . This modifier attaches a left argument to a function.

diff --git a/docs/tutorial/variable.html b/docs/tutorial/variable.html index 634bd5d5..16186db4 100644 --- a/docs/tutorial/variable.html +++ b/docs/tutorial/variable.html @@ -25,7 +25,7 @@

A variable can't be defined twice in the same scope. Later we'll work with functions and other pieces of code that create their own scopes, but for now all you need to know is that all the code in a tutorial runs in the same scope. So three is already defined, and can't be defined again.

↗️
    three  4
-ERROR
+Error: Redefinition
 

It's a little crazy to call them variables if the definition can never change, right? Doesn't "variable" mean "able to change"? Fortunately, this is one way in which BQN isn't crazy. You can modify a variable's value with the arrow provided it's already been defined. This never does anything to the original value: that value stays the same; it's just (probably) not the value of the modified variable any more.

↗️
    three  4
@@ -37,12 +37,12 @@ ERROR
 1
 
     four  3    # four isn't defined yet
-ERROR
+Error: Undefined identifier
 

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

↗️
    BQN  "[many pages of specification]"
-ERROR
+Error: Role of the two sides in assignment must match
 

What's going on? Does BQN not know about capital letters? Does it object to self-reference? Why is "BQN" green?

If you open that statement in the online REPL, you'll see the more informative message "Role of the two sides in assignment must match" (assignment means anything written with a leftward arrow—either definition or modification). This is still cryptic but at least a "role" is something we've heard about before.

@@ -65,7 +65,7 @@ ERROR -3{𝔽} - _three -ERROR +Error: Interpreting non-1-modifier as 1-modifier

Now might be a good time to review the earlier material on roles, experiment, and see if you can puzzle out what's happening here. Or a good time to keep reading until the horrifying distortions these texts inevitably wrap around your existence become apparent, so I'll explain that all these names do represent the same value—they all refer to the same variable—but they have different syntactic roles. Just as the same person might sometimes stand in front of the counter to order a coffee and sometimes stand behind it pouring coffee, the same variable is spelled different ways to indicate what it might be doing right now. There's a spelling for each role:

-- cgit v1.2.3