Teaman
Teaman

Reputation: 162

Swi-prolog bug weird output

I have following program:

filter([],_What,[]).

filter(List,What,Output):-
    not(select(What-Val,List,Rest)), 
    filter([],What,Output).

filter(List,What,[Val|Output]):-
    select(What-Val,List,Rest),
    filter(Rest,What,Output).

I don't understand why following query:

filter([age-90, age-80,age-80],age,Output).

outputs:

Output = "ZPP" 

I have latest version of SWI-prolog ( 7.4.2 ), and have mac with El Captain (10.11.6).

I have tried guitracer, and it builds list [90,80,80] but outputs "ZPP" I have no idea why it does that.

SWISH online prolog outputs [90,80,80], so it must be something with SWI-Prolog.

EDIT

It seems that it converts number into characters 90=Z, 80=P, etc...

Why does it do this?

Upvotes: 0

Views: 332

Answers (1)

Jan Wielemaker
Jan Wielemaker

Reputation: 1710

Hard to tell how it got loaded, but this behaviour can be triggered by portray_text(true):

6 ?- A = [90,80,80].
A = [90,80,80].

7 ?- portray_text(true).
true.

8 ?- A = [90,80,80].
A = "ZPP".

The idea is that if you process text as lists of character codes the output is hard to read. portray_text/1 enables a portray/1 hook that tries to interpret a list of integers as a list of character codes and if successful prints the result as a string.

The GUI tracer can be configured to do this, but I don't think this is the default.

Upvotes: 2

Related Questions