weird, I was looking for this exact concept (except for Javascript code) literally right before checking whats new on HN.
This looks great. Its super useful for when you need to perform calculations and also keep a saved record of it (like structural engineering calcs)