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

rebis-dev: length unexpectedly missing from TAB completions

Open triska opened this issue 8 months ago • 4 comments

I file this issue for https://github.com/mthom/scryer-prolog/issues/2575#issuecomment-2826706784:

In rebis-dev, length_rundown and length_addendum are suggested as completions for len, whereas length is not. Why not?

In master, all 3 are suggested completions.

Are there any other cases like this?

triska avatar Apr 24 '25 20:04 triska

length_rundown and length_addendum are predicates internal in library(lists), whereas length is an exported predicate. At the time the completion is tried, none of these predicates are even available, and the ideal behaviour would be that len does not expand further. But at the very least, if the predicates from library(lists) are part of completions even though the library itself is not yet loaded, then length should also be among the completions.

@euanlacy: Since you awesomely implemented TAB completion, would you maybe be interested in taking a look what is going going on here? I would greatly appreciate your help. Thank you a lot!

triska avatar Apr 26 '25 06:04 triska

I think this is likely due to short atoms no longer being stored in the atom table, as we only consult the atom table and the static atoms map for completion, this is also why we offer completion candidates which should not actually available on the prolog side of things.

I will continue to look through the code to try and work out how to get all the atoms which are actually valid, but as I am not well acquainted with the codebase any guidance or pointers would be greatly appreciated

euanlacy avatar Apr 27 '25 19:04 euanlacy

Maybe it could be worth considering to take current_predicate/1 into account for possible completions.

For instance, we have:

$ scryer-prolog -f
?- current_predicate(P).
   P = term_expansion/2
;  P = verify_attributes/3
;  P = goal_expansion/2
;  P = project_attributes/2
;  P = attribute_goals/3
;  P = repl/0.
?- use_module(library(lists)).
   true.
?- current_predicate(P).
   P = term_expansion/2
;  P = verify_attributes/3
;  P = goal_expansion/2
;  P = project_attributes/2
;  P = attribute_goals/3
;  P = repl/0
;  P = member/2
;  P = select/3
;  P = append/2
;  P = append/3
;  P = foldl/4
;  ... .

triska avatar Apr 27 '25 19:04 triska

this is likely due to short atoms no longer being stored in the atom table

Yes indeed, this seems to be the reason! Atoms up to length 6 (in bytes) are stored directly on the heap:

?- [user].
abcdef.
abcdefg.

abc now expands to abcdefg, whereas abcdef (6 bytes) is not suggested.

triska avatar Apr 27 '25 19:04 triska