Changeset 4090 for trunk/library
- Timestamp:
- 02/15/08 07:27:42 (11 months ago)
- Location:
- trunk/library
- Files:
-
- 2 modified
Legend:
- Unmodified
- Added
- Removed
-
trunk/library/loop.lgt
r4089 r4090 22 22 whiledo(Condition, Action). 23 23 24 :- meta_predicate(foreach(*, *, ::)). 25 foreach(Count, List, Goal) :- 26 foreach_inv(List, Count, Goal). 27 28 foreach_inv([], _, _). 29 foreach_inv([Element| List], Count, Goal) :- 30 \+ \+ (Count = Element, call(Goal)), 31 foreach_inv(List, Count, Goal). 32 24 33 :- meta_predicate(forto(*, *, ::)). 25 forto(FirstExp, LastExp, Call) :-34 forto(FirstExp, LastExp, Goal) :- 26 35 First is FirstExp, 27 36 Last is LastExp, 28 37 ( First =< Last -> 29 \+ \+ call( Call),38 \+ \+ call(Goal), 30 39 Next is First + 1, 31 forto(Next, Last, Call)40 forto(Next, Last, Goal) 32 41 ; true 33 42 ). 34 43 35 44 :- meta_predicate(forto(*, *, *, ::)). 36 forto(Count, FirstExp, LastExp, Call) :-45 forto(Count, FirstExp, LastExp, Goal) :- 37 46 First is FirstExp, 38 47 Last is LastExp, 39 48 ( First =< Last -> 40 \+ \+ (Count = First, call( Call)),49 \+ \+ (Count = First, call(Goal)), 41 50 Next is First + 1, 42 forto(Count, Next, Last, Call)51 forto(Count, Next, Last, Goal) 43 52 ; true 44 53 ). 45 54 46 55 :- meta_predicate(fordownto(*, *, ::)). 47 fordownto(FirstExp, LastExp, Call) :-56 fordownto(FirstExp, LastExp, Goal) :- 48 57 First is FirstExp, 49 58 Last is LastExp, 50 59 ( First >= Last -> 51 \+ \+ call( Call),60 \+ \+ call(Goal), 52 61 Next is First - 1, 53 fordownto(Next, Last, Call)62 fordownto(Next, Last, Goal) 54 63 ; true 55 64 ). 56 65 57 66 :- meta_predicate(fordownto(*, *, *, ::)). 58 fordownto(Count, FirstExp, LastExp, Call) :-67 fordownto(Count, FirstExp, LastExp, Goal) :- 59 68 First is FirstExp, 60 69 Last is LastExp, 61 70 ( First >= Last -> 62 \+ \+ (Count = First, call( Call)),71 \+ \+ (Count = First, call(Goal)), 63 72 Next is First - 1, 64 fordownto(Count, Next, Last, Call)73 fordownto(Count, Next, Last, Goal) 65 74 ; true 66 75 ). -
trunk/library/loopp.lgt
r4089 r4090 15 15 argnames is ['Action', 'Condition']]). 16 16 17 :- public(foreach/3). 18 :- meta_predicate(foreach(*, *, ::)). 19 :- mode(foreach(-term, +list(term), @callable), zero_or_one). 20 :- info(foreach/3, [ 21 comment is 'For each element Count in List call Goal.', 22 argnames is ['Count', 'List', 'Goal']]). 23 17 24 :- public(forto/3). 18 25 :- meta_predicate(forto(*, *, ::)). 19 26 :- mode(forto(+integer, +integer, @callable), zero_or_one). 20 27 :- info(forto/3, [ 21 comment is 'Counting from First to Last do Call. For convenience and clarity, First and Last can be arithmetic expressions.',22 argnames is ['First', 'Last', ' Call']]).28 comment is 'Counting from First to Last call Goal. For convenience and clarity, First and Last can be arithmetic expressions.', 29 argnames is ['First', 'Last', 'Goal']]). 23 30 24 31 :- public(forto/4). … … 26 33 :- mode(forto(-integer, +integer, +integer, @callable), zero_or_one). 27 34 :- info(forto/4, [ 28 comment is ' Do Call counting from First to Last and instantiating Count to each successive value. For convenience and clarity, First and Last can be arithmetic expressions.',29 argnames is ['Count', 'First', 'Last', ' Call']]).35 comment is 'Call Goal counting from First to Last and instantiating Count to each successive value. For convenience and clarity, First and Last can be arithmetic expressions.', 36 argnames is ['Count', 'First', 'Last', 'Goal']]). 30 37 31 38 :- public(fordownto/3). … … 33 40 :- mode(fordownto(+integer, +integer, @callable), zero_or_one). 34 41 :- info(fordownto/3, [ 35 comment is 'Counting from First to Last do Call. For convenience and clarity, First and Last can be arithmetic expressions.',36 argnames is ['First', 'Last', ' Call']]).42 comment is 'Counting from First to Last call Goal. For convenience and clarity, First and Last can be arithmetic expressions.', 43 argnames is ['First', 'Last', 'Goal']]). 37 44 38 45 :- public(fordownto/4). … … 40 47 :- mode(fordownto(-integer, +integer, +integer, @callable), zero_or_one). 41 48 :- info(fordownto/4, [ 42 comment is ' Do Call counting from First to Last and instantiating Count to each successive value. For convenience and clarity, First and Last can be arithmetic expressions.',43 argnames is ['Count', 'First', 'Last', ' Call']]).49 comment is 'Call Goal counting from First to Last and instantiating Count to each successive value. For convenience and clarity, First and Last can be arithmetic expressions.', 50 argnames is ['Count', 'First', 'Last', 'Goal']]). 44 51 45 52 :- public(whiledo/2).
