mthom / scryer-prolog

A modern Prolog implementation written mostly in Rust.
BSD 3-Clause "New" or "Revised" License
2.08k stars 125 forks source link

... / 2 appears to run in O(N) when it could run in O(1) #2156

Open stefan-kral opened 1 year ago

stefan-kral commented 1 year ago
?- use_module(library(iso_ext)), use_module(library(pio)), use_module(library(dcgs)), use_module(library(time)).
   true.
?- time(countall(phrase_from_file((...,[_],...),'scryer-prolog.wxs'),N)).
   % CPU time: 1.056s
   N = 2065.

I seems to me that ... / 2 does not yet quite exploit the properties of the internal partial string representation.

UWN commented 1 year ago

As long as #1714 is open,...

But at least you could consider '$max_skip_list'/3 for this purpose (of the last ... //0)

stefan-kral commented 1 year ago

As long as #1714 is open,...

What happens as long as #1714 is open?

But at least you could consider '$max_skip_list'/3 for this purpose (of the last ... //0)

That's up to the implementer of library(dcgs), not to a simple user of Scryer Prolog, wouldn't you agree?

UWN commented 1 year ago

As long as #1714 is open,...

What happens as long as #1714 is open?

... there is some space overhead just for reading a partial string with Prolog clauses. Any further consideration is moot.

stefan-kral commented 1 year ago

Right.

Still, properly using '$max_skip_list'/3 in the implementation of ... /2 in library(dcgs) would not hurt though...