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/doc/lexical.html | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'docs/doc/lexical.html') diff --git a/docs/doc/lexical.html b/docs/doc/lexical.html index ec3f6567..dcc5fef0 100644 --- a/docs/doc/lexical.html +++ b/docs/doc/lexical.html @@ -62,7 +62,7 @@

Each scope can only define a given name once. Trying to shadow a name that's in the current scope and not a higher one gives an error at compilation.

↗️
    { inc3  inc4 }
-ERROR
+Error: Redefinition
 

Let's go all in on shadowing and make a modifier that creates its own copies of counter and inc, returning a custom version of the Count function above.

↗️
    _makeCount  { counterinc𝕗  { counter + 𝕩 × inc } }
@@ -85,7 +85,7 @@ ERROR
 

But you'll still get an error if the variable is used before its definition is run. Unlike the single-level case, this is a runtime error and only appears when the variable is actually accessed.

↗️
    { 2+d }  d¯2
-ERROR
+Error: Reading variable before its defined
 

Why define things this way? It's easier to see if you imagine the variable used is also a function. It's normal for a function to call other functions defined at the top level, of course. And it would be pretty unpleasant for BQN to enforce a specific ordering for them. It would also make recursive functions impossible except by using 𝕊, and mutually recursive ones completely impossible. A simple rule that makes all these things just work smoothly seems much better than any alternative.

Closures

@@ -140,6 +140,6 @@ ERROR

Only code with access to a variable can modify it! This means that if none of the code in a variable's scope modifies it, then the variable is a constant in each environment that contains it (not necessarily across environments). That is, constant once it's defined: it's still possible to get an error if the variable is accessed before being defined.

↗️
    { { a }  a4 }
-ERROR
+Error: Reading variable before its defined
 

With lexical scoping, variable mutation automatically leads to mutable data. This is because a function or modifier that depends on the variable value changes its behavior when the variable changes. For further discussion see the documentation on mutable objects.

-- cgit v1.2.3