Changeset 4482
- Timestamp:
- 10/04/08 12:30:36 (3 months ago)
- Location:
- trunk
- Files:
-
- 4 modified
-
examples/roots/NOTES.txt (modified) (1 diff)
-
library/numberlist.lgt (modified) (3 diffs)
-
library/numberlistp.lgt (modified) (3 diffs)
-
RELEASE_NOTES.txt (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/examples/roots/NOTES.txt
r4466 r4482 47 47 48 48 Please note that the entities above are just example definitions. There is 49 nothing fundamental about either of them; they can and should be replaced50 bydefinitions better fitted to the requirements of specific applications.49 nothing fundamental about any of them; they can and should be replaced by 50 definitions better fitted to the requirements of specific applications. -
trunk/library/numberlist.lgt
r4216 r4482 5 5 6 6 :- info([ 7 version is 1. 2,7 version is 1.3, 8 8 author is 'Paulo Moura', 9 date is 2008/ 4/22,9 date is 2008/9/15, 10 10 comment is 'List of numbers predicates.']). 11 11 … … 21 21 average(Ns, Lacc2, Sacc2, Average). 22 22 23 min([ N| Ns], Min) :-24 min( Ns, N, Min).23 min([X| Xs], Min) :- 24 min(Xs, X, Min). 25 25 26 26 min([], Min, Min). 27 min([ N| Ns], Aux, Min) :-28 ( N< Aux ->29 min( Ns, N, Min)30 ; min( Ns, Aux, Min)27 min([X| Xs], Aux, Min) :- 28 ( X < Aux -> 29 min(Xs, X, Min) 30 ; min(Xs, Aux, Min) 31 31 ). 32 32 33 max([ N| Ns], Max) :-34 max( Ns, N, Max).33 max([X| Xs], Max) :- 34 max(Xs, X, Max). 35 35 36 36 max([], Max, Max). 37 max([ N| Ns], Aux, Max) :-38 ( N> Aux ->39 max( Ns, N, Max)40 ; max( Ns, Aux, Max)37 max([X| Xs], Aux, Max) :- 38 ( X > Aux -> 39 max(Xs, X, Max) 40 ; max(Xs, Aux, Max) 41 41 ). 42 42 43 product( List, Product) :-44 product( List, 1, Product).43 product([X| Xs], Product) :- 44 product(Xs, X, Product). 45 45 46 46 product([], Product, Product). 47 product([ N| Ns], Acc, Product) :-48 Acc2 is Acc * N,49 product( Ns, Acc2, Product).47 product([X| Xs], Acc, Product) :- 48 Acc2 is Acc * X, 49 product(Xs, Acc2, Product). 50 50 51 51 sum(List, Sum) :- … … 53 53 54 54 sum([], Sum, Sum). 55 sum([ N| Ns], Acc, Sum) :-56 Acc2 is Acc + N,57 sum( Ns, Acc2, Sum).55 sum([X| Xs], Acc, Sum) :- 56 Acc2 is Acc + X, 57 sum(Xs, Acc2, Sum). 58 58 59 59 valid(-) :- % catch variables and lists with unbound tails -
trunk/library/numberlistp.lgt
r3567 r4482 3 3 4 4 :- info([ 5 version is 1. 1,5 version is 1.2, 6 6 author is 'Paulo Moura', 7 date is 200 7/4/20,7 date is 2008/9/15, 8 8 comment is 'List of numbers protocol.']). 9 9 … … 11 11 :- mode(product(+list(number), ?number), zero_or_one). 12 12 :- info(product/2, 13 [comment is 'Calculates the product of all list values.',13 [comment is 'Calculates the product of all list numbers. Fails if the list is empty.', 14 14 argnames is ['List', 'Product']]). 15 15 16 16 :- public(sum/2). 17 :- mode(sum(+list(number), ?number), zero_or_one).17 :- mode(sum(+list(number), ?number), one). 18 18 :- info(sum/2, 19 [comment is 'Calculates the sum of all list values.',19 [comment is 'Calculates the sum of all list numbers. Returns zero if the list is empty.', 20 20 argnames is ['List', 'Sum']]). 21 21 … … 23 23 :- mode(average(+list(number), ?float), zero_or_one). 24 24 :- info(average/2, 25 [comment is 'Calculates the average of a list of values.',25 [comment is 'Calculates the average (i.e. arithmetic mean) of a list of numbers. Fails if the list is empty.', 26 26 argnames is ['List', 'Average']]). 27 27 -
trunk/RELEASE_NOTES.txt
r4480 r4482 42 42 creation of the K-Prolog integration shortcut could fail when performing 43 43 a custom installation. Fixed a bug in detecting a CxProlog installation. 44 45 Modified the implementation of the predicate product/2 in the library 46 object "numberlist" to fail for empty lists. 44 47 45 48 Improved "metainterpreters" example.
