| 1 | ================================================================ |
|---|
| 2 | Logtalk - Open source object-oriented logic programming language |
|---|
| 3 | Release 2.35.0 |
|---|
| 4 | |
|---|
| 5 | Copyright (c) 1998-2009 Paulo Moura. All Rights Reserved. |
|---|
| 6 | Logtalk is free software. You can redistribute it and/or modify |
|---|
| 7 | it under the terms of the "Artistic License 2.0" as published by |
|---|
| 8 | The Perl Foundation. Consult the "LICENSE.txt" file for details. |
|---|
| 9 | ================================================================ |
|---|
| 10 | |
|---|
| 11 | |
|---|
| 12 | % start by loading the "assignvars" category and the example: |
|---|
| 13 | |
|---|
| 14 | | ?- logtalk_load(assignvars(loader)). |
|---|
| 15 | ... |
|---|
| 16 | |
|---|
| 17 | |
|---|
| 18 | % rectangle example: |
|---|
| 19 | |
|---|
| 20 | ?- rectangle(2, 3, _)::(init, position(X0, Y0), move(3, 7), position(X1, Y1), move(2, 5), position(X2, Y2)). |
|---|
| 21 | |
|---|
| 22 | X0 = 0 |
|---|
| 23 | Y0 = 0 |
|---|
| 24 | X1 = 3 |
|---|
| 25 | Y1 = 7 |
|---|
| 26 | X2 = 2 |
|---|
| 27 | Y2 = 5 |
|---|
| 28 | |
|---|
| 29 | Yes |
|---|
| 30 | |
|---|
| 31 | |
|---|
| 32 | % finite state machine example: |
|---|
| 33 | |
|---|
| 34 | | ?- fsm(T, I, F), fsm(T, I, F)::recognise([0,1,1,2,1,2,0]). |
|---|
| 35 | |
|---|
| 36 | red-0-red |
|---|
| 37 | red-1-green |
|---|
| 38 | green-1-yellow |
|---|
| 39 | yellow-2-red |
|---|
| 40 | red-1-green |
|---|
| 41 | green-2-red |
|---|
| 42 | red-0-red |
|---|
| 43 | |
|---|
| 44 | T = [red-0-red, red-1-green, red-2-red, yellow-0-red, yellow-1-green, yellow-2-red, green-0-yellow, ... -... -yellow, ... -...] |
|---|
| 45 | I = red |
|---|
| 46 | F = [red] |
|---|
| 47 | |
|---|
| 48 | Yes |
|---|
| 49 | |
|---|
| 50 | |
|---|
| 51 | % finite state machine example: |
|---|
| 52 | |
|---|
| 53 | | ?- fsm(T, I, F), !, fsm(T, I, F)::recognise([0,1,1,2,1,2,1,0]). |
|---|
| 54 | |
|---|
| 55 | red-0-red |
|---|
| 56 | red-1-green |
|---|
| 57 | green-1-yellow |
|---|
| 58 | yellow-2-red |
|---|
| 59 | red-1-green |
|---|
| 60 | green-2-red |
|---|
| 61 | red-1-green |
|---|
| 62 | green-0-yellow |
|---|
| 63 | backtracking... |
|---|
| 64 | backtracking... |
|---|
| 65 | backtracking... |
|---|
| 66 | backtracking... |
|---|
| 67 | backtracking... |
|---|
| 68 | backtracking... |
|---|
| 69 | backtracking... |
|---|
| 70 | backtracking... |
|---|
| 71 | |
|---|
| 72 | No |
|---|