The less-familiar parts of Lisp for beginners — pprint-newline

Continuing our discussion of pretty-printing, we arrive at pprint-newline.  This is another function that is used inside the environment set up within the context of pprint-logical-block.  The pprint-newline function takes a ‘kind’ argument that can be one of four possible keyword values.

If kind is :linear, a newline will be printed only if the entire output of the section cannot fit on a single line.  In that case, all such linear-mode newlines will be output.  In the typical usage, this means you either print all objects on one line, or each object on its own line.  Compare this to the pprint-linear function.

If the kind is :miser, then this function inserts a newline exactly like :linear, but only when in “miser mode”.  Miser mode takes effect whenever the start of the printing block is closer to the right margin than the value of the variable *print-miser-width*.  If miser mode is not in effect, this function never inserts a newline.

If the kind is :fill, then this function inserts a newline only when the current line cannot hold the next object to be printed.  The effect is to put as many objects on each line as possible before starting a new line.  Compare this to the pprint-fill function.

If the kind is :mandatory, the function always inserts a newline, unconditionally.

You should use pprint-newline in pprint-logical-block blocks, and avoid the use of format or terpri functions, as the latter do not integrate with the formatting behaviour of pretty-printing.  For instance, the pprint-indent function, which only takes effect after the next newline, is not guaranteed to do anything if you use format or terpri instead of pprint-newline.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

*

反垃圾邮件 / Anti-spam question * Time limit is exhausted. Please reload CAPTCHA.