3 ms·
> more abstract, but made your programs longer There are a few main reasons for Prolog code to come out longer than Lisp: - Prolog style is mostly first order
by abecedarius 7y ago
> more abstract, but made your programs longer
There are a few main reasons for Prolog code to come out longer than Lisp:
- Prolog style is mostly first order -- there's not a direct equivalent of lambda.
- Mutation is also used less.
- There's an equivalent of Lisp macros, but it's also less common.
- You don't nest function calls, but pass common named arguments instead.
So I can see where he was coming from. On the other hand I'd guess he had his Prolog experience before constraint logic programming was well supported, and certainly before MiniKanren which gives back the conveniences of Lisp and helps you take the pure-declarative subset further.
- hjek 7y agoPG does indeed use a lot of mutation in his Arc code. "Karma" on `vote-for` on HN is just incremented like this: (++ (karma i!by) (case dir up 1 down -1)) At first this looks nice and simple, but when you have to write `unvote`, you're in trouble (because not all votes increase karma, and you'll have to figure out whether the particular vote being unvoted did). I was reading through The Reasoned Schemer (which covers MiniKanren). They do a lot of unnesting when translating from functional to logical programming. And yes, this does introduce an additional variable each time, making the logical version slightly longer. Apart from the `markdown` in the Hacker News code, there is an `unmarkdown` function[0] (whose job is to translate back from HTML to markdown!). In Prolog you could have gotten away with one predicate for that. That's a 50% saving just there. And you could perhaps use DCGs to cut it down further. Not sure I about Prolog being mostly first order. Plenty of built-in predicates that take predicate arguments, like `maplist`, `findall` and `foldl` that seem to be as commonly used as in Lisp. You might be right about lambdas missing though, so not sure you can emit a predicate (although you could emit the name of a predicate and call it). I'm too new to Prolog to tell, really. [0]: https://github.com/arclanguage/anarki/blob/master/lib/markdown.arc#L120 https://github.com/arclanguage/anarki/blob/master/lib/markdo...
- abecedarius 7y agoRe: lambda expressions, it turns out there was a proposal to add them. Maybe it or something like it is in common use by now; I wouldn't know. http://www.complang.tuwien.ac.at/ulrich/Prolog-inedit/ISO-Hiord.html http://www.complang.tuwien.ac.at/ulrich/Prolog-inedit/ISO-Hi... (It's true that you can write higher-order programs without them. The style was often clumsier and used less, at least as I saw it back when I read much Prolog.) Re: unnesting, I've toyed with the idea of a slightly fancier Prolog syntax that lets you write nested calls which get desugared to the use of an extra parameter. Of course they'd have to look distinct from functors as data.