
Interpreter for a simple Lisp, Written in Prolog - martinlaz
https://github.com/triska/lisprolog
======
jasim
It seems that it takes far fewer lines of code (and correspondingly simple
program model) to implement LISP in Prolog than both imperative and functional
languages.

Once I asked a Prolog expert at a conference "Prolog is truly mind-bending and
powerful, but why don't we see it used more often? where are the jobs so I
could get one" and they said that for those who use Prolog in production it is
a real competitive advantage that they don't want to announce to the world;
plus some are state actors and quasi-state actors who use it for huge
scheduling and optimization problems and like their secrets secret. I think I
believe that.

~~~
plinkplonk
" they said that for those who use Prolog in production it is a real
competitive advantage that they don't want to announce to the world;"

with due respect to prolog (which is a mindbending language), the proponents
of every niche language say the same thing. "it is so powerful that users
don't talk about it and that is why you don't hear about it"

I've heard many variants of this with respect to Forth, for example.

The reality is that devs can't stop talking about the languages, tools, and
frameworks they use.

The simpler explanation is that next to no one actually uses prolog in
productions, because it is, well, a _niche_ language (which doesn't take away
from its coolness)

Color me skeptical about "secret weapons".

~~~
segmondy
I use Prolog in production. :-)

I know many people that do too and don't talk about it unless you move in the
Prolog world.

Here's a stock broker using it
[https://dtai.cs.kuleuven.be/CHR/files/Elston_SecuritEase.pdf](https://dtai.cs.kuleuven.be/CHR/files/Elston_SecuritEase.pdf)

Java Virtual Machine specifiction is verified using prolog ", implemented the
Prolog verifier that formed the basis for the specification in both Java ME
and Java SE."
[https://docs.oracle.com/javase/specs/jvms/se7/html/jvms-0-pr...](https://docs.oracle.com/javase/specs/jvms/se7/html/jvms-0-preface7.html)
Prolog code ->
[https://docs.oracle.com/javase/specs/jvms/se7/html/jvms-4.ht...](https://docs.oracle.com/javase/specs/jvms/se7/html/jvms-4.html#jvms-4.10)

[https://kylecordes.com/2010/the-prolog-
story](https://kylecordes.com/2010/the-prolog-story)

IBM Watson was written in C++ and Prolog

~~~
jasim
Thanks a ton! I was hoping to hear more about people like you when I wrote
that comment.

------
mark_l_watson
This is old code, but it has sparked a great discussion here.

In the 1980s I spent months writing a prototype planning system in Common Lisp
(which is a primary language for me, and I wrote a CL book for Springer-Verlag
back then). Even though I was a Prolog novice, I was able to rewrite my entire
prototype in Prolog in one week. Admittedly this was because the second
implementation of something is always easier, but also because Prolog was such
a good fit to this particular problem.

I remember reading The Fifth Generation Computer about Japan’s AI efforts -
enjoyed the book but it didn’t really click for me, mostly because I had a
Lisp Machine and considered that the `one true path` for AI development at the
time.

------
pjmlp
Prolog was one of my favourite languages during my degree, to the point that I
participated in some logic programming championships.

Would like to have some excuses to actually use it on my daily work.

As side note, until our compiler design lectures decided to switch the
required implementation language to the newly arrived Java, it was possible to
choose whatever programming language to implement our assignments.

However Lisp and Prolog were off limits as they would make them too easy!

------
kevsim
This brings back fond memories as writing a lisp interpreter in prolog was the
final project for my survey of programming languages course in university.
Didn’t know people would still be doing it 20 years later.

~~~
KineticLensman
As someone who is implementing a Lisp interpreter (admittedly in C#, not
Prolog) I've decided that this sort of project is somewhat analogous to
restoring a classic car. It'a a good way to get a handle on earlier times.

------
FigBug
This was a fairly common project when I was in University, except we had to do
Scheme in Prolog.
[https://github.com/FigBug/scheme](https://github.com/FigBug/scheme)

Prolog was a mind bending language. Some things that would be so simple in
another language were so hard, and somethings that would be hard, were so
easy.

I never really got my head around Prolog, just enough to get the assignment
finished. But I do remember it as being one of the more interesting
assignments I did, interesting enough that I've managed to keep the code for
20+ years.

------
MayeulC
I suspect that an optimization problem I will have to face in a bit of time
might be a good fit for Prolog. What would be the best resources for a quick,
relatively high level overview/introduction, then a more involved guide for
learning it?

This question has been asked elsewhere, but is there a way to pass data back
and forth with other languages, and let them control the execution flow? A C
interface would seem like a good IR to target.

My apologies if I used the wrong terminology, I am not intimate with the more
academic nomenclature.

~~~
hjek
Here's a nice and simple one:
[https://xmonader.github.io/prolog/2018/12/21/solving-
murder-...](https://xmonader.github.io/prolog/2018/12/21/solving-murder-
prolog.html)

------
sp332
_Some online books... require you to manually translate Prolog programs to
Lisp forms that are no longer valid Prolog syntax._

I thought Lisp was commonly used to create domain-specific languages with
different syntaxes. Wouldn't this be old hat for someone experienced with
Lisp? (Asking because I don't have a lot of experience with Lisp.)

~~~
lispm
Often Prolog implementations in Lisp used a lisp-like syntax. They were not
concerned with reading standard Prolog code.

Several implementations support(ed) standard Edinburgh-Prolog syntax. For
example the LispWorks implementation of Prolog supports both:
[http://www.lispworks.com/documentation/lw71/KW-W/html/kwprol...](http://www.lispworks.com/documentation/lw71/KW-W/html/kwprolog-w-135.htm#marker-869240)

------
lispm
a more complex attempt at a Common Lisp in Prolog:

[https://github.com/TeamSPoon/wam_common_lisp](https://github.com/TeamSPoon/wam_common_lisp)

------
jedimastert
This is a weird nit, and I might be wrong, but isn't the "pl" extension
usually used with Perl scripts?

~~~
def-
Prolog uses .pl and because of the Perl conflict occasionally .pro:
[http://www.swi-prolog.org/pldoc/man?section=fileext](http://www.swi-
prolog.org/pldoc/man?section=fileext)

I still found a

    
    
        autocmd Filetype pl set syntax=prolog
    

in my vim config from my Prolog days.

------
ealhad
Funny. Chapter 24 of Paul Graham's _On Lisp_ is about implementing Prolog in
Common Lisp.

~~~
zerr
It's obligatory for any Lisp book to include a Prolog implementation.

~~~
vram22
Interesting. Do you know why?

~~~
lispm
Implementing some kind of Prolog (and also other logic formalism) was common
in the AI boom. Some were primitive (for example only using Lisp-like syntax),
some were quite extensive (then also providing Edinburgh-Prolog syntax). Most
AI tools included some reasoning facility, often in the form of some Prolog.
The two commercial Common Lisps (Allegro CL and LispWorks) still offer Prolog
implementations.

One of the more extensive treatments of implementing Prolog-like features can
be found in "Paradigms of Artificial Intelligence Programming" (PAIP) by Peter
Norvig.

Book and code available here:

[https://github.com/norvig/paip-lisp](https://github.com/norvig/paip-lisp)

~~~
ken
"Prolog is similar to Lisp on the main points." (ibid)

~~~
triska
In my opinion, this is true for _some_ main points, but definitely not for all
of them.

A key difference between the languages is in how easily you can _reason about_
programs. In Prolog, if you program in the pure monotonic subset of the
language, you get certain algebraic guarantees that are not available in Lisp.
For instance, for pure Prolog code and a declarative reading, removing a goal
can at most _increase_ the set of solutions, and removing a clause can at most
_decrease_ the set of solutions.

In Prolog, these guarantees can be used to test and debug your programs by
logical reasoning. In fact, to a significant extent, you can even _automate_
debugging due to these properties. Such techniques were pionereed by Ehud
Shapiro in his 1982 PhD thesis, _Algorithmic Program Debugging_ :

[http://cpsc.yale.edu/sites/default/files/files/tr237.pdf](http://cpsc.yale.edu/sites/default/files/files/tr237.pdf)

The thesis is an excellent read, and I highly recommend it! Specifically,
quoting from page 155:

“ _Although Lisp is considered a high level language, it is not clear that it
encourages precision and clarity of thought. As one Lisp hacker puts it [91]:
"Lisp...is like a ball of mud. You can add any amount of mud to it...and it
still looks like a ball of mud!". This aspect of Lisp is the hacker's delight,
but the theoretician's nightmare. It is known that one may implement without
too much effort a reasonable Prolog in Lisp. However, the issue is not
implementation — the issue is the method of thought. Based on my experience
with both languages I maintain that one's thoughts are better organized, and
one's solutions are clearer and more concise, if one thinks in Prolog rather
than in Lisp._”

Another key feature of Prolog is that _constraints_ blend in seamlessly,
leading to an important declarative programming paradigm called _constraint
logic programming_ (CLP). This is the key reason why Prolog is frequently used
to solve combinatorial tasks in practice, and often an important motivation
for buying a commercial Prolog system.

~~~
lispm
> Although Lisp is considered a high level language

Lisp is generally not restricted to a particular 'level'. It also comes out-of
the box with support for different programming paradigms - but no particular
language support for logic programming.

> if one thinks in Prolog rather than in Lisp

Lisp supports high-level programming in logic by zillions of extensions. This
has been popular throughout Lisp's history. Thus if we have a problem which is
best solved by some kind of Logic, then it would be great of the Lisp system
could be programmed in terms of that logic - which is not unusual.

That said, a programming language built from the ground on some logic
formalism like Prolog is a great tool.

------
crimsonalucard
This can probably done with CSS. Also assembly language. You can do it with
assembly language as well.

