⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 family1.pro

📁 一个最新的PROLOG程序
💻 PRO
字号:
/*****************************************************************************

                        Copyright (c) Sabu Francis Associates

******************************************************************************/

implement family1
    open core

    constants
        className = "family1".
        classVersion = "$JustDate: $$Revision: $".

    clauses
        classInfo(className, classVersion).

    domains
        gender = female(); male().

    class facts - familyDB
        person : (string Name, gender Gender).
        parent : (string Person, string Parent).

    class predicates
        father : (string Person, string Father) nondeterm anyflow.
    clauses
        father(Person, Father) :-
            parent(Person, Father),
            person(Father, male()).

    class predicates
        grandFather : (string Person, string GrandFather) nondeterm (o,o).
    clauses
        grandFather(Person, GrandFather) :-
            parent(Person, Parent),
            father(Parent, GrandFather).

    class predicates
        ancestor : (string Person, string Ancestor) nondeterm (i,o).
    clauses
        ancestor(Person, Ancestor) :-
            parent(Person, Ancestor).
        ancestor(Person, Ancestor) :-
            parent(Person, P1),
            ancestor(P1, Ancestor).

    class predicates
        reconsult : (string FileName).
    clauses
        reconsult(FileName) :-
            retractFactDB(familyDB),
            file::consult(FileName, familyDB).

    clauses
        run():-
            console::init(),
            stdIO::write("Load data\n"),
            reconsult("..\\fa.txt"),
            stdIO::write("\nfather test\n"),
            father(X, Y),
                stdIO::writef("% is the father of %\n", Y, X),
            fail.
        run():-
            stdIO::write("\ngrandFather test\n"),
            grandFather(X, Y),
                stdIO::writef("% is the grandfather of %\n", Y, X),
            fail.
        run():-
            stdIO::write("\nancestor of Pam test\n"),
            X = "Pam",
            ancestor(X, Y),
                stdIO::writef("% is the ancestor of %\n", Y, X),
            fail.
        run():-
            stdIO::write("End of test\n").
end implement family1

goal
    mainExe::run(family1::run).

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -