All Manuals > LispWorks® User Guide and Reference Manual > 37 The HCL Package

safe-format-to-string

safe-format-to-limited-string

safe-prin1-to-string

safe-princ-to-string Functions

Summary

Print or format "safely", which means catching errors.

Package

hcl

Signatures

safe-format-to-string &rest format-args => string

safe-format-to-limited-string limit &rest format-args => string

safe-prin1-to-string object => string

safe-princ-to-string object => string

Arguments
format-args
A control-string and arguments as passed to format.
limit
A positive integer.
object
Any object.
Values
string
A string.
Description

safe-format-to-string, safe-prin1-to-string and safe-princ-to-string are analogs to the standard functions format (with first argument nil), prin1-to-string and princ-to-string. If format-args and object can be printed without any errors then they are equivalent to the standard functions, except that they bind *print-readably* and *print-circle* to nil.

The difference is when there is an error during the printing operation. The "safe" functions catch the error, and try to produce something that indicates that an error occurred during the printing operation and what it was, without causing recursive errors.

safe-format-to-limited-string is like safe-format-to-string, except that the length of the result string is limited to limit. The printing is stopped when the output become longer than limit and the result is a string of length limit, with the last three characters being "...". Limiting the length in this way also copes well when printing deeply nested objects.

Notes

These functions are intended to be used in code that handles and reports errors, where it is important to avoid recursive errors.

The debugging tools of the LispWorks IDE use these functions.

See also

prin1-to-string
princ-to-string
format


LispWorks® User Guide and Reference Manual - 01 Dec 2021 19:30:35