|
|
|
|
|
by mattcwilson
4229 days ago
|
|
"if" here isn't a perfect analog to a traditional imperative language's if statement. A better set of keywords to describe the logic might be "when ... allow". Because there is an implication here, it's just in reverse. Because the relation finds all possible solutions that meet the relationship, this code really reads "when s is the letter a, allow x to be 0, and call that a solution. Otherwise, any pairing where x is 2 is a solution." So if you were to call p(s, 0), you would find that you only get one solution, where s must be 'a'. From an imperative-ish POV, that "sets" (constrains) s to 'a'. OP is using if, combined with the notions that you take only the first of all relation solutions, and that you treat the rightmost relation member as an output, to achieve an imperative-like behavior in a non-deterministic logic language. Which is mentioned in the paragraph following the example. |
|