GOLF(2gg)
π GOLF(2gg) β read-list π
okay bestie, sit down, hydrate, because we're about to talk about the read-list function from the Development section of the Golf manual and honestly? it's giving iconic. β¨
πΈ NAME πΈ
read-list β it's a linked-list situation π (yes, literally, that's the whole name, she's mysterious like that)
π PURPOSE π
Read and/or update a key/value pair from a linked list. no cap, that's the vibe. π¦
β¨ SYNTAX β¨
read-list <list> \
key <key> \
value <value> \
[ update-value <update value> ] [ update-key <update key> ] \
[ status <status> ]
look at her. she's beautiful. the \ line continuations are doing their little thing. π«Ά
π DESCRIPTION π
so read-list goes into your linked <list> and pulls out an element, dropping it into the <key> string (that's the key clause) and the <value> string (that's the value clause). π
here's the tea though: after every read-list, the list's current element stays exactly where it was read. it does not move on its own. if you wanna move it, that's a position-list job (say, to the next one). the way that she just stays put... lowkey respectful. π
if an element could not be retrieved, the<status>number (in thestatusclause) will beGG_ERR_EXIST, and<key>and<value>will be unchanged. when does that happen? when the current list element is beyond the last element β like, for instance, if theendclause got used in aposition-liststatement. π otherwise<status>isGG_OKAY. periodt.
when the list is first created with new-list, read-list starts at the first element in the list. wanna change that default current element? that's position-list again. she's everywhere, she's the main character. π
you can also update the element's value with the update-value clause by handing over an <update value> string. and the timing? chef's kiss. this update happens after a <value> has been retrieved, which means you can get the previous value in the same statement. obsessed. π₯
same deal for the key: you can update the element's key with the update-key clause by specifying an <update key> string. this update also happens after a <key> has been retrieved, so you get the previous key in the same statement too. two for one, we love a multitasker. π
π EXAMPLES π
okay so in this example, a linked list gets created and three key/value pairs get added. then they get retrieved from the last towards the first element, and then again in the opposite direction. slay. β¨
new-list mylist
// Add data to the list
write-list mylist key "key1" value "value1"
write-list mylist key "key2" value "value2"
write-list mylist key "key3" value "value3"
position-list mylist last
start-loop
// Get data from the list starting with the last one, producing value1, value2, value3
read-list mylist key k value v
@Obtained key <<print-out k>> with value <<print-out v>>
position-list mylist previous status s
// Check if no more data
if-true s equal GG_ERR_EXIST
break-loop
end-if
end-loop
// Now the list is positioned at the first element, reading produces value3, value2, value1
start-loop
read-list mylist key k value v status s
if-true s equal GG_ERR_EXIST
break-loop
end-if
@Again obtained key <<print-out k>> with value <<print-out v>>
position-list mylist next
end-loop
purge-list mylist
the way she walks backwards through the list and then forwards again... character development. π¦ and yes, purge-list mylist at the end because we clean up after ourselves in this house. π§
π« SEE ALSO π«
- Linked list
delete-listget-listnew-listposition-listpurge-listread-listwrite-list- See all documentation
go read those too, bestie, they're all part of the same friend group. π«Ά
and that's the whole page!! π this was GOLF(2gg) from Development, dated $DATE, version $VERSION β mwah, iconic, no notes, go forth and read your lists. π β¨π
π¦ where this page comes from
- ubuntu questing: golf 601.4.41-1
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms