Ask ICP AI solved my record extension syntax with more than one extension question!

TLDR: Ask ICP AI is awesome.

I wasn’t able to find an example of how to use the with keyword with more than one override and was fumbling in finding the syntax, so I asked the ICP Docs AI.

It gave me this response

{ <exp1> and ... <expn> with <exp-field1>; ... <exp_fieldn>; }

I realize this might be a bit technical for some, so a simple example would look like:

let myRecord = {
  a = 1;
  b = 2;
  c = 3;
};

let myExtendedRecord = {
  myRecord with
    d = 4;
    e = 5;
    ...
};

If you have more than one record it could look like

let r1 = {
  a = 1;
  b = 2;
  c = 3;
};

let r2 = {
  c = 3;
  d = 4;
};

let myExtendedRecord = {
  r1 and r2 with
    // since c appears in both r1 and r2, need to specify what c is
    c = r2.c;
    e = 5;
    ...
};
4 Likes

Cool stuff! Thanks for sharing!

1 Like