如何使用持久性库在 swi-prolog 中持久化自定义或非平凡数据类型?

问题描述

我想使用持久性库 (https://www.swi-prolog.org/pldoc/man?section=persistency) 持久化我的 prolog 数据库

我有一个类似这样的模块文件

:- module(model,[ campament/5
          ]).

:- use_module(library(persistency)).

:- persistent
   campament(name:atom,date_from:date,date_to:date,ubication:text,description:text).

此定义与 date 数据类型 (https://www.swi-prolog.org/pldoc/man?section=timedate) 有关,该数据类型不存在于 persistent/1 (https://www.swi-prolog.org/pldoc/man?section=error ).

因此,当我尝试保留此子句时,出现错误

?- use_module(model).

?- model:bd('data.db').

?- parse_time('20180720',iso_8601,From),|  parse_time('20180729',To),|  model:assert_campament('My campament',From,To,'there','nothing').

ERROR: type `date' does not exist
ERROR: In:
ERROR:   [15] throw(error(existence_error(type,date),_37572))
ERROR:   [11] model:assert_campament('My campament','nothing') at /home/xxx/model.pl:9
ERROR:    [9] <user>
ERROR: 
ERROR: Note: some frames are missing due to last-call optimization.
ERROR: Re-run your program in debug mode (:- debug.) to get more detail.

如何持久化 date 之类的类型?在 must_be/2 (https://www.swi-prolog.org/pldoc/doc_for?object=persistent/1) 中,可能的类型之一是:

...

any 任何术语

type 项是有效的类型规范

...

问候。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)