GOLF(2gg)

๐Ÿ“ฆ version 601.4.41, in ubuntu questing

๐Ÿ’… GOLF(2gg) โ€” the new-array page, but make it cute โœจ

okay bestie, welcome to GOLF(2gg), the Development corner of the manual, and today's main character is new-array. no cap, this is the glow-up your terminal needed. ๐ŸŽ€


โœจ NAME โœจ

new-array โ€” (array) ๐Ÿฆ‹


๐ŸŽฏ PURPOSE ๐ŸŽฏ

make a brand new array, bestie. that's it, that's the whole job. ๐Ÿ’–


๐Ÿ“œ SYNTAX ๐Ÿ“œ

new-array <array> [ max-size <max-size> ] [ process-scope ]  [ type string | number | bool ]

look at her. iconic. ๐Ÿ‘‘


๐ŸŒธ DESCRIPTION ๐ŸŒธ

new-array creates a new <array>. and like, what is an array here? it's an indexed array โ€” the index is a number, and each element is either a string, a number or a boolean. simple as that. ๐Ÿ“

so by default, like when you don't say anything about type, your <array> is an array of strings. but if you do use the type clause, you can say string, number or bool, and then <array> is an array of strings, numbers or booleans respectively. slay, choose your fighter. โœจ

an array is flexible, meaning it just grows whenever it needs to. by default, an array allocates room for 256 elements, and it can grow up to 1,000,000 elements โ€” unless you hand it a <max-size> number in the max-size clause, in which case it can grow up to <max-size> elements. heads up though: <max-size> must be at least 256. no negotiating on that one. ๐Ÿ’€

note that max-size only specifies the upper limit of allocation. the actual amount of memory allocated can vary. don't come for her about the details.

you do not need to pre-size the array, bestie. instead, when you write an element, it resizes automatically. for instance, you can set an array element arr[0] and then arr[1000] (with literally nothing in-between) and the array will automatically extend to accommodate. it's giving "i got you". ๐Ÿซถ

but โ€” and this is important โ€” it will not automatically contract when trailing elements are deleted. it's not gonna shrink just because you left. ๐Ÿ˜ญ use purge-array to delete all the elements in the array and shrink its memory footprint when your processing is done. periodt.


๐Ÿ”ฎ SCOPE ๐Ÿ”ฎ

an array is accessible to the current request only โ€” unless the process-scope clause is used, in which case all requests served by a process can use it (see do-once for a typical way to do this). ๐Ÿ‘€

if process-scope is used, then <array> will keep its data across all requests in a given process. see write-array for an example of a process-scoped array. ๐Ÿงš


๐ŸŒˆ EXAMPLES ๐ŸŒˆ

create a new array:

new-array arr

boom. array created. main character energy achieved. ๐Ÿ”ฅ


๐Ÿ‘‘ SEE ALSO ๐Ÿ‘‘

  • Array
  • new-array
  • purge-array
  • read-array
  • write-array
  • See all documentation โญ

okay that's the whole page bestie, you ate ๐Ÿ’…

that was GOLF(2gg) โ€” source/version $VERSION, dated $DATE. go forth and make arrays. ๐Ÿ’–๐Ÿฆ‹โœจ

๐Ÿ“ฆ where this page comes from