read file and construct facts in prolog

后端 未结 3 748
北荒
北荒 2021-01-23 00:34

I would like to construct a mechanism that constructs different facts depending from txt file, imported in prolog. I already have found some examples where they directly assert

3条回答
  •  傲寒
    傲寒 (楼主)
    2021-01-23 01:17

    You can do any 'normal' prolog in a DCG by enclosing it in {}

    some_nonterminal --> "fridge", blanks, [X], { % you can put any normal Prolog code in here assert(fridge_named(X)) }.

    This looks for a sequence like

    fridge G

    and asserts fridge_named(0x47) in the database (Ascii G is 0x47)

提交回复
热议问题