exercism / prolog

Exercism exercises in Prolog.
https://exercism.org/tracks/prolog
MIT License
29 stars 39 forks source link

Code working under SWISH failing under tests #181

Closed gitonthescene closed 1 year ago

gitonthescene commented 2 years ago

I'm new to both Prolog and Exercism so it's very possible that this is a misunderstanding on my part, but I wrote this code to solve the isograms problem and am getting the following errors (among others). When I run it on SWISH the query runs just fine.

Is it not recognizing or obeying the set_prolog_flag query? I do get the same from the tests if I remove that line (which should be necessary).

:- set_prolog_flag(double_quotes, chars).

repeats([X,X|_]).
repeats([_|Xs]):-repeats(Xs).
mem(L,X):-member(X,L).
string_letters(X,L):-
   partition(mem("abcdefghijklmnopqrstuvwxyz"),X,L,_).

pr(X,X-X).
isogram(X):-
   string_letters(X,L),
   maplist(pr,L,P),
   keysort(P,S),
   maplist(pr,Xs,S),
   \+ repeats(Xs).
% PL-Unit: isogram 
ERROR: 
    [[ EXCEPTION while printing message url('/mnt/exercism-iteration/isogram_tests.plt':9)
       with arguments []:
       raised: type_error(text,url('/mnt/exercism-iteration/isogram_tests.plt':9))
    ]]
:
    test empty_string: failed
gitonthescene commented 2 years ago

Also, I don't really understand what condition(pending) means even after reading the explanation. Is that doc supposed to be visible from the Exercism site or is it a note to exercise writers? As a user, I looked at the tests from the Exercism site and saw this and wondered if it might have something to do with my errors as it seemed mysterious.

[EDIT] I suppose it's the condition described here, but my reading of the predicate pending as written in the test doesn't match the description alluded to above.

gitonthescene commented 2 years ago

I've since solved it using string_codes/2 instead so that seems to be the issue. I still think that using set_prolog_flag should be acceptable.

ErikSchierboom commented 2 years ago

I don't know anything about Prolog's flags, but if you want to support it on Exercism, it should be somehow supported by the test runner: https://github.com/exercism/prolog-test-runner

ErikSchierboom commented 1 year ago

test empty_string: failed

This implies that the code doesn't work for all test cases, and a local run of the code confirms that.

I've double checked in the test runner with the below code and that works fine:

:- set_prolog_flag(double_quotes, chars).

works(X) :-
    "abc" == [a, b, c].