
Logic Programming and Compiler Writing (1980) [pdf] - weatherlight
http://sovietov.com/tmp/warren1980.pdf
======
fusiongyro
If you'd like to see a much smaller worked example of an assembler and
machine, I built a Prolog implementation of the reddit dailyprogrammer
challenge "Halt Machine" a few years ago. My code is here:

[https://github.com/fusiongyro/dailyprogrammer/tree/master/20...](https://github.com/fusiongyro/dailyprogrammer/tree/master/2013/05/22-halt-
simulation)

The challenge itself is here:

[https://www.reddit.com/r/dailyprogrammer/comments/1euacb/052...](https://www.reddit.com/r/dailyprogrammer/comments/1euacb/052213_challenge_125_intermediate_halt_its/)

~~~
nudpiedo
it is very interesting to see an actual implementation of such kind of
compiler in a set of logical rules. I see in the reddit link that there are
implementations in other languages but everyone seems to be an expert in the
languages they are using (e.g. the JS one seems to be the most straightforward
and the Common Lisp quite verbose actually)

Do you have a similar experience using other languages or paradigms? what were
your subjective challenges and the benefits compared with other languages?

~~~
fusiongyro
The idea at work here is Alan Kay's, to bring the spec into the language as
code somehow. Prolog is better suited to this than many other languages,
simply because it is so easy to reuse existing operators and structures but
overlay them with new semantics, as well as adding your own operators. But I
think you can do that same fundamental idea in any language. The ROI will
often be lower though, if you tried to do what I did in Java, for instance. In
this case the core is very procedural. That was kind of fun to do, just as a
reminder that Prolog can do that without it being onerous. But the ROI would
have been even higher if the core problem involved nondeterminism, constraints
or deduction in some unavoidable way.

A lot of the code I write in Prolog is written to demonstrate you can do
practical things in Prolog without it turning into C or Pascal. I feel that
Lisp managed to shed the "this is only for AI" stigma, thanks to books like
_Practical Common Lisp_ and partly thanks to Emacs itself. But Prolog is still
sort of thought of as this freak language only really useful for solving
Einstein puzzles and sudoku.

Prolog is not my strongest language, and I am far from an expert in it. But, I
don't think you have to be an expert in it to use it productively and enjoy
it. If I had tried to do this problem in Haskell or Python or Java, I would
probably have solved it in a completely different way.

I don't know if this addresses your questions or not, but I'm glad to talk
more.

~~~
richard_shelton
it's interesting to mention that both Alan Kay (see "The early history of
Smalltalk") and John McCarthy (see "advice taker") have very high opinion of
logic programming.

Thanks for showing your code! I just placed my minimalist DSL tools and
decided to use "Halt Problem" as an example. Here is my code:
[https://github.com/true-grue/dsl-tools](https://github.com/true-grue/dsl-
tools)

~~~
fusiongyro
Very beautiful code! Thanks for sharing it, I really like the simplicity of
your parser combinators.

~~~
richard_shelton
Thank you very much! I decided to place my DSL tools (they contain a tiny
amount of code, but I've used them successfully in a number of compiler
projects) on github and just started looking for some illustrative examples.
And your solution for Halt Problem (never heard about this problem before -- I
mean this reddit challenge, of course, not Rice's theorem) appeared just in a
right time. Thank you! :)

As a side note. It would be interesting to investigate power of a Prolog-like
language which has terms, term variables, pattern matching (maybe even without
full unification) and only local backtracking. Plus an ability to make user-
defined execution strategies (tree traversals etc) in the form of combinators.
I already use most of these constucts in dsl_match module and I got my
inspiration mostly from Stratego/XT. Still it would be good to see similiar
general-purpose language and compare its expressiveness with Prolog.

