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

Re: Extending format strings.



Well, in GD, format calls do-dispatch which goes:

define function do-dispatch (char :: <byte-character>, stream :: <stream>, arg)
    => consumed-arg? :: <boolean>;
  select (char by \==)
    ('s'), ('S'), ('c'), ('C') =>
      print-message(arg, stream);
      #t;
    ('=') =>
      print(arg, stream);
      #t;
    ('d'), ('D') =>
      format-integer(arg, 10, stream);
      #t;
    ('b'), ('B') =>
      format-integer(arg, 2, stream);
      #t;
    ('o'), ('O') =>
      format-integer(arg, 8, stream);
      #t;
    ('x'), ('X') =>
      format-integer(arg, 16, stream);
      #t;
    ('m'), ('M') =>
      apply(arg, list(stream));
      #t;
    ('%') =>
      write-element(stream, '%');
      #f;
    otherwise =>
      error("Unknown format dispatch character, %c", char);
  end;
end function;

So you get better type checking but less easy extensibility. To combine the advantages of type-checking *and* extensibility, a method could be written that introspects on every method of the format-message GF to build the dispatch table (I think).
I don't know what FD does about type-checking, though.

- Rob.

On Tuesday, November 14, 2000, at 03:30 PM, Michael T. Richter wrote:

> How does %S give me type safety?  If I override print-message for <foo>, 
> <bar> and <booger>, I can still screw up by using the control string "%S %S 
> %S" and calling with (<foo>, <booger>, <bar>) instead of the expected 
> (<foo>, <bar>, <booger>).  And since there's a print-message for <object>, 
> it isn't even as if my not having a handler for a particular type will get 
> caught.  I'll just get irritating results instead.