]> gitweb.factorcode.org Git - factor.git/blob - extra/logic/examples/zebra-short/zebra-short.factor
Switch to https urls
[factor.git] / extra / logic / examples / zebra-short / zebra-short.factor
1 ! Copyright (C) 2019-2020 KUSUMOTO Norio.
2 ! See https://factorcode.org/license.txt for BSD license.
3 USING: logic lists ;
4 IN: logic.examples.zebra-short
5
6 ! Do the same as this Prolog program
7 !
8 ! neighbor(L,R,[L,R|_]).
9 ! neighbor(L,R,[_|Xs]) :- neighbor(L,R,Xs).
10 !
11 ! zebra(X) :- Street = [H1,H2,H3],
12 !             member(house(red,english,_), Street),
13 !             member(house(_,spanish,dog), Street),
14 !             neighbor(house(_,_,cat), house(_,japanese,_), Street),
15 !             neighbor(house(_,_,cat), house(blue,_,_), Street),
16 !             member(house(_,X,zebra),Street).
17
18 LOGIC-PREDS: neighboro zebrao ;
19 LOGIC-VARS: L R X Xs H1 H2 H3 Street ;
20 SYMBOLS: red blue ;
21 SYMBOLS: english spanish japanese ;
22 SYMBOLS: dog cat zebra ;
23 TUPLE: house color nationality pet ;
24
25 { neighboro L R L{ L R . __ } } fact
26 { neighboro L R L{ __ . Xs } } { neighboro L R Xs } rule
27
28 { zebrao X } {
29     { (=) Street L{ H1 H2 H3 } }
30     { membero [ T{ house f red english __ } ] Street }
31     { membero [ T{ house f __ spanish dog } ] Street }
32     { neighboro [ T{ house f __ __ cat } ] [ T{ house f __ japanese __ } ]  Street }
33     { neighboro [ T{ house f __ __ cat } ] [ T{ house f blue __ __ } ] Street }
34     { membero [ T{ house f __ X zebra } ] Street }
35 } rule
36