[pro] User defined format functions

Daniel Weinreb dlw at itasoftware.com
Tue Jan 25 20:53:16 UTC 2011



Didier Verna wrote:
> Daniel Weinreb wrote:
>
>   
>> Yes, we use it heavily, mainly for date/time processing, which can be
>> very complicated when you're dealing with time zones and such. 
>> Example:
>>
>> (list :departure-time (format nil "~/zul%ISO8601/" departure-time-zul)
>>     
>
>   OK, but does it really buy you anything, compared to just calling a
> specific function directly? Your examples all seem to contain only one
> format directive.
>   
Yes, I just realized that these aren't the best examples.
They are intended to be used inside more complex
format strings, and then the developers get used
to using the format directives rather than learning
the names of the corresponding functions, just
to have one less thing to learn.

This is a specifier for a scheduled flight:

    (format nil "F,~A,~A,~@[~A~],~/loc%YYYY-MM-DD/"
            (sched:flight-key-carrier key)
            (sched:flight-key-number key)
            (sched:non-blank-operational-suffix 
(sched:flight-key-op-suffix key))
            (sched:flight-key-date-local key)))

>
>   I reckon it is in general. It's just that if you're writing a library
> (as opposed to a top-level application), then you don't want to pollute
> the cl-user package (in fact, you just can't if you want to be on the
> safe side), so even when your code is (in-package :long.package.name),
> you still need to use the package prefix in the format string, and
> /that/, I find totally unusable.
>   
Well, we find it very useful.  I think there is no need
to prolong this part of the conversation; I think
everyone here is a pro and can understand the
plusses and minuses.

-- Dan

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mailman.common-lisp.net/pipermail/pro/attachments/20110125/cf77bb0f/attachment.html>


More information about the pro mailing list