Changeset 4094 for trunk/library
- Timestamp:
- 02/16/08 03:54:30 (11 months ago)
- Location:
- trunk/library
- Files:
-
- 2 modified
Legend:
- Unmodified
- Added
- Removed
-
trunk/library/loop.lgt
r4090 r4094 6 6 version is 1.2, 7 7 author is 'Paulo Moura', 8 date is 2008/2/1 5,8 date is 2008/2/16, 9 9 comment is 'Loop control structures predicates.']). 10 10 … … 31 31 foreach_inv(List, Count, Goal). 32 32 33 :- meta_predicate(forto_aux(*, *, *, *, ::)). 34 forto_aux(Count, First, Last, Increment, Goal) :- 35 ( First =< Last -> 36 \+ \+ (Count = First, call(Goal)), 37 Next is First + Increment, 38 forto_aux(Count, Next, Last, Increment, Goal) 39 ; true 40 ). 41 33 42 :- meta_predicate(forto(*, *, ::)). 34 43 forto(FirstExp, LastExp, Goal) :- 35 44 First is FirstExp, 36 45 Last is LastExp, 37 ( First =< Last -> 38 \+ \+ call(Goal), 39 Next is First + 1, 40 forto(Next, Last, Goal) 41 ; true 42 ). 46 forto_aux(_, First, Last, 1, Goal). 43 47 44 48 :- meta_predicate(forto(*, *, *, ::)). … … 46 50 First is FirstExp, 47 51 Last is LastExp, 48 ( First =< Last -> 52 forto_aux(Count, First, Last, 1, Goal). 53 54 :- meta_predicate(forto(*, *, *, *, ::)). 55 forto(Count, FirstExp, LastExp, IncrementExp, Goal) :- 56 First is FirstExp, 57 Last is LastExp, 58 Increment is abs(IncrementExp), 59 forto_aux(Count, First, Last, Increment, Goal). 60 61 :- meta_predicate(fordownto_aux(*, *, *, *, ::)). 62 fordownto_aux(Count, First, Last, Decrement, Goal) :- 63 ( First >= Last -> 49 64 \+ \+ (Count = First, call(Goal)), 50 Next is First + 1,51 for to(Count, Next, Last, Goal)65 Next is First - Decrement, 66 fordownto_aux(Count, Next, Last, Decrement, Goal) 52 67 ; true 53 68 ). … … 57 72 First is FirstExp, 58 73 Last is LastExp, 59 ( First >= Last -> 60 \+ \+ call(Goal), 61 Next is First - 1, 62 fordownto(Next, Last, Goal) 63 ; true 64 ). 74 fordownto_aux(_, First, Last, 1, Goal). 65 75 66 76 :- meta_predicate(fordownto(*, *, *, ::)). … … 68 78 First is FirstExp, 69 79 Last is LastExp, 70 ( First >= Last -> 71 \+ \+ (Count = First, call(Goal)), 72 Next is First - 1, 73 fordownto(Count, Next, Last, Goal) 74 ; true 75 ). 80 fordownto_aux(Count, First, Last, 1, Goal). 81 82 :- meta_predicate(fordownto(*, *, *, *, ::)). 83 fordownto(Count, FirstExp, LastExp, DecrementExp, Goal) :- 84 First is FirstExp, 85 Last is LastExp, 86 Decrement is abs(DecrementExp), 87 fordownto_aux(Count, First, Last, Decrement, Goal). 76 88 77 89 :- end_object. -
trunk/library/loopp.lgt
r4091 r4094 5 5 version is 1.2, 6 6 author is 'Paulo Moura', 7 date is 2008/2/1 5,7 date is 2008/2/16, 8 8 comment is 'Loop control constructs protocol.']). 9 10 11 :- public(whiledo/2). 12 :- meta_predicate(whiledo(::, ::)). 13 :- mode(whiledo(+callable, @callable), zero_or_one). 14 :- info(whiledo/2, [ 15 comment is 'While Condition is true do Action.', 16 argnames is ['Condition', 'Action']]). 9 17 10 18 :- public(dowhile/2). … … 17 25 :- public(foreach/3). 18 26 :- meta_predicate(foreach(*, *, ::)). 19 :- mode(foreach( -term, +list(term), @callable), zero_or_one).27 :- mode(foreach(@var, +list(term), @callable), zero_or_one). 20 28 :- info(foreach/3, [ 21 comment is 'For each element Count in List call Goal.',22 argnames is [' Count', 'List', 'Goal']]).29 comment is 'For each element Element in List call Goal.', 30 argnames is ['Element', 'List', 'Goal']]). 23 31 24 32 :- public(forto/3). 25 33 :- meta_predicate(forto(*, *, ::)). 26 :- mode(forto(+ integer, +integer, @callable), zero_or_one).34 :- mode(forto(+number, +number, @callable), zero_or_one). 27 35 :- info(forto/3, [ 28 comment is 'C ounting from First to Last call Goal. For convenience and clarity, First and Last can be integerexpressions.',36 comment is 'Call Goal counting up from First to Last. Increment is 1. For convenience and clarity, First and Last can be arithmetic expressions.', 29 37 argnames is ['First', 'Last', 'Goal']]). 30 38 31 39 :- public(forto/4). 32 40 :- meta_predicate(forto(*, *, *, ::)). 33 :- mode(forto( -integer, +integer, +integer, @callable), zero_or_one).41 :- mode(forto(@var, +number, +number, @callable), zero_or_one). 34 42 :- info(forto/4, [ 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 integerexpressions.',43 comment is 'Call Goal counting up from First to Last and instantiating Count to each successive value. Increment is 1. For convenience and clarity, First and Last can be arithmetic expressions.', 36 44 argnames is ['Count', 'First', 'Last', 'Goal']]). 45 46 :- public(forto/5). 47 :- meta_predicate(forto(*, *, *, *, ::)). 48 :- mode(forto(@var, +number, +number, +number, @callable), zero_or_one). 49 :- info(forto/5, [ 50 comment is 'Call Goal counting up from First to Last and instantiating Count to each successive value. For convenience and clarity, First, Last, and Increment can be arithmetic expressions. The absolute value of Increment is used.', 51 argnames is ['Count', 'First', 'Last', 'Increment', 'Goal']]). 37 52 38 53 :- public(fordownto/3). 39 54 :- meta_predicate(fordownto(*, *, ::)). 40 :- mode(fordownto(+ integer, +integer, @callable), zero_or_one).55 :- mode(fordownto(+number, +number, @callable), zero_or_one). 41 56 :- info(fordownto/3, [ 42 comment is 'C ounting from First to Last call Goal. For convenience and clarity, First and Last can be integerexpressions.',57 comment is 'Call Goal counting down from First to Last. Decrement is 1. For convenience and clarity, First and Last can be arithmetic expressions.', 43 58 argnames is ['First', 'Last', 'Goal']]). 44 59 45 60 :- public(fordownto/4). 46 61 :- meta_predicate(fordownto(*, *, *, ::)). 47 :- mode(fordownto( -integer, +integer, +integer, @callable), zero_or_one).62 :- mode(fordownto(@var, +number, +number, @callable), zero_or_one). 48 63 :- info(fordownto/4, [ 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 integerexpressions.',64 comment is 'Call Goal counting down from First to Last and instantiating Count to each successive value. Decrement is 1. For convenience and clarity, First and Last can be arithmetic expressions.', 50 65 argnames is ['Count', 'First', 'Last', 'Goal']]). 51 66 52 :- public( whiledo/2).53 :- meta_predicate( whiledo(::, ::)).54 :- mode( whiledo(+callable, @callable), zero_or_one).55 :- info( whiledo/2, [56 comment is ' While Condition is true do Action.',57 argnames is ['Co ndition', 'Action']]).67 :- public(fordownto/5). 68 :- meta_predicate(fordownto(*, *, *, *, ::)). 69 :- mode(fordownto(@var, +number, +number, +number, @callable), zero_or_one). 70 :- info(fordownto/5, [ 71 comment is 'Call Goal counting down from First to Last and instantiating Count to each successive value. For convenience and clarity, First, Last, and Decrement can be arithmetic expressions. The absolute value of Decrement is used.', 72 argnames is ['Count', 'First', 'Last', 'Decrement', 'Goal']]). 58 73 59 74 :- end_protocol.
