Functor Domain Versioning

From wiki.visual-prolog.com

Revision as of 16:22, 27 September 2016 by Thomas Linder Puls (talk | contribs) (initial)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

 


It is problematic to update functor domains, if terms have been persisted in serialized form. Because new programs cannot deal with old serializations.

The attributes default/1 and retiredFunctor/1 can help dealing with this problem.

Default values

The last arguments of a functor can have default values:

domains
    ppp =
        fct(
            integer A,
            real B,
            ddd C,
            integer* New [default([])],
            real New2 [default(0)]
        ).

The default attribute does not change anything within the program; it only affects the deserialization. If during deserialization we meet the closing parenthesis too soon we supply default values for the remaining arguments.

Notice that this will only work for text deserialization.

Retired functors

Functor alternatives can be retired.

domains
    ppp =
        fct(integer A, real B, ddd C) [retiredFunctor(aaa::fct_ppp)];
        fct2(integer A, ddd C, integer* New).

aaa::fct_ppp must be a predicate with this type (it can be an anonymous predicate):

predicates
    fct_ppp : (integer A, real B, ddd C) -> ppp NewValue.

I.e. it takes the arguments of the old functor and returns a value in the functor domain.

In the program fct is does not exist at all, it is retired. However, in the deserialization fct terms can still be handled: The arguments are parsed according to the types, and then the value is created by invoking aaa::fct_ppp.

This method will also work for binary serializations, provided:

  • The old domain had more than one alternative (so there are functor numbers in the serialization)
  • New alternatives are added last (to retain functor numbers)

(It is however not recommend using binary serialization for inter-session persistence).