Arc Forumnew | comments | leaders | submitlogin
1 point by Pauan 4911 days ago | link | parent

I just added in some more stuff. First off, you can now write your own macros. So for instance, let's say you had this file:

  (mac w/element (n x . body)
    `(let ,n (document.createElement ,x)
       (do ,@body)
       ,n))

  (mac w/div (x . body)
    `(w/element ,x "div" ,@body))

  (w/div x
    (x.appendChild
      (w/div x
        (x.setAttribute "foo" "bar"))))
It would then compile into this JavaScript:

  (function (x) {
      x.appendChild((function (x) {
          x.setAttribute("foo", "bar");
          return x;
      })(document.createElement("div")));
      return x;
  })(document.createElement("div"))
Notice how "w/div" and "w/element" don't appear at all in the JS: they're expanded away by the compiler. In case you're curious, the above code generates the following DOM structure:

  <div>
    <div foo="bar"></div>
  </div>
---

Another nifty change I did was add in a couple optimizations for common cases. For instance, before, if you used this:

  (def foo ()
    (let a 50
      (+ a 10)))
It would compile into this:

  var foo = (function () {
      return (function (a) {
          return (a + 10);
      })(50);
  });
This is correct in all circumstances, but it's inefficient in the very common circumstance of a let inside a function. So I optimized it so it now compiles into this:

  var foo = (function () {
      var a = 50;
      return (a + 10);
  });
Aside from the superfluous parentheses, that code is just as fast as if you had manually wrote it! I also optimized `do` within functions:

  (def foo ()
    (do a
        b
        c))
Used to be:

  var foo = (function () {
      return (function ()
          a;
          b;
          return c;
      })();
  });
But now it's:

  var foo = (function () {
      a;
      b;
      return c;
  });
---

Lastly, I added in an "arc2js" function, that lets you convert an entire file from Arc to JS:

  (arc2js "/path/to/foo.arc" "/path/to/foo.js")