Re: handling state the database way
Jan Wielemaker <[email protected]>
| Newsgroups | gmane.comp.ai.prolog.swi |
|---|---|
| Message-ID | <[email protected]> |
On 02/18/2014 10:36 AM, Paulo Moura wrote: > The design idea behind the "single_fact" module centralizes (for an > application) the handling of mutable data. This can be both an > advantage (a single place to hold the mutable data) and a > disadvantage (multiple modules using this module must be careful to > use different keys). This makes "single_fact" more like a *prototype* > solution than an ideal *library* solution. As a library solution it > comes with a bias towards a single central, global store. > > Logtalk provides a bit more flexible library solution by using a > category instead. A Logtalk category is a fine-grined unit of code > reuse that can be (virtually) imported by any object. Using the > "single_fact" module suggested predicates, we can define: Logtalk's abstracting has a cleaner design than classical Prolog modules, but that doesn't mean we can't realise module local storage with Prolog modules: :- meta_predicate initialize(:, +), ... initialize(Module:Key, Value) :- asserta(Module:store(Key, Value)). ... And the central store is just initialize(central:size, 42). Cheers --- Jan