title: How do I write more advanced functions/objects in KDB?
body: <p>I'm trying to write something that'll fit a linear regression on <code>x;y</code> as below.</p>
  <pre><code>fit: {
    coef: enlist[y] lsq flip[x];
    intercept: avg y;
    rSquared: sum raze[(intercept + (raze coef mmu flip[x]) - y) xexp 2];
    0&quot;intercept&quot;;
    0&quot;coef&quot;; }
  fit[x;y]
  </code></pre>
  <p>The issue I'm having is:</p>
  <ul>
  <li><p>How can I output <code>intercept</code>, <code>coef</code> and <code>rSquared</code> into some kind of single structured data format that I can use in my <code>predict</code> function (not shown). I tried to do</p>
  <p>`intercept`coef!(intercept coef)</p>
  </li>
  </ul>
  <p>but it wouldn't allow it owing to the resultant dictionary not being square.</p>
  <p>What's the right way to handle this in KDB?</p>