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

support functional predicate definition syntax #8

Description

@mndrix

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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions