(no title)
lapsed_lisper | 3 years ago
https://www.dreamsongs.com/Files/PatternsOfSoftware.pdf
> What are the trade-offs? Format strings don’t look like Lisp, and they constitute a non-Lispy language embedded in Lisp. This isn’t elegant. But, the benefit of this is compact encoding in such a way that the structure of the fill-in-the-blank text is apparent and not the control structure.
IMO McDermott's OUT macro has precisely the drawbacks Gabriel predicts. While McDermott seems to think it's an advantage that
> we no longer have to squeeze the output data into a form intelligible to format, because we can use any Lisp control structure we like
his example PRINT-XAPPING basically duplicates the logic for extracting data from the xapping structure as Steele's FORMAT call, but buries the data extraction into control structure alongside constant strings that go into the output.
And that's where I think FORMAT really a win: a FORMAT control deliberately separates the control flow and constant text from the data extraction logic. Presumably you could write functions that do the same thing using McDermott's OUT macro, but they'll be more verbose and no more enlightening; what's the point?
interroboink|3 years ago
I think there is some advantage to allowing comments to be nested alongside the relevant bits of format text.
It reminds me a bit of Perl's /x modifier[1], which arguably achieves some of the best of both worlds for regex expressions.
[1] https://perldoc.perl.org/perlre#/x-and-/xx
lapsed_lisper|3 years ago
martinflack|3 years ago
I think CL-PPCRE gets this correct for a similar domain: regex strings. The library is not pedantic about whether you provide the compact string or an expanded nice version.
lapsed_lisper|3 years ago
Anyhow, while it's certainly possible to parse FORMAT control strings into S-expressions, ISTM that if you want them to be invertible back into FORMAT strings, you'll end up with control structure and constant strings being contained within the S-expression, with data extraction as a separate concern. IOW, you won't get McDermott's preferred style of interwoven control, data extraction, and constant strings. For instance, you could have this FORMAT control string
parse to something like but this still separates concerns the way FORMAT does, and the way OUT doesn't.