Skip to content

Commit

Permalink
Slightly modified shell-like examples in ~examples/als [animals,dc,di…
Browse files Browse the repository at this point in the history
…ff,hickory+id] to make them a little more shell-like (banners; cycling in hickory+id).
  • Loading branch information
kenbowen committed Jul 30, 2018
1 parent a8cf4bd commit 4d5de8b
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 14 deletions.
5 changes: 4 additions & 1 deletion examples/als/animals.pro
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,10 @@ question(c20,'Does it swim').
question(c21,'Is it a good flyer').

animal :-
abolish(fact/2),
nl,write('Simple shell for animal identification via questions'),nl,
write('From: How to Solve it in Prolog,'),nl,
write(' by Coelho, Cotta, Pereira, Lisbon, 1980'),nl,nl,
abolish(fact/2),
write('Please describe the animal.'),nl,nl,
recognition(_),
nl,nl,
Expand Down
13 changes: 10 additions & 3 deletions examples/als/dc.pro
Original file line number Diff line number Diff line change
Expand Up @@ -38,18 +38,24 @@ module desk_calc.
* and evaluator.
*/

dc :- write('dc: '),
dc :-
nl,write('Simple shell for a desk calculator'),nl,
write(' By Kevin Buettner'),nl,nl,
write('Type numeric expressions (no final . needed) plus return'),nl,
write('Type exit to exit from the calculator to Prolog'),nl,nl,
dc0.
dc0 :- write('dc: '),
readin(Line),
lexan(Line,Tokens),
parse(Tokens,Tree),
eval(Tree,Answer),
write(Answer), nl,
!,
dc_again(Answer).
dc :- write('??'), nl, dc.
dc0 :- write('??'), nl, dc0.

dc_again(exit) :- !, seen.
dc_again(_) :- dc.
dc_again(_) :- dc0.

source(File) :-
seeing(OldF),
Expand Down Expand Up @@ -112,6 +118,7 @@ module desk_calc.
*/

lexan([],[]) :- !.
lexan(".",[]) :- !.
lexan(InL,[Tok | Toks]) :-
classify(InL,RestL,Tok),
lexan(RestL,Toks).
Expand Down
21 changes: 18 additions & 3 deletions examples/als/diff.pro
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,17 @@
| Enter stop to exit the program.
*----------------------------------------------------------------*/


diff :-
nl,write('Simple shell for a Symbolic Differentiator'),nl,
write(' By Keith Hughes'),nl,nl,
write('Type Expressions in the form'),nl,
write(' V:Xpr.'),nl,
write('where V is a variable occurring in Xpr, e.g.,'),nl,
write(' x:(4*x + tan(x)).'),nl,
write('Type stop. to exit.'),nl,nl,
diff0.

diff0 :-
write('Expression: '),
read(T),
diff(T).
Expand All @@ -37,10 +46,10 @@ diff(X:Expr) :-
diff(X,Expr,T),!,
simplify(T,Ans),
nl,write(Ans),nl,nl,
diff.
diff0.
diff(_) :-
write('Illegal expression. Type stop to exit.'),nl,
diff.
diff0.

diff(X,X,1) :- !.
diff(_,Y,0) :-
Expand All @@ -67,6 +76,12 @@ diff(X,sin(Y),cos(Y)*DY) :- !,
diff(X,Y,DY).
diff(X,tan(Y),DY/(cos(Y)^2)) :- !,
diff(X,Y,DY).
diff(X,X^Z0,X^Z1) :- !,
integer(Z0),
Z0 > 1,
!,
Z1 is Z0-1,
diff(X,Y,DY).

% simplify an expression to a very limited extent

Expand Down
6 changes: 1 addition & 5 deletions examples/als/hickory.pro
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,7 @@
| <Character> is <Generic Character>(<Particular Aspect>).
*-------------------------------------------------------------------*/

% When a prolog file is part of an ALS Prolog project (*.ppj), don't include
% such consults; ususally, they will cause an error because the file to be
% consulted isn't in the right folder; it will be listed in the project, and
% the project search path(s) should find it:
%:- consult(id). % the diagnosis system
:- consult(id). % the diagnosis system

module identify.

Expand Down
30 changes: 28 additions & 2 deletions examples/als/id.pro
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,39 @@ export identify/0.
:- dynamic(does_not_hold/1).
:- dynamic(trait/2).

identify :-
identify :-
header,
identify0.

header :- nl,
write('Generic Identification by Properties shell'),nl,
write(' applied to Hickory Trees'),nl,
write(' by Ken Bowen'),nl,nl,
write('Enter properties characteristics of hicory trees (see hickory.pro)'),nl,
write('Type ''done.'' to finish inputting initial observations'),nl,nl,
write('Type ''exit.'' to exit the shell.'),nl,nl.

identify0 :-
obtain_description,
entertain_hypothesis(Identification), % these 2 goals are a generate
validate(Identification), % and test loop
report(Identification),
abolish(user_observed,1), % clear the database of recorded
abolish(does_not_hold,1). % observations
abolish(does_not_hold,1), % observations
loop_or_quit.

loop_or_quit
:-
nl, write('Identify another (yes. or no. ):'),
read(Ans),
loop_or_quit(Ans).

loop_or_quit(yes)
:-
identify0.
loop_or_quit(_)
:-
write('Bye.'),nl.

obtain_description :-
write('Observation: '), % requires a term which occurs
Expand Down

0 comments on commit 4d5de8b

Please sign in to comment.