[m-dev.] a conditional field update operator

Zoltan Somogyi zoltan.somogyi at runbox.com
Wed Mar 8 16:57:56 AEDT 2017



On Wed, 8 Mar 2017 16:46:38 +1100, Michael Day <mikeday at yeslogic.com> wrote:
> Our CSS style processing code goes to some effort to avoid allocating 
> structures that haven't changed, but I think it wouldn't get any value 
> from this pointer equality test unless we canonicalised more values 
> deeper in the struct; currently we only canonicalise the whole thing at 
> the top level instead of each subfield.

I understand; there are several analogous situations in the Mercury compiler.

That is part of what I was trying to get at. As you say, conditional assignment
at any level of a data structure works only if you do it consistently at all the
levels below it; if you don't, then the new value of a field may be semantically
equal to the old value, but bitwise different from it. So to apply conditional
update to the transformation of a whole data structure, you have to do it
for the transformation of *every part*. This means that at the moment,
if you have code that does a traversal with unconditional update, your only
choices are

- replace every line where a part of the data structure is updated with *five*
  lines of code, greatly increasing the size of the code and making it harder
  to read, or

- give up on conditional update.

With the operator I propose, you would have a third option:

- replace every use of := with the new operator, leaving the code effectively
  the same size, and with the same readibility.

Zoltan.





More information about the developers mailing list