[m-users.] ROTD-2024-06-28 and use of new format_call pragma

Sean Charles (emacstheviking) objitsu at gmail.com
Sat Jun 29 19:56:15 AEST 2024


Hi,

First of all, a huge big massive thank you to everybody involved in that ROTD, I read the entire release notes over breakfast, what a fantastic amount of work and effort has been expended over it. Very much appreciated here.  Again, thank you.

I noticed the format_call pragma, and that is a welcome addition as I have a simple ANSI output module that makes it easy to add emojis and colour to my output. I once had a subtle bug in it and since that day have always used the compiler option --warn-unknown-format-calls but this new pragma, well!

My export section then is:

:- pragma format_call(pred(error/4), format_string_values(1, 2)).
:- pragma format_call(func(format/2), format_string_values(1, 2)).
:- pragma format_call(pred(format/4), format_string_values(1, 2)).

:- pred error(string::in, list(poly_type)::in, io::di, io::uo) is det.
:- func format(string::in, list(poly_type)::in) = (string::out) is det.
:- pred format(string::in, list(poly_type)::in, io::di, io::uo) is det.

:- func chromakey(string::in) = (string::out) is det.

The function chromakey/1 is the source of my problem because it is used by all of the above to actually map the source format string into the final format string, and thus, when we look at the implementation code:

format(Format, Args, !IO) :- format_to(io.stdout_stream, Format, Args, !IO).
error(Format, Args, !IO) :- format_to(io.stderr_stream, Format, Args, !IO).

:- pred format_to(output_stream::in, string::in, list(poly_type)::in, io::di, io::uo) is det.
:- pragma format_call(pred(format_to/5), format_string_values(2, 3)).

format_to(Stream, Format, Args, !IO) :-
[52] io.format(Stream, chromakey(Format), Args, !IO).

[67] format(Format, Args) = string.format(chromakey(Format), Args).

The errors I get are:

aio.m:052: Error: unknown format string in call to predicate `io.format'/5.
aio.m:052: Error: unknown list of values to be formatted in call to predicate
aio.m:052:   `io.format'/5.
aio.m:067: Error: unknown format string in call to function `string.format'/2.
aio.m:067: Error: unknown list of values to be formatted in call to function
aio.m:067:   `string.format'/2.
** Error making `Mercury/cs/aio.c'.

Am I stuck with this error in these two places or is there someway I can rearrange the code?
Thanks,
Sean.



-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mercurylang.org/archives/users/attachments/20240629/8987cd74/attachment.html>


More information about the users mailing list