-
Notifications
You must be signed in to change notification settings - Fork 0
/
kopilog.pl
80 lines (70 loc) · 2 KB
/
kopilog.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
/* before you hit the coffeeshops, ask Kopilog! */
isADrink(espresso).
isADrink(coffee).
isADrink(tea).
isADrink(milo).
isADrink(horlicks).
/* mods */
sugar(less).
sugar(more).
sugar(none).
sugar(normal).
milk(evaporated).
milk(condensed).
temperature(hot).
temperature(cold).
dilution_factor(high).
dilution_factor(low).
dilution_factor(normal).
/* rough translations */
translate(espresso, tilok).
translate(coffee, kopi).
translate(tea, teh).
translate(milo, takkiu).
translate(horlicks, daikahou).
translate(sugar(less), siudai).
translate(sugar(more), kadai).
translate(sugar(none), kosong).
translate(sugar(normal), '').
translate(milk(evaporated), si).
translate(milk(condensed), '').
translate(dilution_factor(low), gao).
translate(dilution_factor(high), po).
translate(dilution_factor(normal), '').
translate(temperature(cold), peng).
translate(temperature(hot), sio).
writeTranslated(D, M, F, S, T) :-
translate(D, Dt),
translate(milk(M), Mt),
translate(dilution_factor(F), Ft),
translate(sugar(S), St),
translate(temperature(T), Tt),
/* side effects */
writeWithSpaces([Dt, Mt, Ft, St, Tt]).
writeWithSpaces([]) :- nl.
writeWithSpaces([''|T]) :- writeWithSpaces(T).
writeWithSpaces([H|T]) :-
write(H),
write(' '),
writeWithSpaces(T).
/* we want to write out the translated term with the right positional order */
order(espresso, sugar(none), milk(none), temperature(hot), dilution_factor(none)) :-
translate(espresso, X),
writeWithSpaces([X]), !.
order(D, sugar(S), milk(M), temperature(T), dilution_factor(F)) :-
D \= espresso,
isADrink(D),
writeTranslated(D, M, F, S, T), !.
/*
$ swipl
?- [kopilog].
true.
?- order(tea, sugar(less), milk(condensed), temperature(cold), dilution_factor(low)).
teh gao siudai peng
true .
?- order(coffee, sugar(none), milk(condensed), temperature(hot), dilution_factor(low)).
kopi gao kosong sio
true .
?- translate(sugar(none), S).
S = kosong.
*/