4 ms·
Learning Prolog for "mind expansion" feels weird in 2021. As a language (at least SWI-Prolog), it's missing some niceties that I took for granted: e.g., a func
by legerdemain 5y ago
Learning Prolog for "mind expansion" feels weird in 2021.
As a language (at least SWI-Prolog), it's missing some niceties that I took for granted: e.g., a function's output is always to a C-style output variable, all "context" variables must be passed around in recursive calls, etc.
There are several well-regarded books on Prolog that also feel quite antiquated in their concerns: authors taking pains to build elaborate conventions around function naming and argument ordering, etc.
Aside from its unusual features, Prolog really feels like a language from the early 90s, with a small, static standard library you might memorize, and authors offering "helpful tips" around functions with slightly different names in "commercial systems."
- khaled_ismaeel 5y agoI think it's incorrect to think of prolog's execution model in terms of "functions" and "output". So I don't think the nicities you're hoping for are applicable in prolog (at least not in their straightforward definition). Though I agree that prolog seems like it came from the 90's; I especially agree with that "functions with slightly different names" bit.
- legerdemain 5y agoO'Keefe's The Craft of Prolog happily describes function arguments as "input" and "output." I'm taking the liberty to say "function" instead of "functor," because the latter is more obscure. And there absolutely is a distinction between conceptual inputs and outputs, because many functions can find instantiations only for some arguments and not others. For example, I can query `length([a, b, c], N)`, but not `length(X, 3)`.
- lager 5y agoEh? Your Prolog system must be broken… ?- length(X, 3). X = [_1586, _1592, _1598]. ?-
- legerdemain 5y agoVery well, if you insist on ignoring the broader point in favor of the specific example, then replace `length` with `is`. We can unify `X is 3 * 3`, we cannot unify `9 is 3 * X` (at least not in SWI-Prolog v8.4.1). Therefore, we can call the thing to the left of `is` the output and the thing to the right of `is` the input.