Remember that a Prolog "character" is an atom of length 1.
However, this predicate also accepts SWI-Prolog strings of length 1 on first position.
:- begin_tests(char_code). test(ok1,[true(Truly)]) :- char_code('a',X), Truly = (X == 97). test(ok2,[true(Truly)]) :- char_code("a",X), Truly = (X == 97). test(ok3,[true(Truly)]) :- char_code(C,97) , Truly = (C == a). test(ouch1,[error(type_error(_,_))]) :- char_code(aa,_). test(ouch2,[error(type_error(_,_))]) :- char_code('',_). test(ouch3,[error(type_error(_,_))]) :- char_code(12,_). test(ouch4,[error(type_error(_,_))]) :- char_code(_,a). test(ouch5,[error(type_error(_,_))]) :- char_code(_,"a"). test(ouch6,[error(instantiation_error)]) :- char_code(_,_). % It's not not quite relational: test(weird1,[true(Truly)]) :- XS="a", char_code(XS,C), char_code(XA,C), Truly = (XS\==XA). :- end_tests(char_code). rt(char_code) :- run_tests(char_code).