I made some custom output of dictionaries with portray. The problem now, If I use it with the command
set_prolog_flag(answer_write_options,[max_depth(0)])
my custom portray predicate is no longer used. How can I solve that problem?
Here is some simple example code to illustrate this:
% Prints dictionary varlues in a way, every value is on a seperate line in the terminal.
portray(Term) :-
is_dict(Term),
dict_pairs(Term, Tag, Pairs),
writef("%p{\n", [Tag]),
foreach(member(Key-Value, Pairs), writef("\t%p: %p\n\n", [Key, Value])),
write("}").
% Converts some string into some dictionary.
alphabeth(ABC, IndexList, Dict) :-
string_length(ABC, N), numlist(1, N, IndexList),
string_chars(ABC, V),
pairs_keys_values(KV, IndexList, V),
dict_pairs(Dict, alphabeth, KV).
go(I, D) :-
set_prolog_flag(answer_write_options,[max_depth(0)]),
alphabeth("abcdefghijklmnopqrstuvwxyz", I, D).
If I now call:
?- go(I, D).
I = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26],
D = alphabeth{1:a,2:b,3:c,4:d,5:e,6:f,7:g,8:h,9:i,10:j,11:k,12:l,13:m,14:n,15:o,16:p,17:q,18:r,19:s,20:t,21:u,22:v,23:w,24:x,25:y,26:z}.
The index list I
is shown without dots. The problem here, the dictionary output is not the one I would expect because of my portray predicate.
If I call the following instead:
?- alphabeth("abcdefghijklmnopqrstuvwxyz", I, D).
I = [1, 2, 3, 4, 5, 6, 7, 8, 9|...],
D = alphabeth{
1: a
2: b
3: c
4: d
5: e
6: f
7: g
8: h
9: i
10: j
11: k
12: l
13: m
14: n
15: o
16: p
17: q
18: r
19: s
20: t
21: u
22: v
23: w
24: x
25: y
26: z
}.
The dictionary itself is illustrated fine. But the list is shown limited. What could be the problem here?