Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Built-in predicate request: function_property/2 #353

Open
pmoura opened this issue Jun 8, 2023 · 1 comment
Open

Built-in predicate request: function_property/2 #353

pmoura opened this issue Jun 8, 2023 · 1 comment

Comments

@pmoura
Copy link
Contributor

pmoura commented Jun 8, 2023

Latest versions of LVM and Trealla Prolog implement a function_property/2 built-in predicate, which provides similar functionality to the de facto standard predicate_property/2 built-in predicate, allowing checking or enumerating the properties of a given arithmetic function. The function_property/2 predicate allows clean checking if an arithmetic function is defined, simplifying e.g. portability linter checks for arithmetic expressions. The first argument is a function template (e.g. abs(_)) and the second argument is the property. Four properties are specified:

  • built_in (function is a defined built-in arithmetic function)
  • foreign (function is a defined arithmetic function implemented using the FLI)
  • static (function is a static arithmetic function)
  • dynamic (function is a dynamic arithmetic function)

The dynamic is meant for Prolog systems that allow runtime definition of new arithmetic functions (e.g. LVM). Built-in and foreign functions usually also have the static property.

The predicate spec is:

Template:
function_property(Function, Property)
Modes and number of proofs:
function_property(+callable, ?function_property) - zero_or_more

Exceptions:

  • Function is a variable:
    instantiation_error
  • Function is neither a variable nor a callable term:
    type_error(callable, Function)
  • Property is neither a variable nor an atom:
    type_error(atom, Property)
  • Property is an atom but not a valid function property:
    domain_error(function_property, Property)

Examples:

Check that popcount/1 is a built-in arithmetic function:

?- function_property(popcount(_), built_in).
true.

Would it be possible to add this predicate to Tau Prolog?

@pmoura
Copy link
Contributor Author

pmoura commented Jun 9, 2023

Update

An additional property, that enables e.g. more sophisticated linter checks, is template/2. It allows querying function arguments types and return types. For example:

?- function_property(abs(_), Property).
   Property = built_in ;
   Property = static ;
   Property = template(abs(integer), integer) ;
   Property = template(abs(float), float) ;
   false.

For some Prolog systems, the necessary internal tables to implement this property seems to already be there. For other, it would be more work. And in the case of Tau Prolog?

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

No branches or pull requests

1 participant