Hacker News new | ask | show | jobs
by radomir_cernoch 1254 days ago
When I was teaching Prolog are the university, I always introduced it as a niche language. “Prolog makes you unbelievably fast at very specific tasks, but don't try to implement a web server in it.”

I was so wrong! :-D

3 comments

Mercury, which is Prolog inspired, is actually a very interesting underrated language!

I think languages need to lean harder in the direction of doing more with functions than just evaluating them. Unification is one example, but you can imagine more.

> you can imagine more

My imagination is failing me! Can you give more examples?

Differential computing comes to mind. Kinda like prolog in that you can run a function in reverse.
What tasks is it really good for?
Straightforward searching through combinatoric spaces for planning and optimization, including robotic and eg. discrete investment planning for models where solutions can't be described by a finite number of variables (see [1] for in-browser container logistics planning).

Composition of programs with complex rule-based semantics and large specs (the Prince CSS renderer is written in Mercury).

Diagnostics, capturing legal, medical, and other taxonomic knowledge in executable form, possibly as implementation, extension, or replacement for semantic web stuff and description logic.

All of the above with easy and powerful DSL capabilities ranging from built-in customizable operator precedence parsing, over natural recursive descent parsing with backtracking, to attribute grammars and arbitrary logic (Prolog started out as a 70's natural language understanding approach employing logic grammars).

[1]: https://quantumprolog.sgml.io/

Define a model of your program’s state, as if you’d define a model in a database. There, that’s your program! It is actually a database. You can’t create invariants in the program. It’s entirely defined by how you modeled it. Your program is correct.
IIRC (it's been years), a highly-conformant Perl5/Perl6/python/javascript regex engine core in SWI Prolog was concise and performant. Like "wow, it just one short file" concise. And "KISS competitive-with-little-optimization" performant. Modulo memory halo. IIRC, far more effort went into bootstrapping grammars and creating testing infrastructure. It helped warped my perspective on how concise and pretty compiler guts could/should be.
Well, a CGI script isn't really a web server.