What's the difference between write, print, pprint, princ, and prin1?
Asked Answered
A

1

24

I'm getting into some Lisp, and I've come across various different functions that to me appear to be doing the same thing... Namely printing to console... So what exactly is the difference between all those different functions?

Avoid answered 3/11, 2013 at 18:19 Comment(1)
In general, the HyperSpec, to which Rainer Joswig's answer links is a very good reference for Common Lisp. There's also a documentation search, lispdoc, that's very useful, as it searches the HyperSpec and some other Common Lisp language references.Ingle
B
38

This is answered here: http://www.lispworks.com/documentation/HyperSpec/Body/f_wr_pr.htm

  • write is the general entry point to the Lisp printer.
  • prin1 produces output suitable for input to read.
  • princ is just like prin1 except that the output has no escape characters. princ is intended to look good to people, while output from prin1 is intended to be acceptable for the function read.
  • print is just like prin1 except that the printed representation of object is preceded by a newline and followed by a space.
  • pprint produces pretty output.
Borlase answered 3/11, 2013 at 18:27 Comment(2)
Is there a specification of what is "pretty" output? Indentation is one thing that I can think of. Might different implementations define it differently?Hobble
'pretty printed' means layouted for the available horizontal space and indented accordingly.Borlase

© 2022 - 2024 — McMap. All rights reserved.