Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Maps

A map in God is a data structure that has an analogue in practically every programming language; Lua tables, Python dictionaries, Perl hash slices, (Type/Java)script objects, Lisp and Scheme association lists, and Java HashMaps just to name a few.

The commonality is the structure of an identifier which is assigned a group of fields. Fields can be seen as key-value pairs in an abstract sense.

In God specifically, they are delimited by opening and closing "curly" braces ({ }). When they are used as just a field, they must be use a termination operator; when used as an element, only any fields within it will require termination.

me = {
    name = "Will";
    age = 26;
    married = false;
    favorite-songs = [
        { artist = "Slint"; title = "Nosferatu Man"; }
        { artist = "OutKast"; title = "Hey Ya!"; }
    ];
    best-friend = {
        name = "Floyd";
        age = 29;
        married = true;
        favorite-songs = [
            { artist = "Tool"; title = "Lateralus"; }
            { artist = "Deafheaven"; title = "Dream House"; }
        ];
    };
};

Any type of field is allowed within a map, so long as it follows any necessary rules of field termination.

Warning

Repeated use of the same identifier name in the same scope will result in the last occurrence determining its' value.

me = {
    name = "Will";
    age = 26;
    age = 27; # 27 will 'overwrite' the previous value
};