home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Power-Programmierung
/
CD1.mdf
/
magazine
/
nvdc87
/
extrac
/
mymenu.pro
< prev
next >
Wrap
Text File
|
1987-07-28
|
4KB
|
132 lines
/************************************************************
Listing 1.
Turbo Prolog Toolbox Article
This program demonstrates the use of extracted
predicates from files furnished on the Turbo Prolog
Toolbox distribution disks. It creates two new
INCLUDE files from those on the distribution disks:
MENPREDS.PRO from TPREDS.PRO and NEWMENU.PRO from
MENU.PRO. In both cases, unneeded predicates have
been removed from the original files and the modified
files saved separately.
************************************************************/
include "tdoms.pro" /* no modifications - nothing to delete */
include "menpreds.pro" /* as modified for this program */
include "newmenu.pro" /* as modified for this program */
predicates
member(integer,integerlist)
fun(integerlist)
power_user(integerlist)
developer(integerlist)
fun_only(integerlist)
all_work(integerlist)
crazy(integerlist)
write_it(integerlist)
goal
clearwindow,
menu_mult(10,10,7,7,["Arcade-style games","Databases",
"Expert Systems Development","Math Research",
"Programming","Spreadsheets","Telecommunications",
"Text Adventure Games","Word Processing"],
"Select all of the things for which you use a
computer",
[],Choices),
write_it(Choices).
clauses
/* These predicates permit us to categorize responses from the
menu in such a way as to make the computer's analysis and advice
more interesting and less expected. To see what they are intended
to mean, look at the "write_it" clauses below. All work basically
the same way. The menu choices are categorized into "fun", "power
user", "developer" and "crazy." Since the user is making a
multiple-choice selection, his/her replies are stored in a list
called Choices (as set up in the "menu_mult" predicate call in
the goal, above). Then we just use the "member" predicate to
determine if a particular value is part of that list or not. */
fun(Choices) :-
member(1,Choices).
fun(Choices) :-
member(8,Choices).
power_user(Choices) :-
member(2,Choices).
power_user(Choices) :-
member(6,Choices).
power_user(Choices) :-
member(7,Choices).
power_user(Choices) :-
member(9,Choices).
developer(Choices) :-
member(3,Choices).
developer(Choices) :-
member(5,Choices).
crazy(Choices) :-
member(4,Choices). /* Isn't any math researcher? */
/* If the user indicates only game choices, s/he's categorized as
"fun_only" for our purposes. */
fun_only(Choices) :-
fun(Choices),
not(power_user(Choices)),
not(developer(Choices)).
/* Similarly, if the user indicates no fun choices at all, but only
power user or programmer uses, s/he's categorized as
"all_work". */
all_work(Choices) :-
not(fun(Choices)),
power_user(Choices).
all_work(Choices) :-
not(fun(Choices)),
developer(Choices).
all_work(Choices) :-
not(fun(Choices)),
not(crazy(Choices)).
/* Here come the messages of advice -- words of wisdom, if you will --
for each category of respondent. */
write_it(Choices) :-
fun_only(Choices),
write("Maybe it's time you got serious about your
computer!").
write_it(Choices) :-
all_work(Choices),
write("All work and no play makes for rich, but dull,
programmers!").
write_it(Choices) :-
crazy(Choices),
write("You are definitely a strange duck!").
write_it(Choices) :-
not(fun_only(Choices)),
not(all_work(Choices)),
not(crazy(Choices)),
write("You seem to be pretty well-balanced.").
/* Standard "member" definition, but not included with Turbo
Prolog. */
member(X,[X|_]).
member(X,[_|Y]) :-
member(X,Y).