GOLF(2gg)

πŸ“¦ version 601.4.41, in ubuntu questing

πŸ’– GOLF(2gg) β€” the read-lifo era πŸ’–

okay bestie, this one lives in the GOLF manual, section 2gg, and it's lowkey one of the most satisfying little commands in the whole dev toolbox. no cap. 🫢


✨ NAME ✨

read-lifo β€” (LIFO) πŸ₯ž


🎯 PURPOSE 🎯

Reads a key/value pair from a LIFO list. that's it. that's the whole job. and it eats every time. πŸ’…


🌸 SYNTAX 🌸

read-lifo <list> \
    key <key> \
    value <value> \
    [ status <status> ]

note the status clause is optional β€” the rest? mandatory, babes. ✨


πŸ’œ DESCRIPTION πŸ’œ

read-lifo retrieves an element from the LIFO <list> into the <key> string (that's the "key" clause) and the <value> string (that's the "value" clause). one element, two strings, iconic behaviour. πŸŽ€

Once an element has been retrieved, the next use of read-lifo will obtain the following one, in the reverse order they were put in. so it starts with the last element put in and moves backwards from there β€” unless rewind-lifo is called, which positions back to the last one. πŸ¦‹

also important: write-lifo will cause the next read-lifo to start with the element just written, i.e. it implicitly calls rewind-lifo. the way it just does that for you? main character energy fr fr. πŸ‘‘

If the element is successfully retrieved, the <status> number (the "status" clause) is GG_OKAY. otherwise it's GG_ERR_EXIST, which means there are no more elements to retrieve. that's your signal to stop looping, bestie, don't fight it. 😭


🌈 EXAMPLES 🌈

In this example, a LIFO list is created, and two key/value pairs added. They are then retrieved in a loop and printed out (twice with rewind), and then the list is purged. it's giving full life cycle. πŸ’–

%% /lifo public
    new-lifo mylist

    // Add data to the list
    write-lifo mylist key "key1" value "value1"
    write-lifo mylist key "some2" value "other2"

    start-loop
       // Get data from the list
       read-lifo mylist key k value v status st

       // Check if no more data
       if-true st not-equal GG_OKAY
           break-loop
       end-if

       @Obtained key <<print-out k>> with value <<print-out v>>
    end-loop

    // Go through the list again, use rewind-lifo for that
    rewind-lifo mylist

    start-loop
       read-lifo mylist key k value v status st
       if-true st not-equal GG_OKAY
           break-loop
       end-if
       @Again obtained key <<print-out k>> with value <<print-out v>>
    end-loop

    // Delete all in LIFO
    purge-lifo mylist
    // Verify nothing is left
    rewind-lifo mylist
    read-lifo mylist key k value v status st
    if-true st not-equal GG_OKAY
       @LIFO is empty
    end-if
%%

see how it loops, rewinds, loops again, then purges and confirms it's empty? that's the whole arc. character development. 🧚


πŸ‘€ SEE ALSO πŸ‘€

  • LIFO
  • delete-lifo
  • get-lifo
  • new-lifo
  • purge-lifo
  • read-lifo
  • rewind-lifo
  • write-lifo
  • See all documentation πŸ“š

and that's the page, babe. this manual was served up at version $VERSION back on $DATE β€” yeah, $DATE and $VERSION, that's the source stamp, keep it cute and keep it exact. GOLF(2gg) forever. πŸ’…βœ¨πŸŒΈπŸ¦‹πŸ’–

πŸ“¦ where this page comes from