[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

format strings are the Right Thing



I retract my previous apologetic attitude towards format and wishy-washy
"it's ugly but handy" attitude.  I now consider format superior both
practically *and* theoretically.  I won't fall into the "it's not
functional, kill it!" camp.

Yes, format is a mini-language.  Mini-languages are not inherently bad.
R5RS itself uses a mini-language for macros rather than give the full
functional power of Scheme to macros as CL does.

In this case format is the bottom tier of a long and rich tradition of
templated output.  If you work with HTML template systems you know that
one of the Holy Grails of templating is to achieve a clean separation of
data and logic.  Then you can just pour the data into the template, and
re-use the same template for different data, or pass the data into
different templates, or modify a template safely without risk of
breaking any code.  Full CL format is Turing-complete and therefore
falls short of this Holy Grail (as do most template systems in practice)
but still has most of these properties for the common cases, and
SRFI-{2,4}8 both *do* preserve this distinction.

HTML template systems usually use a more verbose syntax, but that
doesn't mean that format syntax is bad, nor does it mean we can't revise
or extend format syntax.  One possibility is to define a full XML-based
template system and use automatic abbreviations for short format
strings.  This is a rich area of study and I don't think we should
abandon it or label it as ugly just "because it's not functional."

Don't be sheep!  The time for that is over, it's almost the year of the
monkey!  Not everything has to be a function.

-- 
Alex