Skip to content
This repository has been archived by the owner on Feb 9, 2020. It is now read-only.

support functional predicate definition syntax #8

Open
mndrix opened this issue Jul 10, 2013 · 0 comments
Open

support functional predicate definition syntax #8

mndrix opened this issue Jul 10, 2013 · 0 comments

Comments

@mndrix
Copy link
Owner

mndrix commented Jul 10, 2013

Ciao (with :=) and GRIPS (with <-) and Mercury (with =) provide special syntax for defining predicates that behave like functions.

In both GRIPS and Mercury, function definition implies determinism. I think Ciao makes a mistake here by allowing nondeterministic predicates to be defined with functional notation.

Using functional definitions should imply determinism. Mercury's = should be enough syntax. I've never seen =/2 as a top level functor. So, assuming --/1 performs decrement, our definition should be

fact(0) = 1
fact(N) = N * fact(--N)

which desugars into

fact(0, F) :- 
    !,
    F = 1.
fact(N, F) :- 
    succ(Nminus, N),
    fact(Nminus, F0),
    F is F0*N.

There's no protection against fact(-1) looping forever, but most functional languages don't protect against that either.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant