[M3devel] efficient "safe" Modula-3?

Henning Thielemann lemming at henning-thielemann.de
Wed Jan 2 12:28:18 CET 2008


On Tue, 1 Jan 2008, Jay wrote:

> How can I write this in idiomatic Modula-3:

>     date : Date.T    Fmt.FN(                                 (* heap alloc *)        "%04s-%02s-%02s %02s:%02s:%02s",        ARRAY OF TEXT{                      (* heap alloc? easily avoided, but just over the limit *)            Fmt.Int(date.year),             (* heap alloc *)            Fmt.Int(ORD(date.month) + 1),   (* heap alloc *)            Fmt.Int(date.day),              (* heap alloc *)            Fmt.Int(date.hour),             (* heap alloc *)            Fmt.Int(date.minute),           (* heap alloc *)            Fmt.Int(date.second)            (* heap alloc *)            })));

 I think that this solution is the most elegant one can do. It's still not
entirely safe, because the number of arguments may not match the number of
placeholders in the format string. GCC checks this for printf and friends,
but I'm afraid this is restricted to the standard format strings.
 Even more safe, but maybe less readable and less efficient is
  Fmt.Int(date.year) & "-" & Fmt.Int(date.month+1) & "-" ...

 People have even invented dependently typed languages in order to get
functions like printf typed in a statically safe manner:
  http://en.wikipedia.org/wiki/Cayenne_(programming_language)



More information about the M3devel mailing list