trealla-prolog / trealla

A compact, efficient Prolog interpreter written in plain-old C.
MIT License
252 stars 11 forks source link

arg/3 + string weirdness #553

Closed guregu closed 1 week ago

guregu commented 1 week ago

Noticed some oddities with strings and bagof, doesn't seem to happen with other types (that I have tried).

Example program:

foo("abc").
foo("blah").

Query:

?- bagof(X, foo(X), Xs).
   Xs = ["abc","blah"]. % ok, expected
?- X = "abc", bagof(X, foo(X), Xs).
   throw(error(type_error(compound,[a,b,c]),arg/3)). % unexpected, want Xs = ["abc"]

Another example query (this time erroring on the 2nd arg?)

?- X = "foo", bagof(X, member(X, ["foo", "bar"]), Xs).
   throw(error(type_error(compound,[b,a,r]),arg/3)). % unexpected
guregu commented 1 week ago

More concise issue:

?- arg(2,"foo",_74).
   throw(error(type_error(compound,[f,o,o]),arg/3)).

Interestingly SWI throws an error for this ^ but Scryer accepts it fine.

guregu commented 1 week ago

Thanks, looks good now!