Example Programs Illustrating use of Cut
showing trace obtained by running it with EDProlog which has that capability
There are differences in where the
cut is placed in the programs on the left
Print this out and study it and see
how the placement of the cut modifies the results
using cut |
without cut |
/*
filename: cutdo.pro
- */ holiday (tuesday,
july_4). weather (tuesday,
fair). weekend (saturday). weekend (sunday). make (potato_salad,
Day) :- picnic(Day). picnic(Day) :- weather (Day, fair),!, weekend(Day). picnic (Day) :- holiday (Day, july_4). /* TRACE ?-consult cutdo. Compiling cutdo. Yes ?-trace. E: trace Yes. ?-make(potato_salad, tuesday). C: make(potato_salad,tuesday) C: picnic(tuesday) C: weather(tuesday,fair) E: weather(tuesday,fair) ! C: weekend(tuesday) F: weekend(tuesday) ! FAIL F: make(potato_salad,tuesday) No. ?- */ |
/*
filename: cutno.pro
*/ holiday (tuesday,
july_4). weather (tuesday,
fair). weekend (saturday). weekend (sunday). make (potato_salad,
Day) :- picnic(Day). picnic(Day) :- weather (Day, fair),
weekend(Day). picnic (Day) :- holiday (Day, july_4). /* TRACE ?-consult cutno. Compiling cutno. Yes. ?-trace. E: trace Yes. ?-make(potato_salad, tuesday). C: make(potato_salad,tuesday) C: picnic(tuesday) C: weather(tuesday,fair) E: weather(tuesday,fair) C: weekend(tuesday) F: weekend(tuesday) R: weather(tuesday,fair) F: weather(tuesday,fair) R: picnic(tuesday) C:
holiday(tuesday,july_4) E:
holiday(tuesday,july_4) Yes. ?- */ |
/* filename: cutdo2.pro */ holiday (tuesday, july_4). weather (tuesday, fair). weather (saturday, fair). weather (sunday, fair). weekend (saturday). weekend (sunday). make (potato_salad, Day) :- picnic(Day). picnic(Day) :- weather (Day, fair),!, weekend(Day). picnic (Day) :- holiday (Day, july_4). /* TRACE ?-consult cutdo2. Compiling cutdo2. Yes. ?-trace. E: trace Yes. ?-make(potato_salad, When). C: make(potato_salad,When_0) C: picnic(When_0) C: weather(When_0,fair) E: weather(tuesday,fair) ! C: weekend(tuesday) F: weekend(tuesday) ! FAIL F: make(potato_salad,When_0) No. ?- */ |
/* filename: cutno1.pro */ holiday (tuesday, july_4). weather (tuesday, fair). weather (saturday, fair). weather (sunday, fair). weekend (saturday). weekend (sunday). make (potato_salad, Day) :- picnic(Day). picnic(Day) :- weather (Day, fair), weekend(Day). picnic (Day) :- holiday (Day, july_4). /* TRACE ?-consult cutno1. Compiling cutno1. Yes. ?-trace. E: trace Yes. ?-make(potato_salad, When). C: make(potato_salad,When_0) C: picnic(When_0) C: weather(When_0,fair) E: weather(tuesday,fair) C: weekend(tuesday) F: weekend(tuesday) R: weather(When_0,fair) E: weather(saturday,fair) C: weekend(saturday) E: weekend(saturday) When = saturday More? (Y/N):y R: weekend(saturday) F: weekend(saturday) R: weather(When_0,fair) E: weather(sunday,fair) C: weekend(sunday) E: weekend(sunday) When = sunday More? (Y/N):y R: weekend(sunday) F: weekend(sunday) R: weather(When_0,fair) F: weather(When_0,fair) R: picnic(When_0) C: holiday(When_0,july_4) E: holiday(tuesday,july_4) When = tuesday ?- */ |
/* filename : cutdo3.pro */ holiday (tuesday, july_4). weather (tuesday, fair). weather (saturday, fair). weather (sunday, fair). weekend (saturday). weekend (sunday). make (potato_salad, Day) :- picnic(Day). picnic(Day) :- weather (Day, fair), weekend(Day),!. picnic (Day) :- holiday (Day, july_4). /* TRACE ?-consult cutdo3. Compiling cutdo3. Yes. ?-trace. E: trace Yes. ?-make(potato_salad, When). C: make(potato_salad,When_0) C: picnic(When_0) C: weather(When_0,fair) E: weather(tuesday,fair) C: weekend(tuesday) F: weekend(tuesday) R: weather(When_0,fair) E: weather(saturday,fair) C: weekend(saturday) E: weekend(saturday) ! When = saturday More? (Y/N):y ! FAIL F: make(potato_salad,When_0) No. ?- */ |
|
/* filename: cutdo4.pro */ holiday (tuesday, july_4). weather (tuesday, fair). weather (saturday, fair). weather (sunday, fair). weekend (saturday). weekend (sunday). make (potato_salad, Day) :- picnic(Day). picnic(Day) :- !, weather (Day, fair), weekend(Day). picnic (Day) :- holiday (Day, july_4). /* TRACE ?-consult cutdo4. Compiling cutdo4. Yes. ?-trace. E: trace Yes. ?-make(potato_salad, When). C: make(potato_salad,When_0) C: picnic(When_0) ! C: weather(When_0,fair) E: weather(tuesday,fair) C: weekend(tuesday) F: weekend(tuesday) R: weather(When_0,fair) E: weather(saturday,fair) C: weekend(saturday) E: weekend(saturday) When = saturday More? (Y/N):y R: weekend(saturday) F: weekend(saturday) R: weather(When_0,fair) E: weather(sunday,fair) C: weekend(sunday) E: weekend(sunday) When = sunday More? (Y/N):y R: weekend(sunday) F: weekend(sunday) R: weather(When_0,fair) F: weather(When_0,fair) ! FAIL F: make(potato_salad,When_0) No. ?- */ |
|
/* filename: cutdo5.pro */ holiday (tuesday, july_4). weather (tuesday, fair). weather (saturday, fair). weather (sunday, fair). weekend (saturday). weekend (sunday). make (potato_salad, Day) :- picnic(Day). picnic (Day) :- holiday (Day, july_4),!. picnic(Day) :- weather (Day, fair), weekend(Day). /* TRACE ?-consult cutdo5. Compiling cutdo5. Yes. ?-trace. E: trace Yes. ?-make(potato_salad, When). C: make(potato_salad,When_0) C: picnic(When_0) C: holiday(When_0,july_4) E: holiday(tuesday,july_4) ! When = tuesday More? (Y/N):y ! FAIL F: make(potato_salad,When_0) No. ?- */ |
|