Sujet : Re: How Prolog became an education nightmare (Was: 50 Years of Prolog Nonsense)
De : julio (at) *nospam* diegidio.name (Julio Di Egidio)
Groupes : comp.lang.prologDate : 14. Nov 2024, 21:21:50
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <vh5m4u$2o1jf$1@dont-email.me>
References : 1 2 3 4 5
User-Agent : Mozilla Thunderbird
On 14/11/2024 05:14, Mild Shock wrote:
Typically we want to then go on and write
for example a compiler:
:- op(1100,fy,begin).
:- op(1100,yf,end).
compile((begin X end)) --> compile(X). %%% scoping omitted
compile((X;Y)) --> compile(X), compile(Y).
compile((V=E)) --> [load(E),store(V)].
The problem is the pattern (begin X end) will
not work, if multiple (begin … end) are involved
in the compile/1 call. You can try yourself, no
Prolog system can do it:
/* SWI-Prolog */
?- X = (begin
x = 1;
begin
y = 2
end
end), compile(X, L, []).
false.
%%% expected L = [load(1),store(x),load(2),store(y)]
<snip>
This seems to do the trick:
```
% SWI-Prolog 9.2.7
:- op(1100, fy, begin).
:- op(1100, yf, end).
compile((begin XEnd)) --> compile(XEnd).
compile((X end)) --> compile(X).
compile((X;Y)) --> compile(X), compile(Y).
compile((V=E)) --> [load(E),store(V)].
compile_t(X, L) :-
X = (
begin
x = 1;
begin
y = 2
end
end
),
compile(X, L, []).
```
```
?- compile_t(X, L).
X = (begin x=1;begin y=2 end end),
L = [load(1),store(x),load(2),store(y)].
```
-Julio