[m-dev.] Here's an idea.
Tyson Richard DOWD
trd at students.cs.mu.oz.au
Tue Sep 9 16:07:09 AEST 1997
Fergus Henderson wrote:
> Tyson Richard DOWD, you wrote:
> > Fergus Henderson wrote:
> > >
> > > It would work OK if you use import_module rather than use_module,
> > > but then you have the problem that [1,2,3] is ambiguous.
> >
> > This probably isn't a huge problem, but it's not very nice.
>
> Hmm, I suspect it would probably break type inference in a lot of cases.
> And I think type inference is likely to save more keystrokes.
>
> However, I'm not really sure exactly how it would interact with
> type inference, maybe we should try it out and get some experience with
> it.
This could still be worthwhile. Perhaps it's worth adding a heterogenous
list type to the library (or to a library), and playing with some
different syntaxes.
Or we could throw it to the wolves (mercury-users, that is ;-)
> Well, for an extensible version, using a special little language inside the
> format string is a bit of a problem, because it is difficult to extend
> that language. So instead of
>
> printf("X = %6.3f, S = %20s\n", [f(X), s(S)])
>
> you might write something like
>
> printf("X = %%, S = %%", [f(6, 3, X), s(20, S)])
>
> If most of your format strings contain formatting information like "%6.3f",
> then special support for heterogenous lists wouldn't help much.
>
> On the other hand, thinking about it a bit more it is true that most format
> strings don't contain that sort of formatting information.
> So I guess it is worthwhile trying to optimize the common case.
>
Also, C style formatting strings are pretty important, as almost every
programmer is familiar with them. You would need to provide something
_significantly_ better to get people to change (I think in this case,
"worse is better" is appropriate).
>
> Hmm. How's this for another idea:
>
> printf([X, S |+ "X = %%, S = %%"])
>
> This one avoids the problem with [1,2,3] being ambiguous.
> To make it work, you just need to overload ./2 and +/1:
>
> :- type format_list.
> :- func '.'(T, format_list) = format_list.
> :- func '+'(string) = format_list.
>
> The '|+' is kinda baroque syntax, though.
This isn't bad at all - it's certainly pretty easy to use, and easy to
implement.
(I assume you mean for this to be actually implemented as a list(univ)).
--
Tyson Dowd # Another great idea from the
# people who brought you
trd at .cs.mu.oz.au # Beer Milkshakes!
http://www.cs.mu.oz.au/~trd # Confidence --- Red Dwarf
More information about the developers
mailing list