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 --- doc/control.md | 6 +++--- docs/doc/control.html | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/doc/control.md b/doc/control.md index 782f1541..e65ee006 100644 --- a/doc/control.md +++ b/doc/control.md @@ -11,7 +11,7 @@ The surfeit of ways to write control structures could be a bit of an issue for r 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 𝕩}@} @@ -77,7 +77,7 @@ Despite the name, an if-else statement is most closely related to a [switch-case 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 ⟨𝕩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   {cFT: cTF@}
+IfElse   {cTF: cFT@}
 While    {𝕨{𝕊𝔾𝔽𝕩}𝕩@}´        # While 1‿{... to run forever
 DoWhile  {𝕨{𝕊𝔽𝔾𝕩}𝕩@}´
 For      {ICPA: I@  {𝕊PAC 𝕩}@}
@@ -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  {condFalseTrue: condTrueFalse @}
+
IfElse  {condTrueFalse: condFalseTrue @}
 
 IfElse 𝕩<mid𝕨
   {𝕤 himid}
@@ -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{CondAct 𝕊 else: CondActElse}´𝕩  Fn@}
+
Test  {fn{CondAct 𝕊 else: CondElseAct}´𝕩  Fn@}
 
 Test 
   (  a<b){𝕤a+1}
-- 
cgit v1.2.3