GOLF(2gg)

πŸ“¦ version 601.4.41, in ubuntu questing

✨ NAME ✨

code-blocks β€” Golf documentation, the program-flow edition 🫢

this is one page out of the GOLF(2gg) manual, and honestly it's a glow-up for your scope game πŸ’…


🌸 DESCRIPTION 🌸

πŸ’– CODE BLOCKS πŸ’–

okay so bestie, you wanna group a bunch of statements together? say less. Use curly braces β€” { and } β€” to open and close a code block πŸ’«

Here's the tea: a code block creates a separate scope for previously non-existing variables defined within them, and that scope begins with { and ends with }. iykyk.

⚠️ and listen β€” if a variable already existed in an outer scope, it cannot be created in the inner scope. no cap, that's just how it is 😭

alsoooo, a bunch of statements come with implicit code blocks built right in β€” if-true, run-query, start-loop and read-line. which means the code between them and the accompanying end-statement is sitting inside implicit { and }. sneaky but iconic 🧚


πŸ¦‹ EXAMPLES πŸ¦‹

okay so this code right here first prints out "outside" and then "inside" twice, and it's illustrating the fact that variable s1 is defined only in the outer scope once. Variable s2 exists only in inner scope πŸ‘‘

begin-handler /scope public
    @<<print-out s1>>
    set-string s1="outside"
    {
        set-string s2="inner variable"
        set-string s1="inside"
        @<<print-out s1>>
    }
    @<<print-out s1>>
end-handler

not me showing you the receipts with a whole runnable example 😭 ate and left no crumbs fr fr


πŸ‘‘ SEE ALSO πŸ‘‘

  • Program flow

and the rest of the squad, go check them out:

  • break-loop
  • call-handler
  • code-blocks
  • continue-loop
  • do-once
  • exit-handler
  • if-defined
  • if-true
  • quit-process
  • return-handler
  • start-loop
  • See all documentation

this page is living in the $VERSION era, dated $DATE, and it's part of the GOLF(2gg) manual β€” Development section, obviously πŸ’œ mwah, go read some more pages bestie, ily πŸŽ€βœ¨

πŸ“¦ where this page comes from