annotate 3-Prolog/day2-unification.pl @ 58:90c4b7f28690

Add initial Day 2 notes for Prolog
author IBBoard <dev@ibboard.co.uk>
date Tue, 26 Sep 2017 20:58:49 +0100
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
58
90c4b7f28690 Add initial Day 2 notes for Prolog
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
1 % Unification works both sides of the equals:
90c4b7f28690 Add initial Day 2 notes for Prolog
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
2 % (A, 2, C) = (1, B, 3).
90c4b7f28690 Add initial Day 2 notes for Prolog
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
3 % We can't actually run this from a file, because Prolog. We get:
90c4b7f28690 Add initial Day 2 notes for Prolog
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
4 %
90c4b7f28690 Add initial Day 2 notes for Prolog
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
5 % native code procedure (=)/2 cannot be redefined (ignored)
90c4b7f28690 Add initial Day 2 notes for Prolog
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
6 %
90c4b7f28690 Add initial Day 2 notes for Prolog
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
7 % But we can run it from the REPL.
90c4b7f28690 Add initial Day 2 notes for Prolog
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
8 %
90c4b7f28690 Add initial Day 2 notes for Prolog
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
9 % Lists have heads and tails:
90c4b7f28690 Add initial Day 2 notes for Prolog
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
10 %
90c4b7f28690 Add initial Day 2 notes for Prolog
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
11 % [a, b, c] = [Head|Tail].
90c4b7f28690 Add initial Day 2 notes for Prolog
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
12 %
90c4b7f28690 Add initial Day 2 notes for Prolog
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
13 % Underscore is the wildcard variable:
90c4b7f28690 Add initial Day 2 notes for Prolog
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
14 %
90c4b7f28690 Add initial Day 2 notes for Prolog
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
15 % [a, b, c] = [_|Tail].
90c4b7f28690 Add initial Day 2 notes for Prolog
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
16 %
90c4b7f28690 Add initial Day 2 notes for Prolog
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
17 % Note: It's not magic "Head|Tail", it's "[X|Y]" notation