% module: print_chars % date: November 21, 2005 % author: Douglas M. Auclair % Copyright (c) 2005, Cotillion Group, Inc. All rights reserved. % synopsis: Facilitates porting applications between Quintus and SWI by % providing skeletal implementations of these Quintus modules % to SWI. :- module(print_chars, []). % modified: December 8, 2005, DMA % changed: Passed in the max number of characters we wish to see % modified: December 6, 2005, DMA % changed: Added assertation to print the list as a string, given that % every member is a character (an integer) and that every % character is printable. :- asserta((user:portray(Chars) :- improper_string(60, Chars, Last, [Char|S], []), (\+ (\+ Last = '_|_') -> format('["~s"|~p]', [[Char|S], Last]) ; (\+ (\+ Last = []) -> format('"~s"', [[Char|S]]) ; format('["~s"|~p]', [[Char|S], Last]))))). :- asserta((user:portray(L1-L2) :- print_chars:difference_string(60, L1-L2, String, []), format('["~s"|_L]-_L', [String]))). difference_string(X, [Char|L1] - L2) --> { X > 0, Y is X - 1, integer(Char), Char > 9, Char < 128 }, [Char], difference_string(Y, L1 - L2). difference_string(0, _) --> !, "...". difference_string(_, L1 - L1) --> []. improper_string(X, [Char|T], Last) --> { X > 0, Y is X - 1, integer(Char), Char > 9, Char < 128 }, !, [Char], improper_string(Y, T, Last). improper_string(0, _Last, "...") --> !. improper_string(_, Last, Last) --> [].