updated to Logtalk 2.9.1
git-svn-id: https://yap.svn.sf.net/svnroot/yap/trunk@212 b08c6af1-5177-4d33-ba66-4b1c6b8b522a
This commit is contained in:
parent
b77427df89
commit
6855745dff
21
Logtalk/examples/errors/NOTES
Normal file
21
Logtalk/examples/errors/NOTES
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
=================================================================
|
||||||
|
Logtalk - Object oriented extension to Prolog
|
||||||
|
Release 2.9.1
|
||||||
|
|
||||||
|
Copyright (c) 1998-2001 Paulo Moura. All Rights Reserved.
|
||||||
|
=================================================================
|
||||||
|
|
||||||
|
To load all entities in this example consult the warnings.loader and
|
||||||
|
the errors.loader utility files (note that these are Prolog files).
|
||||||
|
|
||||||
|
This folder contains examples of objects, categories, and protocols
|
||||||
|
containing errors that will trigger Logtalk compiler warnings and
|
||||||
|
errors. The goal of this example is to help the user to get acquainted
|
||||||
|
to the Logtalk compiler warning and error reporting. Open the object
|
||||||
|
source files in a text editor to better understand how the compiler
|
||||||
|
deals with common programming errors.
|
||||||
|
|
||||||
|
Note that the warnings and errors that yoy will get while compiling
|
||||||
|
your files depend on your compiler options (setted explicitly as
|
||||||
|
parameters in the logtalk_compile/2 or logtalk_load/2 built-in
|
||||||
|
predicates or by default in your configuration file).
|
38
Logtalk/examples/errors/errors.loader
Normal file
38
Logtalk/examples/errors/errors.loader
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
|
||||||
|
:- initialization((
|
||||||
|
catch(
|
||||||
|
logtalk_load(
|
||||||
|
[lgtmthdredef],
|
||||||
|
[unknown(warning), misspelt(warning), singletons(warning), plredef(warning), lgtredef(warning), report(on)]),
|
||||||
|
_,
|
||||||
|
true),
|
||||||
|
catch(
|
||||||
|
logtalk_load(
|
||||||
|
[invclause],
|
||||||
|
[unknown(warning), misspelt(warning), singletons(warning), plredef(warning), lgtredef(warning), report(on)]),
|
||||||
|
_,
|
||||||
|
true),
|
||||||
|
catch(
|
||||||
|
logtalk_load(
|
||||||
|
[unknowndir],
|
||||||
|
[unknown(warning), misspelt(warning), singletons(warning), plredef(warning), lgtredef(warning), report(on)]),
|
||||||
|
_,
|
||||||
|
true),
|
||||||
|
catch(
|
||||||
|
logtalk_load(
|
||||||
|
[noninstdir],
|
||||||
|
[unknown(warning), misspelt(warning), singletons(warning), plredef(warning), lgtredef(warning), report(on)]),
|
||||||
|
_,
|
||||||
|
true),
|
||||||
|
catch(
|
||||||
|
logtalk_load(
|
||||||
|
[invargdir],
|
||||||
|
[unknown(warning), misspelt(warning), singletons(warning), plredef(warning), lgtredef(warning), report(on)]),
|
||||||
|
_,
|
||||||
|
true),
|
||||||
|
catch(
|
||||||
|
logtalk_load(
|
||||||
|
[unmatchdir],
|
||||||
|
[unknown(warning), misspelt(warning), singletons(warning), plredef(warning), lgtredef(warning), report(on)]),
|
||||||
|
_,
|
||||||
|
true))).
|
8
Logtalk/examples/errors/invargdir.lgt
Normal file
8
Logtalk/examples/errors/invargdir.lgt
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
|
||||||
|
:- object(invargdir).
|
||||||
|
|
||||||
|
|
||||||
|
:- public(1234).
|
||||||
|
|
||||||
|
|
||||||
|
:- end_object.
|
9
Logtalk/examples/errors/invclause.lgt
Normal file
9
Logtalk/examples/errors/invclause.lgt
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
|
||||||
|
:- object(invclause).
|
||||||
|
|
||||||
|
|
||||||
|
1234 :-
|
||||||
|
write(hello).
|
||||||
|
|
||||||
|
|
||||||
|
:- end_object.
|
8
Logtalk/examples/errors/lgtmthdredef.lgt
Normal file
8
Logtalk/examples/errors/lgtmthdredef.lgt
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
|
||||||
|
:- object(lgtmthdredef).
|
||||||
|
|
||||||
|
|
||||||
|
asserta(_).
|
||||||
|
|
||||||
|
|
||||||
|
:- end_object.
|
6
Logtalk/examples/errors/lgtredef.lgt
Normal file
6
Logtalk/examples/errors/lgtredef.lgt
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
|
||||||
|
:- object(lgtredef).
|
||||||
|
|
||||||
|
current_object(_).
|
||||||
|
|
||||||
|
:- end_object.
|
8
Logtalk/examples/errors/misspell.lgt
Normal file
8
Logtalk/examples/errors/misspell.lgt
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
|
||||||
|
:- object(misspell).
|
||||||
|
|
||||||
|
output(A) :-
|
||||||
|
writr(A).
|
||||||
|
|
||||||
|
:- end_object.
|
||||||
|
|
8
Logtalk/examples/errors/noninstdir.lgt
Normal file
8
Logtalk/examples/errors/noninstdir.lgt
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
|
||||||
|
:- object(noninstdir).
|
||||||
|
|
||||||
|
|
||||||
|
:- Public(predicate/0).
|
||||||
|
|
||||||
|
|
||||||
|
:- end_object.
|
7
Logtalk/examples/errors/plredef.lgt
Normal file
7
Logtalk/examples/errors/plredef.lgt
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
|
||||||
|
:- object(plredef).
|
||||||
|
|
||||||
|
write(_).
|
||||||
|
|
||||||
|
:- end_object.
|
||||||
|
|
8
Logtalk/examples/errors/singletons1.lgt
Normal file
8
Logtalk/examples/errors/singletons1.lgt
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
|
||||||
|
:- object(singletons(L)).
|
||||||
|
|
||||||
|
predicate(A) :-
|
||||||
|
write(C).
|
||||||
|
|
||||||
|
:- end_object.
|
||||||
|
|
8
Logtalk/examples/errors/unknowndir.lgt
Normal file
8
Logtalk/examples/errors/unknowndir.lgt
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
|
||||||
|
:- object(unknowndir).
|
||||||
|
|
||||||
|
|
||||||
|
:- index(predicate/3, [1, 2]).
|
||||||
|
|
||||||
|
|
||||||
|
:- end_object.
|
9
Logtalk/examples/errors/unknownrefs.lgt
Normal file
9
Logtalk/examples/errors/unknownrefs.lgt
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
|
||||||
|
:- object(unknownrefs,
|
||||||
|
implements(protocol),
|
||||||
|
imports(category),
|
||||||
|
extends(object)).
|
||||||
|
|
||||||
|
|
||||||
|
:- end_object.
|
||||||
|
|
5
Logtalk/examples/errors/unmatchdir.lgt
Normal file
5
Logtalk/examples/errors/unmatchdir.lgt
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
|
||||||
|
:- objecto(unmatchdir).
|
||||||
|
|
||||||
|
|
||||||
|
:- end_object.
|
5
Logtalk/examples/errors/warnings.loader
Normal file
5
Logtalk/examples/errors/warnings.loader
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
|
||||||
|
:- initialization(
|
||||||
|
logtalk_load(
|
||||||
|
[misspell, singletons1, plredef, lgtredef, unknownrefs],
|
||||||
|
[unknown(warning), misspelt(warning), singletons(warning), plredef(warning), lgtredef(warning), report(on)])).
|
6
Logtalk/examples/inheritance/descendant1.lgt
Normal file
6
Logtalk/examples/inheritance/descendant1.lgt
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
|
||||||
|
:- object(descendant1,
|
||||||
|
imports(interface),
|
||||||
|
extends(prototype1)).
|
||||||
|
|
||||||
|
:- end_object.
|
6
Logtalk/examples/inheritance/descendant2.lgt
Normal file
6
Logtalk/examples/inheritance/descendant2.lgt
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
|
||||||
|
:- object(descendant2,
|
||||||
|
imports(interface),
|
||||||
|
extends(prototype2)).
|
||||||
|
|
||||||
|
:- end_object.
|
6
Logtalk/examples/inheritance/descendant3.lgt
Normal file
6
Logtalk/examples/inheritance/descendant3.lgt
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
|
||||||
|
:- object(descendant3,
|
||||||
|
imports(interface),
|
||||||
|
extends(prototype3)).
|
||||||
|
|
||||||
|
:- end_object.
|
72
Logtalk/examples/searching/bridge.lgt
Normal file
72
Logtalk/examples/searching/bridge.lgt
Normal file
@ -0,0 +1,72 @@
|
|||||||
|
|
||||||
|
:- object(bridge,
|
||||||
|
instantiates(heuristic_state_space)).
|
||||||
|
|
||||||
|
|
||||||
|
:- uses(list).
|
||||||
|
:- uses(numberlist).
|
||||||
|
:- uses(set).
|
||||||
|
|
||||||
|
|
||||||
|
initial_state(start, ([], right, [1,3,6,8,12])).
|
||||||
|
|
||||||
|
|
||||||
|
goal_state(end, ([1,3,6,8,12], left, [])).
|
||||||
|
|
||||||
|
|
||||||
|
next_state((Left1, left, Right1), (Left2, right, Right2), Slower) :- % two persons
|
||||||
|
list::append(List, [Person1| Persons], Left1),
|
||||||
|
set::select(Person2, Persons, Others),
|
||||||
|
list::append(List, Others, Left2),
|
||||||
|
set::insert_all([Person1, Person2], Right1, Right2),
|
||||||
|
(Person1 > Person2 ->
|
||||||
|
Slower = Person1
|
||||||
|
;
|
||||||
|
Slower = Person2).
|
||||||
|
|
||||||
|
next_state((Left1, right, Right1), (Left2, left, Right2), Slower) :- % two persons
|
||||||
|
list::append(List, [Person1| Persons], Right1),
|
||||||
|
set::select(Person2, Persons, Others),
|
||||||
|
list::append(List, Others, Right2),
|
||||||
|
set::insert_all([Person1, Person2], Left1, Left2),
|
||||||
|
(Person1 > Person2 ->
|
||||||
|
Slower = Person1
|
||||||
|
;
|
||||||
|
Slower = Person2).
|
||||||
|
|
||||||
|
next_state((Left1, left, Right1), (Left2, right, Right2), Person) :- % one person
|
||||||
|
set::select(Person, Left1, Left2),
|
||||||
|
set::insert(Right1, Person, Right2).
|
||||||
|
|
||||||
|
next_state((Left1, right, Right1), (Left2, left, Right2), Person) :- % one person
|
||||||
|
set::select(Person, Right1, Right2),
|
||||||
|
set::insert(Left1, Person, Left2).
|
||||||
|
|
||||||
|
|
||||||
|
heuristic((Left, Lamp, Right), Heuristic) :-
|
||||||
|
Lamp = left ->
|
||||||
|
list::min(Left, Heuristic)
|
||||||
|
;
|
||||||
|
list::max(Right, Max),
|
||||||
|
list::min(Right, Min),
|
||||||
|
Heuristic is Max + Min.
|
||||||
|
|
||||||
|
|
||||||
|
print_state((Left, Lamp, Right)) :-
|
||||||
|
write_list(Left),
|
||||||
|
(Lamp = left ->
|
||||||
|
write(' lamp _|____________|_ ')
|
||||||
|
;
|
||||||
|
write(' _|____________|_ lamp ')),
|
||||||
|
write_list(Right),
|
||||||
|
nl.
|
||||||
|
|
||||||
|
|
||||||
|
write_list([]).
|
||||||
|
|
||||||
|
write_list([Head| Tail]) :-
|
||||||
|
write(Head), write(' '),
|
||||||
|
write_list(Tail).
|
||||||
|
|
||||||
|
|
||||||
|
:- end_object.
|
Reference in New Issue
Block a user