GOLF(2gg)
π GOLF(2gg) β the write-list page, bestie edition π
okay so we're in the Development corner of the manual (that's the 2gg section, iykyk) and today's main character is write-list. it's part of the linked-list fam. let's get into it π«Ά
β¨ NAME β¨
write-list β (linked-list)
π PURPOSE π
write a key/value pair into a linked list. that's it. that's the whole job. slay. π
πΈ SYNTAX πΈ
write-list <list> key <key> \
value <value> \
[ append [ <append> ] ]
π¦ DESCRIPTION π¦
so write-list takes a pair of key/value strings and adds them to the linked <list> β you specify them with the <key> and <value> clauses, and together those two clauses are what we call an "element" (yes, that's the official name, no cap).
the key/value pair gets added just prior to the list's current position β so it becomes the current element. it's giving "sneaking in right before the spotlight" energy β¨
but wait, there's more. if you use the append clause without the boolean variable <append>, or if <append> evaluates to true, then the element goes at the end of the list instead, and the list's current element becomes the newly added one. periodt. π₯
π EXAMPLES π
add a key/value pair to the end of the list:
new-list mylist
write-list mylist key "mykey" value "myvalue" append
the following is a list that is process-scoped, i.e. it is a linked-list server, which can add, delete, read and position to various elements:
%% /llsrv public
// Create linked list just once for the life of the process
do-once
new-list t process-scope
end-do-once
// Get input parameters
get-param op
get-param key
get-param data
if-true op equal "add" // Add data to list
// Make a copy of key,data so they are Golf-allocated
write-list t key (key) value data append
@Added [<<print-out key>>] value [<<print-out data>>]
else-if op equal "delete" // Delete first data and obtain the value deleted
position-list t first
read-list t key (key) value val status st
if-true st equal GG_ERR_EXIST
@Not found
else-if
// If found, then delete key and value
@Deleted key [<<print-out key>>], [<<print-out val>>]
delete-list t
end-if
else-if op equal "next" // Position to next element
position-list t next status st
if-true st equal GG_OKAY
@Okay
else-if
@Not found
end-if
else-if op equal "last" // Position to last element
position-list t last status st
if-true st equal GG_OKAY
@Okay
else-if
@Not found
end-if
else-if op equal "previous" // Position to element
position-list t previous status st
if-true st equal GG_OKAY
@Okay
else-if
@Not found
end-if
else-if op equal "first" // Get first element
position-list t first status st
if-true st equal GG_OKAY
@Okay
else-if
@Not found
end-if
else-if op equal "query" // Get current element
read-list t key (key) value val status st
if-true st equal GG_ERR_EXIST
@Not found
else-if
@Key [<<print-out key>>], value [<<print-out val>>]
end-if
else-if op equal "purge" // remove all, keep the list
purge-list t
end-if
%%
create application:
sudo mgrg -i -u $(whoami) linkserver
start the server:
mgrg -w 1 linkserver
try it out:
gg -r --req="/llsrv/op=add/key=1/data=1" --exec --service
gg -r --req="/llsrv/op=add/key=2/data=2" --exec --service
gg -r --req="/llsrv/op=query" --exec --service
gg -r --req="/llsrv/op=previous" --exec --service
gg -r --req="/llsrv/op=query" --exec --service
π SEE ALSO π
- Linked list
delete-listget-listnew-listposition-listpurge-listread-listwrite-list
see all documentation β
bestie the list doesn't know what's coming π go forth and append πΈ
this page is version $VERSION, dated $DATE, and lives in the GOLF(2gg) manual β mwah, thanks for reading, love u, bye π§π
π¦ 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