From d22b685b0135e0e36fa02b9e0f4336c6893d0b0f Mon Sep 17 00:00:00 2001 From: Marshall Lochbaum Date: Fri, 9 Apr 2021 08:08:14 -0400 Subject: Fix some swapped identifiers --- docs/doc/control.html | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'docs/doc') diff --git a/docs/doc/control.html b/docs/doc/control.html index ab006e98..c00ce6e5 100644 --- a/docs/doc/control.html +++ b/docs/doc/control.html @@ -10,7 +10,7 @@

The surfeit of ways to write control structures could be a bit of an issue for reading BQN. My hope is that the community can eventually settle on a smaller set of standard forms to recommend so that you won't have to recognize all the variants given here. On the other hand, the cost of using specialized control structures is lower in a large project without too many contributors. In this case BQN's flexibility allows developers to adapt to the project's particular demands (for example, some programs use switch/case statements heavily but most do not).

The useful control structures introduced here are collected as shortened definitions below.

If      โ† {๐•โŸ๐•Ž@}ยด               # Also Repeat
-IfElse  โ† {cโ€ฟFโ€ฟT: cโ—ถTโ€ฟF@}
+IfElse  โ† {cโ€ฟTโ€ฟF: cโ—ถFโ€ฟT@}
 While   โ† {๐•จ{๐•Šโˆ˜๐”พโŸ๐”ฝ๐•ฉ}๐•ฉ@}ยด        # While 1โ€ฟ{... to run forever
 DoWhile โ† {๐•จ{๐•ŠโŸ๐”ฝ๐”พ๐•ฉ}๐•ฉ@}ยด
 For     โ† {Iโ€ฟCโ€ฟPโ€ฟA: I@ โ‹„ {๐•Šโˆ˜Pโˆ˜AโŸC ๐•ฉ}@}
@@ -60,7 +60,7 @@
 

If-Else

Despite the name, an if-else statement is most closely related to a switch-case statement: in fact, it's just a special case where the two cases are true (1) and false (0). As a result, we can implement it either with Choose (โ—ถ) or with case headers of 1 and 0.

When using Choose, note that the natural ordering places the false case before the true one to match list index ordering. To get the typical if-else order, the condition should be negated or the statements reversed. Here's a function to get an if-else statement by swapping the conditions, and two ways its application might be written.

-
IfElse โ† {condโ€ฟFalseโ€ฟTrue: condโ—ถTrueโ€ฟFalse @}
+
IfElse โ† {condโ€ฟTrueโ€ฟFalse: condโ—ถFalseโ€ฟTrue @}
 
 IfElse โŸจ๐•ฉ<midโŠ‘๐•จ
   {๐•คโ‹„ hiโ†ฉmid}
@@ -84,7 +84,7 @@
 

Chained If-Else

One pattern in imperative languages is to check one condition and apply an action if it succeeds, but check a different condition if it fails, in sequence until some condition succeeds or every one has been checked. Languages might make this pattern easier by making if-else right associative, so that the programmer can write an if statement followed by a sequence of else if "statements", or might just provide a unified elif keyword that works similarly (while this is a common pattern, I suspect it's used more often than it's really wanted because of this syntactic support).

In BQN it's possible to nest IfElse expressions, but it's also possible to write a control structure that chains them all at one level. For this statement the input will be a sequence of โŸจTest,ActionโŸฉ pairs, followed by a final action to perform if no test succeeds. The first test is always performed; other tests should be wrapped in blocks because otherwise they'll be executed even if an earlier test succeeded.

-
Test โ† {fnโ†{Condโ€ฟAct ๐•Š else: Condโ—ถActโ€ฟElse}ยด๐•ฉ โ‹„ Fn@}
+
Test โ† {fnโ†{Condโ€ฟAct ๐•Š else: Condโ—ถElseโ€ฟAct}ยด๐•ฉ โ‹„ Fn@}
 
 Test โŸจ
   (  a<b)โ€ฟ{๐•คโ‹„a+โ†ฉ1}
-- 
cgit v1.2.3