4 ms·
I was rather disappointed when I learned Prolog 20 years ago, because of the unfulfilled expectations. You could program in a totally declarative way, with log
by Al-Khwarizmi 4y ago
I was rather disappointed when I learned Prolog 20 years ago, because of the unfulfilled expectations.
You could program in a totally declarative way, with logic formulas, and the system would take care evaluating the formulas! As a person who likes the math/theory side of CS, that sounded absolutely amazing! Except that it wasn't really like that, because IIRC (20 years have passed so there may be some inaccuracies here, but this is the gist of what I remember) logical operators like "and" or "or" weren't even commutative, "a and b" vs "b and a" could be the difference between running normally and an infinite loop, you had to insert "!" (which were totally non-declarative and non-logic) to make things work as you wanted, and at that point you were thinking about what order things would be run in, so why not use an imperative language instead, where at least the order of execution is clear in the first place.
To each their own, though.
- triska 4y agoThese are valid concerns, arising mostly from inadequate implementations and a lack of modern features in early (and also current) Prolog systems. In the past 20 years, many new language constructs and implementation improvements were introduced and have become widely available in newer Prolog systems to address precisely these problems among others. For example, inspired by pioneering systems such as XSB Prolog, modern Prolog systems such as Scryer Prolog support alternative execution strategies, internally implemented via delimited continuations as described by Desouter et al., and thus prevent many infinite loops that arise with the default execution strategy: https://www.ijcai.org/Proceedings/16/Papers/619.pdf https://www.ijcai.org/Proceedings/16/Papers/619.pdf As another example, in 2016, Neumerkel and Kral introduced if_/3 and related predicates, which are now available as library(reif) in Scryer Prolog, and also available for SICStus with advanced compile-time expansions: https://arxiv.org/abs/1607.01590 https://arxiv.org/abs/1607.01590 As yet further examples, better indexing techniques such as JIT indexing and Scryer Prolog's first instantiated argument indexing help to improve determinism and efficiency automatically, and much improved internal string representations allow efficient parsing of large amounts of data with Prolog's built-in grammar mechanism that is now being drafted for standardisation. Constraints such as dif/2 are now also becoming more widely available after decades of being largely ignored by implementors. As long as we keep to the pure monotonic core of Prolog, conjunction and disjunction are indeed semantically commutative, and different execution strategies are applicable. Of course, using !/0 and other constructs that rely on specific execution strategies forfeits this advantage.
- bawolff 4y agoI'm a beginner at prolog, but i always found the logic explanation unsatisfying. I viewed it more as - imagine you construct a graph. Some of the verticies you construct have side effects, then to execute a program you run DFS on the graph you made.