From 1518205cceeb1fef27c584d24e92b189ffd234f4 Mon Sep 17 00:00:00 2001 From: Marshall Lochbaum Date: Sun, 2 Oct 2022 21:29:30 -0400 Subject: Grammar --- docs/doc/quick.html | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'docs') diff --git a/docs/doc/quick.html b/docs/doc/quick.html index cbda94a9..5b7061a9 100644 --- a/docs/doc/quick.html +++ b/docs/doc/quick.html @@ -210,7 +210,7 @@

First, Split requires that the rank =𝕩 be 1, that is, 𝕩 must be a list. In 1==𝕩, = has two meanings, depending on whether it has a left argument. Next, it checks that each element has a character type.

The subexpression !2=β€’Type is a function train, and it happens to have a simple expansion, as (!2=β€’Type)e is !2=β€’Type e. It matters that 2 is just a number; if it were a function it would be applied to e. We'll discuss trains more later. This one is applied with Each to test every element of 𝕩. This does form an array result, but it's not used.

Subfunction

-

The function Proc is called on each character of 𝕩 along with the previous character, and says what to at that position. Also, it's deliberately inconsistent to cover more BQN features. Here's the whole thing:

+

The function Proc is called on each character of 𝕩 along with the previous character, and says what to do at that position. Also, it's deliberately inconsistent to cover more BQN features. Here's the whole thing:

Proc ← {
   Β· π•Š ' ': spl⇐1 ;             # Space: break and delete it
   prev Fn cur: ⟨spl,strβŸ©β‡
@@ -226,7 +226,7 @@
 

This function has two bodies with ; in between. Each one has a header, separated from the body with a :. A header indicates the kind of the block as a whole, and also which inputs the body after it works on. It mirrors the way the block should be used. In the right context, both Β· π•Š ' ' and prev Fn cur would be valid function calls. Which tells us Proc is a function.

The first header, Β· π•Š ' ':, is more specific. The function is unlabelled, since π•Š just indicates the block function it's in (useful for recursion). The right argument is ' ', a space character, so this body will only be used if 𝕩 is a space. And the left argument is… Β·, which is called Nothing. Both here and as an assignment target, Nothing indicates an ignored value. This body does require a left argument, but it doesn't name it. And the body itself is just spl⇐1. The ⇐ makes this body (only this one!) return a namespace, which has only the field spl.

-

The next header, prev Fn cur: sets names for the function and its arguments, but doesn't constrain them other than requiring two arguments. So it applies in all the cases where the previous one didn't match, that is, when 𝕩 isn't ' '. The body starts with ⟨spl,strβŸ©β‡, and the ⇐ means it will return a namespace too. This is an export statement, which declares spl and str to be fields but doesn't define themβ€”they must be defined somewhere else in the block, which is what happens next.

+

The next header, prev Fn cur:, sets names for the function and its arguments, but doesn't constrain them other than requiring two arguments. So it applies in all the cases where the previous one didn't match, that is, when 𝕩 isn't ' '. The body starts with ⟨spl,strβŸ©β‡, and the ⇐ means it will return a namespace too. This is an export statement, which declares spl and str to be fields but doesn't define themβ€”they must be defined somewhere else in the block, which is what happens next.

prev Fn cur: ⟨spl,strβŸ©β‡
   spl←0 β‹„ strβ†βŸ¨cur⟩          # Include and don't break...
   { prev=cur ? spl+↩1 ; @ }  # except at equal characters
@@ -240,7 +240,7 @@
                 {𝕩.spl} ⟩
 

Going left to right, GVβ€ΏGS indicates destructuring assignment, which will expect a list of two values on the right and take it apart to assign the two names. The right hand side is the function {𝕏¨}Β¨ applied to a list.

-

{𝕏¨} is a block function, like Split but a lot shorter. It uses the uppercase 𝕏 instead of 𝕩, so that it treats 𝕩 as a function (it doesn't require it to be a function, though: see mixing roles. It adds an Each Β¨ onto its argument. This is used to convert the two functions in the list from functions that work on a namespaces to functions that work on a list of them.

+

{𝕏¨} is a block function, like Split but a lot shorter. It uses the uppercase 𝕏 instead of 𝕩, so that it treats 𝕩 as a function (it doesn't require it to be a function, though: see mixing roles). It adds an Each Β¨ onto its argument. This is used to convert the two functions in the list from functions that work on a namespaces to functions that work on a list of them.

The list is split across two lines, using newline as a separator instead of , or β‹„. Its second function {𝕩.spl} is simpler: it takes a namespace 𝕩 and gets the field named spl.

The first function is more complicated, because the argument namespace might or might not have an str field. The list-like notation ⟨s⇐str⟩ is another example of destructuring assignment, but this time it destructures a namespace, using an alias to give it a short name. This header leaves off the function name π•Š, using a special rule for one-argument functions. Arguments in headers are very similar to assignment targets, but if the destructuring doesn't match it tries the next body (if there is one) instead of giving an error. So if the argument is a namespace with an str field then {⟨s⇐str⟩:s;""} returns that field's value, and otherwise it returns "".

Assembly

-- cgit v1.2.3