table.uniqueName

Syntax table.uniqueName (prefix, tableAddr, places=nil)

Params prefix is a string that's used in constructing the unique name.

tableAddr is the address of a table that's about to get a new element.

places is an optional parameter specifying the number of digits in the number used to ensure uniqueness.

Action Creates a name, based on prefix, that is not already in use in the table.

Returns An address of an item in the table that doesn't exist, and is thus safe to assign to.

Examples table.uniqueName ("item", @scratchpad)

   » @scratchpad.item1

table.uniqueName ("item", @scratchpad)^ = 12

   » 12

table.uniqueName ("item", @scratchpad)

   » @scratchpad.item2

table.uniqueName ("item", @scratchpad, 3)

   » @scratchpad.item001

Notes Use this verb when you're adding an item to a table that contains several objects of the same type.

An example: you could use this verb to safely add an item to a table of file paths or Email accounts.

Discuss