1/* 2 * predicates helpful to port buggy programs from Muprolog to 3 * Sepia. 4 */ 5 6% Mireille. 7% these are predicates copied almost straight away from ~sepia/workdir/sepia/lib/cio.pl 8% loaded that way they are local. I think it is better. 9 10:- import 11 is_predicate_/2, 12 put0/1, 13 see1/1, 14 tell1/1, 15 write_/2 16 from sepia_kernel. 17 18see(File) :- 19 see1(File), 20 (File \== user -> 21 set_stream(File, input) 22 ; 23 true 24 ). 25 26seeing(File) :- 27 current_stream(File, _, input). 28 29seen :- 30 seeing(File), 31 (File \== user -> close(File); true), 32 set_stream(input, stdin). 33 34tell(File) :- 35 tell1(File), 36 (File \== user -> 37 set_stream(File, output) 38 ; 39 true 40 ). 41 42telling(File) :- 43 current_stream(File, _, output). 44 45told :- 46 telling(File), 47 (File \== user -> close(File); true), 48 set_stream(output, stdout). 49 50/* 51:- skipped 52 see/1, 53 seeing/1, 54 seen/0, 55 skip/1, 56 tab/1, 57 tell/1, 58 telling/1, 59 told/0. 60*/ 61 62% for the LOB programs 63 64% tells the parser to read strings as lists of ascii 65% to mimic the muprolog's way of handling strings 66% !!! this is a global change (in all modules) 67set_all_strings_to_lists :- 68 set_chtab(128, string_quote), % make something else the string quote 69 set_chtab(0'", list_quote). % make double quote the list quote 70 71% Sets back " " to quote strings 72set_back_strings_to_strings:- 73 set_chtab(0'", string_quote). 74 75 76strings_to_lists([], []). 77strings_to_lists([S|SL], [L|LL]) :- 78 string_to_list(S, L), 79 strings_to_lists(SL, LL). 80 81string_to_list("", []) :- !. 82string_to_list(String, [HI | Tail]) :- 83 substring(String, 1, 1, Head), 84 char_int(Head, HI), 85 string_length(String, L), 86 TL is L - 1, 87 substring(String, 2, TL, ST), 88 string_to_list(ST, Tail). 89 90lists_to_strings([], []). 91lists_to_strings([L|LL], [S|SL]) :- 92 list_to_string(L, S), 93 lists_to_strings(LL, SL). 94 95list_to_string([], "") :- !. 96list_to_string([H | T], String) :- 97 char_int(HS, H), 98 list_to_string(T, TS), 99 concat_strings(HS, TS, String). 100