scryer-prolog icon indicating copy to clipboard operation
scryer-prolog copied to clipboard

`predicate_property/2` doesn't support `static`,`public`,`private`

Open rotu opened this issue 8 months ago • 6 comments

According to ISO/IEC 13211-1, every procedure is either public or private. Also according to spec, every procedure is either static or dynamic.

These are not reported by predicate_property/2.

e.g.: Should also report private and static for builtins:

?- predicate_property(fail,X).
   X = built_in
;  false.

e.g.: Should also report private and static for library procedures that are not declared otherwise:

?- predicate_property(lists:length(_,_),A).
   false.

e.g.: Should also report public for dynamic procedures:

?- assertz(foo).
   true.
?- predicate_property(foo,X).
   X = dynamic
;  false.

rotu avatar Apr 30 '25 18:04 rotu

It seems predicate_property/2 would be a good candidate for inclusion in the standard? A good starting point is a comparison table that shows commonalities among existing implementations, and also parts where they currently differ. (It's in Part 2!)

triska avatar Apr 30 '25 18:04 triska

~~It seems predicate_property/2 would be a good candidate for inclusion in the standard?~~

~~What do you mean?~~

It is in ISO/IEC 13211-2:

6.8 Predicate properties

The properties of procedures can be found using the built-in predicate predicate_property(Callable, Property), where Callable is the meta-argument term Module:Goal (7.2.2). The predicate properties supported shall include:

  • static -- The procedure is static.
  • dynamic -- The procedure is dynamic.
  • public -- The procedure is a public procedure.
  • private -- The procedure is a private procedure.
  • built_in -- The procedure is a built-in predicate.
  • multifile -- The procedure is the subject of a multifile directive.
  • exported -- the module Module exports the procedure.
  • metapredicate(MPMI) -- The procedure is a metapredicate, and MPMI is its metapredicate mode indicator.
  • imported_from(From) -- The predicate is imported into module Module from the module From.
  • defined_in(DefiningModule) -- The module with the name DefiningModule is the defining module of the procedure.

A processor may support one or more additional predicate properties as an implementation specific feature.

rotu avatar Apr 30 '25 18:04 rotu

Yes indeed, it's in Part 2, I initially overlooked it!

triska avatar Apr 30 '25 19:04 triska

I initially overlooked it!

You had me questioning my sanity there!

rotu avatar Apr 30 '25 19:04 rotu

I'm unclear at this point the status of predicate_property/2 vis-à-vis ISO/IEC 13211-2.

Is it intended to specify the standard predicate? Or is it a built-in implementation-specific predicate that happens to share a name?


It seems SICStus defines the predicate properties slightly differently per docs. It also doesn't define static, public, private either.

The various properties associated with Callable. Each loaded predicate will have one or more of the properties:

  • one of the atoms built_in (for built-in predicates) or compiled or interpreted (for user defined predicates) or fd_constraint for indexical predicates see Section 10.9.13 [Defining Indexical Constraints], page 494.
  • the atom dynamic for predicates that have been declared dynamic (see Section 4.3.4.2 [Dynamic Declarations], page 88),
  • the atom multifile for predicates that have been declared multifile (see Section 4.3.4.1 [Multifile Declarations], page 87),
  • the atom volatile for predicates that have been declared volatile (see Section 4.3.4.3 [Volatile Declarations], page 88),
  • the atom jittable for predicates that are amenable to JIT compilation,
  • the atom jitted for predicates that have been JIT compiled,
  • one or more terms (block Term) for predicates that have block declarations (see Section 4.3.4.5 [Block Declarations], page 88),
  • the atom exported or terms imported_from(ModuleFrom) for predicates exported or imported from modules (see Section 4.11 [ref-mod], page 165),
  • the term (meta_predicate Term) for predicates that have meta-predicate declarations (see Section 4.11.16 [ref-mod-met], page 175).

rotu avatar Apr 30 '25 20:04 rotu

Relevant discussion in #2933. Reading between the lines, it seems the property of being "public" in the ISO sense might not be as useful as it seemed at first blush.

I'm not sure whether that means it's not useful to have predicate_property/2 reflect this property.

On one hand, whether a predicate is unchangeable (dynamic) is semantically distinct from whether its implementation can be examined (public). On the other hand, in both Scryer and SICStus today, public and dynamic effectively coincide, so the distinction is useless.

rotu avatar May 01 '25 22:05 rotu