Re: How Prolog became an education nightmare (Was: 50 Years of Prolog Nonsense)

Liste des GroupesRevenir à cl prolog 
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.prolog
Date : 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

Date Sujet#  Auteur
12 Nov 24 * How Prolog became an education nightmare (Was: 50 Years of Prolog Nonsense)9Mild Shock
12 Nov 24 +* Re: How Prolog became an education nightmare (Was: 50 Years of Prolog Nonsense)7Mild Shock
14 Nov 24 i`* Re: How Prolog became an education nightmare (Was: 50 Years of Prolog Nonsense)6Mild Shock
14 Nov 24 i +- Re: How Prolog became an education nightmare (Was: 50 Years of Prolog Nonsense)1Mild Shock
14 Nov 24 i `* Re: How Prolog became an education nightmare (Was: 50 Years of Prolog Nonsense)4Julio Di Egidio
14 Nov 24 i  `* Re: How Prolog became an education nightmare (Was: 50 Years of Prolog Nonsense)3Mild Shock
14 Nov 24 i   +- Re: How Prolog became an education nightmare (Was: 50 Years of Prolog Nonsense)1Mild Shock
15 Nov 24 i   `- Re: How Prolog became an education nightmare (Was: 50 Years of Prolog Nonsense)1Julio Di Egidio
14 Nov 24 `- Mode yfy to the rescue (Was: How Prolog became an education nightmare)1Mild Shock

Haut de la page

Les messages affichés proviennent d'usenet.

NewsPortal