Introducing the AtomTable

This is a moderated forum that collects tutorials, guides, and references for creating Transcendence extensions and scripts.
Post Reply
User avatar
alterecco
Fleet Officer
Fleet Officer
Posts: 1658
Joined: Wed Jan 14, 2009 3:08 am
Location: Previously enslaved by the Iocrym

Mon Feb 09, 2009 10:32 am

Thanks to GambitDash and (sysGlobals) we now have a new datastructure to play with. I am not sure of its usefullness over the list, but since it's there I thought I'd mention it here.

We are talking about the [atom table]

There are 5 functions that show up in (sysGlobals) of which we have no description, and of which I, at least, have seen no use. They are the following

Code: Select all

(atmAddEntry ...)
(atmAtomTable ...)
(atmDeleteEntry ...)
(atmList ...)
(atmLookup ...)
Now, there is no specification of the argument list, and since it's a bit complex, it's hard to decipher it just by testing. So, GambitDash to the rescue, and 5 minutes later, he provided the syntax.

To create a atomTable use (atmAtomTable). It's syntax is the following:

Code: Select all

(atmAtomTable ((atom1 entry1) (atom2 entry2) ... (atomn entryn))) -> atmtable
So, a list containing lists of atoms and their entries.
Now, an atom is everything except a list, so we should think we could use any non-list value as the atom, and we can. But in practice, the only value that is stored as an atom is an int or a string representation of an int.

Code: Select all

(setq a (atmAtomTable 
	(list '(string hello) (list "5" " Print") (list 3 "World") '(8 "me"))
))
[atom table]
Now to see what this produces use:

Code: Select all

(atmList a)
(0 3 5 8)
We can see that it returns an ordered list of integers, most of them being set from the atom entry above (3 5 8) the (0) comes from "string", which can't be converted to an integer, so ends up being 0.

Too actually get at the data use:

Code: Select all

(atmLookup a 5)
Print
We can look up elements by integer, nice! (not much different from (item list int) though)

To add data use:

Code: Select all

(atmAddEntry a 2 "Scripting")
Scripting
(atmList a)
(0 2 3 5 8)
At the moment of this writing it appears that (atmDeleteEntry) does not work, but its use is obvious otherwise

Code: Select all

(atmDeleteEntry a 0)
All in all this is a structure very similar to an ordered array.

For the curious, yes, i did ask GambitDash about the (symCreate) series, but they are not working, in version 0.99c at least.
For the record, the argument structure is very similar, but let me reference it here.

Code: Select all

(symCreate) -> symTable
(symAddEntry symTable symbol entry) -> entry
(symDeleteEntry symTable symbol) -> True
(symLookup symTable symbol) -> entry
Have fun...

Post Reply