[m-users.] Possiblt stupid list question....

Sean Charles (emacstheviking) objitsu at gmail.com
Wed Dec 22 03:42:49 AEDT 2021


Hi Zoltan,

I already had:

:- type rop
    --->    t(string)
    ;       tnl(string)
    ;       nl
    ;       tab(list(rop))
    ;       rops(list(rop)).

By adding a new type constructor, which I have done,

    ;       seq(string, list())

I now have a generalised way of outputting a sequence of terms separated by whataver is in the string value. I have created a mini-DSL of sorts that handles output formatting for me, for example, to output a general function call I compose this:

        Call = rops([
            t(FunctionName), t("("), seq(“, “, ArgsOut), t(")")
        ]),

and then I extended my mini language to handle a seq() and do the right thing getting me what I need.

Sean.


> On 21 Dec 2021, at 16:36, Zoltan Somogyi <zoltan.somogyi at runbox.com> wrote:
> 
> 
> 
> On Tue, 21 Dec 2021 16:21:06 +0000, "Sean Charles (emacstheviking)" <objitsu at gmail.com> wrote:
> 
>> If I have a list of strings I can use
>> 
>> 	string.join_list(Separator, Strings)
>> 
>> but if I have a list of things, and I want to separate them all with a list of another thing within the same type…?
>> 
>> I have a formatted output system, it encapsulates text in various type constructors
>> 
>> 	t(string)
>> 	tnl(string)
>> 	etc
>> 
>> so given a list
>> 
>> 	[ t(“arg1”), t(“arg2”) ]
>> 
>> how do I arrive at
>> 
>> 	[ t(“arg1”), t(“, “), t(“arg2”) ]
> 
> There is no predicate or function in the Mercury standard library
> that does this. On the other hand, there are several different versions
> of it in the error message formatting module of the compiler,
> error_util.m, that all do slightly different versions of this job.
> Some generate output such as "1, 2, 3" (just putting ", " between
> successive integers), while others treat the gap between the
> last pair of elements differently, generating output such as
> "1, 2 and 3".
> 
>> I COULD introduce a new type constructor called csv() but …. just asking for a friend etc.
> 
> I don't understand how a new type constructor would help.
> 
> Zoltan.
> 
> 
> 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mercurylang.org/archives/users/attachments/20211221/eefa3ae2/attachment-0001.html>


More information about the users mailing list