<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Tim Disney on Medium]]></title>
        <description><![CDATA[Stories by Tim Disney on Medium]]></description>
        <link>https://medium.com/@disnet?source=rss-894b301532dc------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*OjKQCo8cU9OHd669KJlstA.jpeg</url>
            <title>Stories by Tim Disney on Medium</title>
            <link>https://medium.com/@disnet?source=rss-894b301532dc------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Thu, 19 Nov 2026 06:36:30 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@disnet/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Sweetening syntactic abstractions]]></title>
            <link>https://medium.com/@disnet/sweetening-syntactic-abstractions-e615ab87f2dd?source=rss-894b301532dc------2</link>
            <guid isPermaLink="false">https://medium.com/p/e615ab87f2dd</guid>
            <category><![CDATA[compilers]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[programming]]></category>
            <dc:creator><![CDATA[Tim Disney]]></dc:creator>
            <pubDate>Mon, 10 Apr 2017 15:31:01 GMT</pubDate>
            <atom:updated>2017-04-10T15:31:01.112Z</atom:updated>
            <content:encoded><![CDATA[<p>Version 3.0 of <a href="http://sweetjs.org/">Sweet.js</a> has just been released! 🎉</p><p>To set expectations, keep in mind that I consider Sweet to still be an experiment and under heavy work. The version number is a reflection of semver (we’ve made breaking changes) not project maturity. Since the big <a href="https://medium.com/@disnet/announcing-sweet-js-1-0-e7f4f3e15594">redesign</a> last year tons of progress has been made, but I expect at least one or two more breaking changes (major version bumps) before things start to get baked and really ready to use. That said, if you are excited about the idea of true syntactic abstractions in JavaScript please dive in!</p><p>So what’s new?</p><h3>Custom Operators</h3><p>Custom operators are back! In the old pre-1.0 days we had the ability to define new operators with custom precedence and associativity but it was dropped in the redesign.</p><p>Operators are defined with the new operator keyword:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f75969e3b85756a6024b0462cdb695a4/href">https://medium.com/media/f75969e3b85756a6024b0462cdb695a4/href</a></iframe><p>That expands to:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/54125f8fe106f526e54372e285a9578f/href">https://medium.com/media/54125f8fe106f526e54372e285a9578f/href</a></iframe><p>The implementation of custom operators is pretty experimental at the moment but give it a whirl and let us know if you run into any problems. More details are in the <a href="http://sweetjs.org/doc/1.0/tutorial.html">tutorial</a>.</p><p>Note: the technical underpinnings for custom operators comes out of Jon Rafkind’s dissertation on the <a href="https://www.cs.utah.edu/%7Erafkind/papers/dissertation.pdf">Honu</a> language.</p><h3>Modules</h3><p>We’ve been steadily adding ES module support over the past few releases. The interaction between macros and modules is fairly complex so this is an ongoing process.</p><p>We currently have the ability to import macros from another module:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/cb88a1de731d1b986c155298607419f5/href">https://medium.com/media/cb88a1de731d1b986c155298607419f5/href</a></iframe><p>Note the use of the &#39;lang sweet.js&#39; directives. These directives are currently required in any module that uses macros. It allows the Sweet compiler to avoid needlessly expanding modules that don&#39;t contain any macros. At present the directive is “just” an optimization but soon we&#39;ll be using it for some pretty cool stuff.</p><p>You can now also import modules into compiletime code (macro definitions) by using the for syntax form of import:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/edcd9f6638cc3ddeab08fb8b1631200d/href">https://medium.com/media/edcd9f6638cc3ddeab08fb8b1631200d/href</a></iframe><p>We’re taking the Racket approach of dividing everything up into <em>phases</em>. Runtime syntax is in phase 0 and compiletime macro definitions are in phase 1. Importing for syntax allows you to phase shift your code around. Phases greater than phase 1 happen when you import for syntax a macro that uses another macro that was imported for syntax. This gives rise to an infinite “tower of phases” which sounds complicated but turns out to be pretty straightforward in practice.</p><p>Still to come are better support for implicit runtime imports, finer grain support for phases that let you import for a specific phase, and an equivalent to Racket’s begin-for-syntax.</p><p>Note: the technical underpinnings of modules and macros comes out of the Racket approach set forward by Matthew Flatt in his <a href="https://www.cs.utah.edu/plt/publications/macromod.pdf">“You want it <em>when</em>?”</a> paper.</p><h3>Readtables</h3><p>While macros allow you to extend how syntax is parsed, sometimes you also need to extend how source text is lexed. The lexing extension approach we are taking is called <em>readtables</em> and <a href="https://twitter.com/gabeijohnson">@gabejohnson</a> has been doing some amazing design and implementation work. Sweet now uses readtables internally and will soon be exposing them to users.</p><h3>Internals and helpers</h3><p>During expansion Sweet constructs several intermediate representations of syntax that can be manipulated and eventually turned into a <a href="http://shift-ast.org/">Shift AST</a>. The exact representation we want to use is under flux but unfortunately it is exposed to macro authors inside macro definitions. Exposing what should be internal details is bad so to move away from that Sweet now provides a helper library for macro authors:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9198441ea3ef6641ad97701ebda303d1/href">https://medium.com/media/9198441ea3ef6641ad97701ebda303d1/href</a></iframe><p>Macro authors should only use the helper library to inspect and manipulate syntax objects rather than rely on the current representation of syntax. Eventually we will document and freeze a intermediate syntax representation but until then just use the helpers.</p><h3>What’s next?</h3><p>The current plan is to get Sweet to a solid and stable place where we can start building declarative conveniences on top its foundation. In particular, the current macro definition syntax is intentionally low-level and not convenient to work in. We’ve got some <a href="https://github.com/sweet-js/sweet.js/issues/516">ideas</a> about what this might look like but first we’re going to make sure the base is solid.</p><p>If any of this excites you, please <a href="https://github.com/sweet-js/sweet.js">jump in</a>! We’d love to have you!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e615ab87f2dd" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Announcing Sweet.js 1.0]]></title>
            <link>https://medium.com/@disnet/announcing-sweet-js-1-0-e7f4f3e15594?source=rss-894b301532dc------2</link>
            <guid isPermaLink="false">https://medium.com/p/e7f4f3e15594</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[compilers]]></category>
            <dc:creator><![CDATA[Tim Disney]]></dc:creator>
            <pubDate>Mon, 28 Mar 2016 16:01:00 GMT</pubDate>
            <atom:updated>2016-03-28T16:01:00.865Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/225/1*7YyusuJOU-pva5Dz_KRh-Q.png" /></figure><p><a href="http://sweetjs.org/">Sweet.js</a>, the hygienic macro system for JavaScript, just got a shiny new release: the magical 1.0! 🎉</p><p>If you’ve been following the development of Sweet for a while you might have noticed a dearth of activity. Part of that was life (I recently finished grad school and started a new job) but part of that seeming lack of activity was actually a giant rewrite in progress.</p><p>Yes I know, <a href="http://www.joelonsoftware.com/articles/fog0000000069.html">that’s a thing you should never do</a>.</p><p>But I swear it made sense this time. The collection of bad decisions I made early in development had finally made forward progress all but impossible. And so, Sweet has been completely rewritten.</p><p>So what’s good about the rewrite? Lot’s of stuff, but two I want to call out specifically here.</p><p>First, a proper parser is now integrated in the expansion pipeline. Previously, Sweet had a half-baked pseudo-parser that kinda-sorta built up an AST during expansion and then immediately flattened it back to tokens to let our crazy fork of <a href="http://esprima.org/">esprima</a> build up a proper AST before doing codegen.</p><p>Yeah, totes reasonable.</p><p>This insane pipeline had tons of bugs especially related to proper ES2015 support.</p><p>Now we have a proper parser modeled after the <a href="http://shift-ast.org/parser.html">Shift Parser</a> and producing a <a href="https://github.com/shapesecurity/shift-spec">Shift AST</a> with Babel as an optional backend for great ES2015 support everywhere. It’s amazing.</p><p>Second, Sweet now has much more reasonable macro binding forms. Previously, you could define a macro in two ways, the recursive and non-recursive declaration forms:</p><pre>// recursive form<br>macro foo { /* ... */ }<br></pre><pre>// non-recursive form<br>let foo = macro { /* ... */ }</pre><p>The recursive form binds the macro name inside the macro definition while the non-recursive form does not. This was gross and confusing because standard let in ES2015 does not work like this at all. Now, Sweet uses “syntax” and “syntaxrec”:</p><pre>// non-recursive form<br>syntax foo = function (ctx) { /* ... */ }</pre><pre>// recursive form<br>syntaxrec foo = function (ctx) { /* ... */ }</pre><p>These are more symmetric and fit in better as a compiletime extension of the var/let/const binding forms of ES2015.</p><p>While all these changes are great, there are a few items from the pre-1.0 days that have not been re-implemented yet. Custom operators and infix macros in particular are not currently supported. However, the foundation provided by the rewrite will make adding these features back pretty straightforward so expect them to be available soon.</p><p>So should you dive in with the new Sweet? Well, to be honest it really depends on how risk averse you are. Since so much has changed with the rewrite there are bound to be bugs we still need to shake out. Maybe don’t go running Sweet over your production code just yet.</p><p>But if you’d like to help out by putting Sweet through its paces we would love to have you! The best way to get started is to familiarize yourself with all the new syntax by reading the <a href="http://sweetjs.org/doc/1.0/tutorial.html">tutorial</a>. If you’ve got questions or need help, head on over to <a href="https://gitter.im/mozilla/sweet.js">gitter</a> or #sweet.js on irc.mozilla.org.</p><p>Have fun sweetening your code!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e7f4f3e15594" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>