3 ms·
> Note that this if-then statement is written backwards from how it’s written in English: the “then” part, the conclusion is written first, followed by the :- s
by vosper 2y ago
> Note that this if-then statement is written backwards from how it’s written in English: the “then” part, the conclusion is written first, followed by the :- symbol. After the :- symbol come the premises
Why not write it like it’s written in English? It could be one less thing to learn for people trying to adopt the language.
https://dusa.rocks/docs/introductions/graph/ https://dusa.rocks/docs/introductions/graph/
- jonjojojon 2y agoThe :- is supposed to sort of look like a left facing arrow for an implication. I think this notation started with prolog, so that is my guess why they chose to make it like this.
- khaledh 2y agoI think the reason is that the right hand side can be a long and complex set of premises. It is supposed to be read as: The lhs is true iff everything on the rhs is true. You can also think the same way about functions in typical languages: we don't write the body of the function first and then assign it to an identifier.
- Jtsummers 2y agoYes, but not `iff`. f(X) :- g(X), h(X). f(a). With those two statements, `f(a)` is true, but it does not mean that `g(a)` and `h(a)` are also true. Instead, it means that we happen to know some fact, `f(a)`, and some rule for cases beyond that fact. If it also happened that `g(a)` and `h(a)` are true then we'd have two ways of arriving at the fact of `f(a)` being true. It's a reverse of the implication arrow and is meant to be read that way: f(X) :- g(X), h(X). Is read as "f(X) if g(X) and h(X)", versus "if g(X) and h(X) then f(X)".
- khaledh 2y agoThanks for the correction :)
- robsimmons 2y agoThe two answers by jonjojojo and khaledh are great, because they are both the correct answers. From a principled point of view, the rule "a :- b, c" helps define what "a" means, and it seems, in practice, most helpful to be able to quickly visually identify the rules that define a certain relation. The list of premises tends to be of secondary importance (in addition to often being longer and more complicated). From a practical point of view, we wrote Dusa as people familiar with existing Datalog and Answer Set Programming languages, which use the backwards ordering and ":-" notation, and some of the core target audience we hope to get interested in this project is people familiar with those languages, so we made some syntax choices to make things familiar to a specific target audience. (Same reason Java uses C-like syntax.)
- skybrian 2y agoIt's not really written backwards; it's just equivalent to a different if statement. Something like this: if (want: edge Y X) { search for: edge X Y } This is searching in reverse compared to a different if statement: if (have: edge X Y) { assert: edge Y X }
- deleted 2y ago[deleted]
- treetalker 2y agoI suppose you could read it (i.e., ":-") as "provided that …", in which case it does follow standard English word order.
- robsimmons 2y agoGood point! "Whenever" is probably even closer to the correct meaning.
- treetalker 2y agoAgreed, "whenever" expresses a necessary implication, while "provided" expresses necessary but not necessarily sufficient prerequisites.