Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><strong>TL;DR: don't!</strong></p> <p><code>current_functor/2</code> is an SWI-specific built-in predicate that you will find nowhere else (except the only historically relevant DECsystem 10). The reason for this predicate is related to the specific representation of functors in SWI. In brief, SWI needs to register each functor, before using it. (And prior to that it needs to register the related atom.) What happens if the functor is no longer used? Will it then still be present or not? Is this resource garbage collected?</p> <p><strong>To answer your question:</strong> <code>current_functor/2</code> will only succeed for functors. There are no functors of arity 0. A term with arity 0 is called an atom and is handled differently.</p> <p>In any case you will write code that depends on a single implementation which is maintained by a single person. Not a very safe bet for a larger project.</p> <p>Other Prolog systems work differently. They need to register atoms too, but then they can construct any functor up to <code>max_arity</code> without using some further global resource. For this reason, many systems offer <code>current_atom/1</code>.</p> <p>But even that very predicate is ill defined. After all, what does it mean that an atom is still present? May an optimizing compiler remove an atom and thereby change its meaning? Is it a means to inspect the confidential atoms an application uses by some otherwise harmless looking query code?</p> <p>This all is really a can of worms. Avoid them at any cost. Maybe use <code>current_predicate</code> instead.</p> <hr> <p>All that said, if you still believe you need it, do:</p> <pre><code>current_f(F, A) :- current_functor(F, A). current_f(F, 0) :- current_atom(F). </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload