sarathy@gpu.utcs.toronto.edu (Rajiv Sarathy) (11/23/88)
According to Clocksin & Mellish, AND according to the C-Prolog user's manual, "display(X) is supposed to display X "on the terminal in standard parenthe- sized prefix notation". The example on page 99 of the edition I have of C & M says that ?- display(a+b*c*c). should return +(a,*(*(b,c),c)) yes However, the implementation of C-Prolog I'm using (on a SUN 3/280, if it matters) merely returns X. Does someone have the definition of the "display" predicate? Thanks a lot in advance, --Raj -- ______________________________________________________________________________ | Disclaimer: I'm just an undergrad. | | All views and opinions are therefore my own. | | | | Rajiv Partha Sarathy sarathy@gpu.utcs.utoronto.ca | |______________________________________________________________________________|
ok@quintus.uucp (Richard A. O'Keefe) (11/24/88)
In article <1988Nov22.191600.26206@gpu.utcs.toronto.edu> sarathy@gpu.utcs.utoronto.ca (Rajiv Sarathy) writes: >The example on page 99 of the edition I have of C & M says that >?- display(a+b*c*c). > should return >+(a,*(*(b,c),c)) >yes I don't know what you mean by "return", but that is indeed what should come out on your terminal. > However, the implementation of C-Prolog I'm using (on a SUN 3/280, if >it matters) merely returns X. Transcript, please! (Easy way to do that: use the Unix 'script' command. Which is why C Prolog doesn't implement log/0 and nolog/0.) Last time I used C Prolog, display/1 worked fine. >Does someone have the definition of the "display" predicate? If you have a copy of C Prolog, you have the source code, so YOU have the definition. If you have a copy of the DEC-10 Prolog library, look in WRITE.PL. Otherwise: display(Term) :- telling(CurrentOutput), tell(user), display_1(Term), tell(CurrentOutput). display_1(Term) :- % for a COMPOUND term, nonvar(Term), functor(Term, F, N), N > 0, !, write(F), put("("), % <fn>(<arg 1>,...,<arg N>) display_1(1, N, Term). display_1(Term) :- % for a SIMPLE term, write(Term). % (variable, number, or atom) display_1(I, N, Term) :- arg(I, Term, Arg), display_1(Arg), ( I < N -> put(","), J is I+1, display_1(J, N, Term) ; put(")") ). There are some fine points that this doesn't get exactly right, but it's pretty close. (One of the fine points is that write/1 may round floating point numbers off; display/1 should write all the digits that make sense.)