-
Notifications
You must be signed in to change notification settings - Fork 24
feat(Fift): Control flow page #1541
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the detailed Fift control-flow docs; I’ve left several suggestions in languages/fift/control.mdx: please apply the inline suggestions to align placeholders, links, and error messages with the style guide.
languages/fift/control.mdx
Outdated
|
|
||
| In the above example, block `{ 2 * }` acts as the "anonymous function" `x -> 2x` that gets applied twice on `17`, producing the result `2 * (2 * 17) = 68`. The above examples show that a block is an execution token, which can be duplicated, stored into a constant, used to define a new word, or executed. | ||
|
|
||
| The word `' <word-name>` recovers the current definition of a word. Namely, `' <word-name>` pushes the execution token equivalent to the current definition of the word `<word-name>`. For instance, the following two lines are equivalent: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[HIGH] Non-conforming placeholder names
The ' <word-name> placeholder in the Blocks section uses a lowercase, hyphenated form instead of the <ANGLE_CASE> pattern required by the style guide (for example <WORD_NAME>). This makes placeholder usage inconsistent and harder to scan across the documentation. A similar non-conforming placeholder appears later in the exceptions section around abort"<message>" and its description of the thrown message (languages/fift/control.mdx L396–L398), which should also follow the <ANGLE_CASE> convention. Normalizing these placeholders to the prescribed pattern improves readability and keeps examples aligned with the global placeholder rules.
| The word `' <word-name>` recovers the current definition of a word. Namely, `' <word-name>` pushes the execution token equivalent to the current definition of the word `<word-name>`. For instance, the following two lines are equivalent: | |
| The word `' <WORD_NAME>` recovers the current definition of a word. Namely, `' <WORD_NAME>` pushes the execution token equivalent to the current definition of the word `<WORD_NAME>`. For instance, the following two lines are equivalent: |
Please leave a reaction 👍/👎 to this suggestion to improve future reviews for everyone!
| // Stack: 1000 | ||
| ``` | ||
|
|
||
| The next is a more complex example that modifies slightly the factorial function defined in the section for [fixed repeat loops](#fixed-repeat-loops). `fact-input` below defines a word that computes the smallest integer that would produce a factorial bigger or equal to the integer at the top of the stack. For example, `10 fact-input` produces `4`, because `4! = 24 >= 10` and `4` is the smallest integer `x` such that `x! >= 10`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[HIGH] Internal link is not root-absolute
Line 316 links to the “fixed repeat loops” section using only a fragment (#fixed-repeat-loops) instead of a root-absolute URL. The extended style guide explicitly requires internal links in Markdown/MDX to start with / and forbids relative segments or bare fragments for internal targets (see https://github.com/ton-org/docs/blob/main/contribute/style-guide-extended.mdx?plain=1#L753-L755). Using a fragment-only URL makes the link brittle if the page is moved or split, and violates the internal-link formatting rule. Updating this to a root-absolute path with the same anchor preserves correct navigation and keeps the page compliant with the documented link rules.
| The next is a more complex example that modifies slightly the factorial function defined in the section for [fixed repeat loops](#fixed-repeat-loops). `fact-input` below defines a word that computes the smallest integer that would produce a factorial bigger or equal to the integer at the top of the stack. For example, `10 fact-input` produces `4`, because `4! = 24 >= 10` and `4` is the smallest integer `x` such that `x! >= 10`. | |
| The next is a more complex example that modifies slightly the factorial function defined in the section for [fixed repeat loops](/languages/fift/control#fixed-repeat-loops). `fact-input` below defines a word that computes the smallest integer that would produce a factorial bigger or equal to the integer at the top of the stack. For example, `10 fact-input` produces `4`, because `4! = 24 >= 10` and `4` is the smallest integer `x` such that `x! >= 10`. |
Please leave a reaction 👍/👎 to this suggestion to improve future reviews for everyone!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this really an issue?
languages/fift/control.mdx
Outdated
| For instance, word `safe/` below is a safe division that checks if the divisor is zero or not. Executing `5 0 safe/` throws an exception with message `safe/: Division by zero` and clears the stack. But executing `5 2 safe/` produces `2` at the top of the stack, since `5/2 = 2` and the divisor `2` is non-zero. | ||
|
|
||
| ```fift | ||
| { dup 0= abort"Division by zero" / } : safe/ | ||
| ``` | ||
|
|
||
| Additionally, when the Fift interpreter encounters an unknown word that cannot be parsed as an integer literal, an exception with the message `"-?"` is thrown and the stack is cleared. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[HIGH] Error messages rendered as code instead of quoted strings
In the exceptions section, the error messages safe/: Division by zero and "-?" are formatted as inline code spans instead of as literal strings in double quotation marks. The style guide requires log and error messages to appear verbatim in quotes so they are easy to copy, search, and distinguish from code identifiers. Leaving them as code formatting blurs the distinction between program text and runtime output and makes it harder to grep for these messages in logs or source. Representing them as plain quoted strings keeps error documentation consistent and improves usability.
Please leave a reaction 👍/👎 to this suggestion to improve future reviews for everyone!
Closes #1539.