3 ms·
>> The version without ! looks identical to the version with ! except only the ! is removed - is this a joke? That's just showing getting rid of the cut in two
by YeGoblynQueenne 5mo ago
>> The version without ! looks identical to the version with ! except only the ! is removed - is this a joke?
That's just showing getting rid of the cut in two stages. The line that makes it possible to remove it is this one:
N #> 0,
Markus Triskas' argument is that if you use the #> etc versions of declarative arithmetic operators, instead of the > ones, you can then call the factorial predicate with both arguments as variables, i.e. without inputs, just outputs, to enumerate the entire factorial relation. Like this:
?- n_factorial(N, F).
N = 0, F = 1
; N = 1, F = 1
; N = 2, F = 2
; N = 3, F = 6
; ... .
If you use > instead of #> the line N > 0 will raise an exception if N is a variable, which will be the case if you call it as above. This stops you from enumerating the relation, which declarative arithmetic allows.
Of course there are other ways to write a factorial predicate (or any predicate) so that it always enumerates a relation but they are more verbose. Then again, you do need a special library to use declarative arithmetic anyway, so.