print/1 and quoted writing

Jan Wielemaker <[email protected]>
Newsgroups gmane.comp.ai.prolog.swi
Message-ID <[email protected]>
Hi,

The predicate print/1 is typically used for printing (debug) messages.
That leads to nasty error messages like this:

1 ?- number_codes('1', X).
ERROR: Type error: `number' expected, found `1'

Yap suffers from the same issue:

?- number_codes('1', X).
     ERROR!!
     TYPE ERROR- number_codes/2: expected number, got 1

GNU-Prolog prints the raw exception using quoted write.  That is
fine in this example, but this makes you very unhappy:

?- length(L, 1000000), number_codes(L, X).

SICStus and ECLiPSe don't seem to be calling print/portray either,
but they use the max_depth option of write_term/3 to limit the
output.

I think that the debugger should call a write routine that calls
portray and uses quoted output.  For the toplevel itself, that
would be rather trivial: use write_term/3.  Messages however
use format/3 and almost all system messages use ~p (print) for
printing terms if there is nothing special to do (e.g., because
we know what term we are talking about).

I see some ways out.

  - Make print/1 do this (portray+quoted).  It makes a lot of
    sense as (AFAIK), print was always intended for interaction
    with the programmer.  It is not ISO (AFAIK), but it is widely
    available and does only portray.  Application code should use
    write/1 (ISO) or format/printf/writef (various systems).  But
    of course, some doesn't :-(

  - Add printq/1 and invent a new format specifier (but q is
    already taken.  Possible ~:p to use the modifier system?)

	Cheers --- Jan

P.s.	The introduction of strings make this more important
	to solve as we now have 1, '1' and "1" that all print
	the same :-(
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.