0
votes

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?

1
Yes, in SWI Prolog, "ZPP" represents the "string" (list) of codes for Z, P, and P. So they're equivalent. Not sure what mode you have your SWI Prolog set to that causes it to default do displaying [90, 80, 80] as a string. Perhaps more importantly, you have at least two singleton variables and your query doesn't terminate (infinitely generates the solution Output = [90, 80, 80]). - lurker

1 Answers

2
votes

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.