[m-users.] About append(out, in, in) for lists and strings

Zoltan Somogyi zoltan.somogyi at runbox.com
Sun Feb 5 08:08:51 AEDT 2017



On Fri, 3 Feb 2017 14:56:06 +0800, Xin Wang <dram.wang at gmail.com> wrote:

> In Mercury reference[1] there is an example shows that a seperate
> definition can be used to make `append(out, in, in)` more efficient.
> 
> But `libraray/list.m` and `library/string.m` both do not define
> `append(out, in, in)` mode, instead `remove_suffix/3`is recommended to be
> used, because of determinism and efficiency issues. That seems to
> contradict with the reference.

The reference manual is using append(out, in, in) as an *example*,
showing how it *could* be implemented. It does *not* say that this
implementation is actually used in the Mercury standard library,
so there is no contradiction. The library's list.remove_suffix predicate
uses the same code as the example code for append(out, in, in)
in the manual, so the only difference between the example and
reality is the name attached to the code. The reason for the difference
is that append is a frequently used predicate, and it is easier for
intermodule optimization to handle it if its definition does not use
different code for different modes.

Zoltan.




More information about the users mailing list