4 ms·
PG 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))
by hjek 7y ago
PG 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.