A shelf is an object with multiple slots whose contents survive backtracking. The content of each slot can be set and retrieved individually, or the whole shelf can be retrieved as a term.
Shelves can be referred to either by handle or by name. Whenever possible, handles should be used, because this naturally leads to robust, reentrant code, and avoids the danger of memory leaks. See shelf_create/2,3 for how to create shelves with a handle.
Named shelves are identified by a functor. This is usually simply an atom, but in general it can be name/arity pair.
When named shelves are used, the visibility of the shelf name is local to the module where it was created. A named shelf never disappears, therefore, in order to free the associated memory, its contents should be erased when no longer needed.
Duplicate shelf declarations are silently ignored.
% A store with the simple, atomic name 'counters' :- local shelf(counters, count(0,0,0)). main :- shelf_get(counters,1,N0), N1 is N0+1, shelf_set(counters,1,N1), printf("main has been called %d times%n", [N1]).