Extending FORMAT
Posted: Mon Sep 22, 2008 2:51 am
I want to format my text using FORMAT-like syntax, but with ability to call some other functions, for example
(message "%a" obj) would print (descr obj), and (message "%b" obj) prints (short-descr obj).
I thought of making wrappers to that functions, and using them to with the FORMAT's slash-tilde directive. Then my code can just replace "%a" with "~/my-package::descr-wrapper/" and "%b" with "~/my-package::short-descr-wrapper/" (this is simplified, I would also preserve directive parameters) and pass control to FORMAT itself.
This, however, looks ugly to me (not to mention inefficient, but that doesn't matter much to me). Is there a better way? Would I be better off with writing my own formatting function? Or maybe there is some library that allows for user-extensible FORMAT-like syntax, like what ITERATE is to LOOP?
(message "%a" obj) would print (descr obj), and (message "%b" obj) prints (short-descr obj).
I thought of making wrappers to that functions, and using them to with the FORMAT's slash-tilde directive. Then my code can just replace "%a" with "~/my-package::descr-wrapper/" and "%b" with "~/my-package::short-descr-wrapper/" (this is simplified, I would also preserve directive parameters) and pass control to FORMAT itself.
This, however, looks ugly to me (not to mention inefficient, but that doesn't matter much to me). Is there a better way? Would I be better off with writing my own formatting function? Or maybe there is some library that allows for user-extensible FORMAT-like syntax, like what ITERATE is to LOOP?