1
votes

I try to implement simple expert system in SWI Prolog. This system reads input data from keyboard and finds the language. Here is my code:

/* Paradigms */
paradigm('Ada', 'Imperative').
paradigm('C', 'Imperative').

/* Typization */
typization('Ada', 'Statical').
typization('C', 'Explicit').

/* Compiler */
compiler('Ada', 'OpenSource').
compiler('C', 'DebugPosibility').

/* Memory */
memory('Ada', 'Stack').
memory('C', 'Pointer').

language(L, P, T, C, M) :- paradigm(L, P), typization(L, T), compiler(L, C), memory(L, M).

run :- write('\nChoose language paradigm:\n1. imperative\n2. object-oriented\n3. distributed\n4. reflexive\n5. declarative\n6. functional\n7. general programming\n'), read(P),
       write('\n\nChoose typization:\n1. statical\n2. explicit\n3. polymorfism\n4. runtime type information\n5. dynamical\n6. implicit\n7. cast without data lose\n8. implicit cast without data lose\n9. argument output at method call\n'), read(T),
       write('\n\nChoose compiler type:\n1. open-source\n2. debug posibility\n3. bootstrapping\n4. multithreading compilation\n5. conditional compilation\n6. command line interpreter\n'), read(C),
       write('\n\nChoose memory management type:\n1. stack\n2. pointer\n3. manual memory management\n4. garbage collector\n'), read(M),

       language(L, P, T, C, M),
       write(L).

When I run this program I receive all languages all the time. But in my test case it is supposed to get only one language. Language is acceptable when all four predicates from language return true for the same language L. Where is my mistake and how can I fix it?

Thank you very much!

1

1 Answers

1
votes

The error is somewhere in the capture of the input (in particular, the user is asked to enter a string that is no correspondence with what the program actually expects; take care here). If you use atoms and drop the single quoting, the program with two test cases reads:

paradigm(ada, imperative).
paradigm(c, imperative).

typization(ada, statical).
typization(c, explicit).

compiler(ada, openSource).
compiler(c, debugPosibility).

memory(ada, stack).
memory(c, pointer).

language(L, P, T, C, M) :- paradigm(L, P), typization(L, T), compiler(L, C), memory(L, M).

test1(L) :- language(L, imperative, statical, openSource, stack).
test2(L,P) :- language(L, P, statical, openSource, stack).

Running test1(L) yields L=ada only and running test2(L,P) yields L=ada, P=imperative only, as wanted.