-
Notifications
You must be signed in to change notification settings - Fork 32
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
length/2 loops for cases of finite failure #191
Comments
Consider to use an implementation similar to Scryer which is based on an internal built-in |
Going through the test cases: #19 that's syntax, It seems you have implemented everything in Go. Instead, consider to implement |
I've been thinking this over. Most of my questions are already answered in mthom/scryer-prolog#1023. 21 and 22 should be Still having trouble at 26. The list is not finite. p.p.3.1.a says "If List is neither a partial list nor a list, then the goal fails." To understand more about 26, I'll implement I'm writing most of the predicates in Go because I want to make this library easy to sandbox. If I write // Good
p := new(prolog.Interpreter) // An interpreter without any predicates
p.Register2(`length`, prolog.Length) // An interpreter with `length/2` // Bad
p := new(prolog.Interpreter) // An interpreter without any predicates
p.Register4(`$skip_max_list`, prolog.SkipMaxList) // An interpreter with `$skip_max_list/4`
p.Exec(`length(L, N) :- ..., $skip_max_list(...), ... .`) // An interpreter with `$skip_max_list/4` and `length/2` |
From the standards viewpoint the name of a resource is just an implementation dependent atom. But it makes sense to somewhat indicate what this resource is about. Regardless of the presence of GC, Go's memory will be finite for the general case, like representing a list of arbitrary length. Therefore, it is helpful and resource-saving in 21 and 22 to produce the resource error immediately (strictly speaking, provided there is no constraint on the list), see Scryer for details. By stating that the resource is
The prologue as much as the entire standard always talks about finite terms. A unification like the one in #26 is STO (subject to occurs check , 7.3.3) and thus undefined. So any conclusion from something normative (which always assumes NSTO unification) to this undefined part does not hold. This includes your conclusion. So for you, as you have rational trees, the question is: what would happen if you let this goal just run. Assuming your implementation with bounded integers, you would run into an |
As for implementing things in Go vs Prolog. You might certainly also use the functionality of The Edinburgh Prologs do this (to varying degree): System code in those Prologs starts with a $, and after the system has loaded all those predicates (and established their relation between each other), these names are removed (interned). |
A helpful perspective is the one from the actual user: The more complex the errors generated, the more burden to the user. With unbounded integers there is one error case less. |
@UWN, thank you for elaboration! I wasn't able to allocate enough time to work on this project since I was busy on my day job, but I managed to re-implemented
|
I've been thinking how I can make it support unbounded integers. The current implementation of terms are simple and easy to work with because most of them are backed by Go's primitive types:
One thing we can do is to change the underlying type of Another option is to add |
For you it seems the objective is to get the system working with as few irregularities as possible. Offering two internal types is something many high performance systems do, but it seems your objective is less to squeeze out the very tiny last bits of performance. |
BTW, is the new |
Not yet. It's still in $ git checkout fix-length
Switched to branch 'fix-length'
Your branch is up to date with 'origin/fix-length'.
$ git pull
Already up to date.
$ go install github.com/ichiban/prolog/cmd/1pl
$ $(go env GOPATH)/bin/1pl
Top level for ichiban/prolog (devel)
This is for testing purposes only!
See https://github.com/ichiban/prolog for more details.
Type Ctrl-C or 'halt.' to exit.
?- skip_max_list(N, 2, [a, b, c, d], S).
N = 2,
S = [c, d].
?- L = [a|L], length(L,N).
2022/05/23 21:08:32 error(resource_error(finite_memory), length/2) |
@UWN I fixed conflicts and now $ git checkout main
Already on 'main'
Your branch is up to date with 'origin/main'.
$ go install github.com/ichiban/prolog/cmd/1pl
$ $(go env GOPATH)/bin/1pl
Top level for ichiban/prolog (devel)
This is for testing purposes only!
See https://github.com/ichiban/prolog for more details.
Type Ctrl-C or 'halt.' to exit.
?- length([_|L],0).
false. |
When I say |
@UWN I finally released $ go install github.com/ichiban/prolog/cmd/1pl@latest
$ $(go env GOPATH)/bin/1pl
Top level for ichiban/prolog v0.10.0
This is for testing purposes only!
See https://github.com/ichiban/prolog for more details.
Type Ctrl-C or 'halt.' to exit.
?- length([_|L],0).
false. |
Added. Please check the table. |
#3:
It may be helpful to go through all cases.
The text was updated successfully, but these errors were encountered: