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

Re: Extending format strings.



"Chris Double" <chris@double.co.nz> wrote in message
wkk8a7lnxh.fsf@double.co.nz">news:wkk8a7lnxh.fsf@double.co.nz...
>> 2) How do I add print-message methods when it looks like
>> print-message is sealed?

> In Functional Developer betas, print-message was sealed. I raised this
> as a bug and I'm pretty sure they fixed this in the release. Are you
> using FD 2.0?

I am.  FD 2.0 SP1, in fact.  I was relying on the documentation which, in
retrospect, given a long and proud history of not documenting anything
properly in our collective industry, was likely a mistake.  :-)

Thanks for the tips.  It's time to go dumpster diving in the code.  :-)

...

OK, here's what's in format.dylan.  The generic for print-message is:

    define open generic print-message
        (object :: <object>, stream :: <stream>)
     => ();

That looks like good news to me.  There are some implementations of this, of
course:

    define /* sealed */ method print-message
        (object :: <object>, stream :: <stream>)
     => ();

    define /* sealed */ method print-message
        (object :: <condition>, stream :: <stream>)
     => ();

    define sealed method print-message
        (object :: <string>, stream :: <stream>)
     => ();

    define sealed method print-message
        (object :: <character>, stream :: <stream>)
     => ();

    define sealed method print-message
        (object :: <symbol>, stream :: <stream>)
     => ();

I'm going to have to brush up on the sealing protocol, but it looks to me
like I can't extend print-message for any subclasses of <string>,
<character> or <symbol> from the above code.  I can, however, extend
print-message for any subclass of <object> or <condition> that isn't sealed
by the above bits.  Am I reading that right?

(Have I mentioned yet how much I love Dylan?  I opened up a library I've
never seen before in my life and that I wasn't sure what to look for and
figured out exactly how format's logic works on the first try.  I tend to
shudder at the prospect of opening up *any* C++ library I didn't write
myself....)

Of course the reason why I avoid looking into libraries is beginning to
haunt me already.  I'm looking at the internal implementation function
do-dispatch and seeing exactly how I could hand-hack a float format dispatch
character....  :-)

>> 4) Another candidate seems to be to use %= and print-object instead.
>> Is this correct or is print-object used for something completely
>> different?

> I have a custom <money> class and to print it I specialize
> print-object and use %= in format to print it. So maybe this is an
> approach. Not sure if you specialize print-object for the float
> classes though as they might already be specialized and sealed.

I'm a little fuzzy on the distinction between %= and %S.  When would I use
which one?  Why?





Follow-Ups: References: