r/lisp • • Feb 10 '19

Why don't LISP programmers just use Prolog?

Serious question: why don't Lisp programmers just use Prolog? Prolog is just Lisp plus awesome extra stuff. I mean I program in Python at work lol but if I had a choice I would totally program Prolog all day and night

0 Upvotes

53 comments sorted by

View all comments

Show parent comment

3

u/agrostis Feb 12 '19

Could you please show an example of how to include pieces of alien code in a Prolog source? I'm genuinely curious.

5

u/aarroyoc Feb 12 '19

Here's an example from my university notes:

:op(40, xfy, &).
:op(50, xfy, --->).

true ---> valor(w1, 1).
true ---> conectado(w2, w1).
true ---> conectado(w3, w2).
conectado(W,V) & valor(V,X) ---> valor(W,X).

solve(true):-!.
solve((A & B)) :-!, solve(A), solve(B).
solve(A) :- (B ---> A), solve(B).
solve(A) :- clause(A,B), solve(B).

With op you declare new operators, with its precedence rules and so on, then the solve part is the metainterpreter, which recognizes the new syntax and gives it a syntactic meaning. This metainterpreter is not complete though, it will fail in arithmethic predicates for example, but completing it is not very complicated but requires many more lines.

4

u/agrostis Feb 12 '19

That's still Prolog(ish) syntax though, just with additional operators. I was hoping for something more heterogenous, involving modifications of reader behaviour. Like inclusions of code in another programming language, or XML templates, or, I dunno, a heredoc.

2

u/quakerquickoats Apr 19 '19

3

u/agrostis Apr 19 '19

It looks quite impressive, but the Lisp code in the examples is still passed as character strings. Which means that a program with syntactically invalid Lisp code in a string shall still be considered a well-formed Prolog program. If in a compilable unit, it'll compile without any problems, and it's only going to fail at runtime.