diff options
Diffstat (limited to 'docs/doc/block.html')
| -rw-r--r-- | docs/doc/block.html | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/docs/doc/block.html b/docs/doc/block.html index ec9e4ed9..cfffe895 100644 --- a/docs/doc/block.html +++ b/docs/doc/block.html @@ -176,7 +176,7 @@ <p>Unlike these assignments, the header also constrains what inputs the block can take: a monadic 1-modifier like the one above can't take a right operand or left argument, so its body can't contain <code><span class='Function'>𝔾</span></code> or <code><span class='Value'>𝕨</span></code>. Calling it with a left argument, or a right argument that isn't a two-element list, will result in an error.</p> <h3 id="destructuring"><a class="header" href="#destructuring">Destructuring</a></h3> <p>Arguments and operands allow <a href="expression.html#destructuring">destructuring</a> like assignment does. While assignment only tolerates lists of variables, header destructuring also allows constants. For the header to match, the argument must share the given structure, including the constants where they appear.</p> -<a class="replLink" title="Open in the REPL" target="_blank" href="https://mlochbaum.github.io/BQN/try.html#code=RGVzdHJ1Y3Qg4oaQIHsg8J2ViiBh4oC/MeKAv+KfqGIswrcsMuKfqTogYeKJjWIgfQpEZXN0cnVjdCAgICAgICA14oC/MeKAv+KfqDcsz4AsMuKfqQ==">↗️</a><pre> <span class='Function'>Destruct</span> <span class='Gets'>←</span> <span class='Brace'>{</span> <span class='Function'>𝕊</span> <span class='Value'>a</span><span class='Ligature'>‿</span><span class='Number'>1</span><span class='Ligature'>‿</span><span class='Bracket'>⟨</span><span class='Value'>b</span><span class='Separator'>,</span><span class='Nothing'>·</span><span class='Separator'>,</span><span class='Number'>2</span><span class='Bracket'>⟩</span><span class='Head'>:</span> <span class='Value'>a</span><span class='Function'>≍</span><span class='Value'>b</span> <span class='Brace'>}</span> +<a class="replLink" title="Open in the REPL" target="_blank" href="https://mlochbaum.github.io/BQN/try.html#code=YeKGkGLihpAib3V0ZXIiCkRlc3RydWN0IOKGkCB7IPCdlYogYeKAvzHigL/in6hiLMK3LDLin6k6IGHiiY1iIH0KRGVzdHJ1Y3QgICAgICAgNeKAvzHigL/in6g3LM+ALDLin6k=">↗️</a><pre> <span class='Function'>Destruct</span> <span class='Gets'>←</span> <span class='Brace'>{</span> <span class='Function'>𝕊</span> <span class='Value'>a</span><span class='Ligature'>‿</span><span class='Number'>1</span><span class='Ligature'>‿</span><span class='Bracket'>⟨</span><span class='Value'>b</span><span class='Separator'>,</span><span class='Nothing'>·</span><span class='Separator'>,</span><span class='Number'>2</span><span class='Bracket'>⟩</span><span class='Head'>:</span> <span class='Value'>a</span><span class='Function'>≍</span><span class='Value'>b</span> <span class='Brace'>}</span> <span class='Function'>Destruct</span> <span class='Number'>5</span><span class='Ligature'>‿</span><span class='Number'>1</span><span class='Ligature'>‿</span><span class='Bracket'>⟨</span><span class='Number'>7</span><span class='Separator'>,</span><span class='Number'>π</span><span class='Separator'>,</span><span class='Number'>2</span><span class='Bracket'>⟩</span> ⟨ 5 7 ⟩ </pre> @@ -219,12 +219,12 @@ ⟨ 2 4 ⟩ </pre> <p>If no header is compatible, the call results in an error.</p> -<a class="replLink" title="Open in the REPL" target="_blank" href="https://mlochbaum.github.io/BQN/try.html#code=MyBDYXNlQWRkIDM=">↗️</a><pre> <span class='Number'>3</span> <span class='Function'>CaseAdd</span> <span class='Number'>3</span> +<a class="replLink" title="Open in the REPL" target="_blank" href="https://mlochbaum.github.io/BQN/try.html#code=Q2FzZUFkZCDihpAgewogIDLwnZWKMzogMOKAvzUgOwogIDLwnZWK8J2VqTog4p+oMSwyK/Cdlanin6kgOwogICDwnZWK8J2VqTogMuKAv/CdlakKfQozIENhc2VBZGQgMw==">↗️</a><pre> <span class='Number'>3</span> <span class='Function'>CaseAdd</span> <span class='Number'>3</span> <span class='Error'>Error: No header matched arguments</span> </pre> <h3 id="case-headers"><a class="header" href="#case-headers">Case headers</a></h3> <p>A special rule allows for convenient case-matching syntax for one-argument functions. In any function header with one argument, the function name can be omitted as long as the argument is <em>not</em> a plain identifier—it must be <code><span class='Value'>𝕩</span></code> or a compound value like a list to distinguish it from an immediate block label.</p> -<a class="replLink" title="Open in the REPL" target="_blank" href="https://mlochbaum.github.io/BQN/try.html#code=VGVzdCDihpAgewogICJhYmMiOiAic3RyaW5nIiA7CiAg4p+oMixi4p+pOiDijL3wnZWpICAgICAgIDsKICA1OiAgICAgIm51bWJlciIgOwogIPCdlak6ICAgICAiZGVmYXVsdCIKfQpUZXN0IDU=">↗️</a><pre> <span class='Function'>Test</span> <span class='Gets'>←</span> <span class='Brace'>{</span> +<a class="replLink" title="Open in the REPL" target="_blank" href="https://mlochbaum.github.io/BQN/try.html#code=YeKGkGLihpAib3V0ZXIiClRlc3Qg4oaQIHsKICAiYWJjIjogInN0cmluZyIgOwogIOKfqDIsYuKfqTog4oy98J2VqSAgICAgICA7CiAgNTogICAgICJudW1iZXIiIDsKICDwnZWpOiAgICAgImRlZmF1bHQiCn0KVGVzdCA1">↗️</a><pre> <span class='Function'>Test</span> <span class='Gets'>←</span> <span class='Brace'>{</span> <span class='String'>"abc"</span><span class='Head'>:</span> <span class='String'>"string"</span> <span class='Head'>;</span> <span class='Bracket'>⟨</span><span class='Number'>2</span><span class='Separator'>,</span><span class='Value'>b</span><span class='Bracket'>⟩</span><span class='Head'>:</span> <span class='Function'>⌽</span><span class='Value'>𝕩</span> <span class='Head'>;</span> <span class='Number'>5</span><span class='Head'>:</span> <span class='String'>"number"</span> <span class='Head'>;</span> @@ -236,7 +236,7 @@ <p>These case-style headers function exactly the same as if they were preceded by <code><span class='Function'>𝕊</span></code>, and can be mixed with other kinds of headers.</p> <h3 id="predicates"><a class="header" href="#predicates">Predicates</a></h3> <p>Destructuring with a header is limited, as it can only match a particular structure or value exactly—not, for example, a range of lengths. A predicate, written with <code><span class='Head'>?</span></code>, allows you to test an arbitrary property before evaluating the rest of the body, and also serves as a limited kind of control flow. It can be thought of as an extension to a header. So the following function requires the argument to have two elements and for the first to be less than the second before using the first body. Otherwise it moves to the next body, which is unconditional.</p> -<a class="replLink" title="Open in the REPL" target="_blank" href="https://mlochbaum.github.io/BQN/try.html#code=Q2hlY2tQYWlyIOKGkCB7IPCdlYrin6hhLGLin6k6IGE8Yj8gIm9rIiA7ICJub3Qgb2siIH0KCkNoZWNrUGFpciDin6gzLDjin6kgICAgIyBGYWlscyBkZXN0cnVjdHVyaW5nCgpDaGVja1BhaXIg4p+oMSw0LDXin6kgICMgTm90IGEgcGFpcgoKQ2hlY2tQYWlyIOKfqDMswq8x4p+pICAgIyBOb3QgYXNjZW5kaW5n">↗️</a><pre> <span class='Function'>CheckPair</span> <span class='Gets'>←</span> <span class='Brace'>{</span> <span class='Function'>𝕊</span><span class='Bracket'>⟨</span><span class='Value'>a</span><span class='Separator'>,</span><span class='Value'>b</span><span class='Bracket'>⟩</span><span class='Head'>:</span> <span class='Value'>a</span><span class='Function'><</span><span class='Value'>b</span><span class='Head'>?</span> <span class='String'>"ok"</span> <span class='Head'>;</span> <span class='String'>"not ok"</span> <span class='Brace'>}</span> +<a class="replLink" title="Open in the REPL" target="_blank" href="https://mlochbaum.github.io/BQN/try.html#code=YeKGkGLihpAib3V0ZXIiCkNoZWNrUGFpciDihpAgeyDwnZWK4p+oYSxi4p+pOiBhPGI/ICJvayIgOyAibm90IG9rIiB9CgpDaGVja1BhaXIg4p+oMyw44p+pICAgICMgRmFpbHMgZGVzdHJ1Y3R1cmluZwoKQ2hlY2tQYWlyIOKfqDEsNCw14p+pICAjIE5vdCBhIHBhaXIKCkNoZWNrUGFpciDin6gzLMKvMeKfqSAgICMgTm90IGFzY2VuZGluZw==">↗️</a><pre> <span class='Function'>CheckPair</span> <span class='Gets'>←</span> <span class='Brace'>{</span> <span class='Function'>𝕊</span><span class='Bracket'>⟨</span><span class='Value'>a</span><span class='Separator'>,</span><span class='Value'>b</span><span class='Bracket'>⟩</span><span class='Head'>:</span> <span class='Value'>a</span><span class='Function'><</span><span class='Value'>b</span><span class='Head'>?</span> <span class='String'>"ok"</span> <span class='Head'>;</span> <span class='String'>"not ok"</span> <span class='Brace'>}</span> <span class='Function'>CheckPair</span> <span class='Bracket'>⟨</span><span class='Number'>3</span><span class='Separator'>,</span><span class='Number'>8</span><span class='Bracket'>⟩</span> <span class='Comment'># Fails destructuring </span>"ok" |
