Explore + Share Site

Steadfast Update II - Rewriting ASTs - Noteflakes

“So, if Prism nodes are immutable, how can we rewrite them? Basically, Prism lets us create a copy of a given node, with specific attributes assigned new values:”

Jump to Highlight ↗
📖 Curated Deep Read Preview 219 words · ~2 min read

Steadfast is a new Ruby project that aims to provide a new way to dynamically generate Ruby code at runtime by synthesizing and manipulating ASTs, as an alternative to the common technique of calling eval with a dynamically generated string containing Ruby source code.

In the last Steadfast update I discussed the foundations of the project, its general API design, and my work on implementing the basic capacity of turning ASTs back to source code (using Steadfast.to_source), as well as providing some facilities for translating backtrace locations for code derived from AST that were composed of pieces of code from different locations.

Over the last few days, I’ve concentrated on implementing the ability to transform an existing AST by replacing specific nodes therein. Previously, I called this “mutating” an AST, but actually I realized this term might be confusing, since Prism ASTs are inherently immutable, that is, they cannot be modified. Instead, you need to create a copy of an AST node with the requisite changes, so using the verb “mutate” is in fact incorrect. So henceforth I’ll use the term “rewrite” instead, which seems more fitting, since we’re basically taking existing code and rewriting it.

Now, there are some interesting nuances to this, because Prism nodes basically have three different kinds of attributes:

Continue reading the full piece on noteflakes.com ↗
Quick Use-Case Tags (tap to vote)
Visit Website ↗

📝 Your Private Notes & Highlights 🔒 Only visible to you

Log in or create a free account to keep private highlights and personal notes on your stored picks.

Creator Trophy & Press Kit

Featured on Storesso

Are you the creator of noteflakes.com? Share your verified feature badge on your website, or export a custom 4:5 editorial social card for Instagram and X.

Verified Website Badge
Featured on Storesso
Claim Resource →
4:5 Social Studio

Generate a 1080×1350 vertical high-res feature card tailored for social sharing.

Instagram & X Feature Card

Export a polished, high-resolution 4:5 editorial graphic displaying your verified inclusion in the Storesso Discovery Index. Perfect for launch threads, founder updates, and newsletters.

Rendered at 1080×1350px (Retina ready) · No attribution watermark required.

Curated in These Public Collections

Stay & Explore Next Continue full collection: Minimal Web & Interface Gems →
Why We Picked This · @elena_design
Exceptional visual restraint, editorial typography, and thoughtful interaction craft.
lua for data representation - citrons.xyz
Next in This Trail →
lua for data representation - citrons.xyz
my major advocacy is that lua is a very good general purpose language.
The Strength of the Record
Also in Collection →
The Strength of the Record
The computer is a curious gadget. It is one of few human inventions which can exist purely…
Discussion 0
🛡️ Safe comments: Text, Emojis & Reaction GIFs only (links & media URLs blocked)
✨ Author / Creator Quick-Reply No password required · Or Sign In