You are browsing as a guest. Sign up (or log in) to start making projects!

Open comments for this post

4h 38m 42s logged

Devlog 5 — Expressions, Memory and a Real “Calculator Feel”


What I learned:

  • How to evaluate user input dynamically using Function() (and why it needs to be handled carefully)
  • How to replace parts of user input using regex.
  • How to structure commands when the number of arguments isn’t always fixed (min/max validation)
  • How small UX details (like colors using chalk) make a big difference in usability
  • How to maintain state across a REPL session
  • How to design a fallback system where unknown commands are treated as expressions

Biggest struggle:

This one was definitely more complex than the previous days.

The hardest part was adding expression evaluation.
Using something like Function() to evaluate user input felt powerful but also risky and confusing at first. Making sure it doesn’t break on invalid input and handling errors properly took some time. Another tricky part was implementing a feature (ans) that lets you reuse the previous result in new calculations. Ensuring it worked consistently across both commands and expressions required careful handling of user input. Replacing it correctly in user input without breaking other words or expressions required using regex carefully.

Also, as the number of commands grew, validation started getting messy. Switching to a min/max argument system helped but it took a bit of thinking to get right. This stage felt less like “just coding” and more like designing how the calculator should behave.


Current features:

  • Full REPL-based interactive CLI

  • Support for both commands and direct expressions:

    add 2 3
    2 + 3 * 4
    
  • ans keyword to reuse the previous result

  • Expanded math operations:

    • Trigonometry (sin, cos, tan)
    • Logarithms (ln, log)
    • Factorial (fact)
    • Rounding (round, ceil, floor)
    • Absolute value (abs)
  • Improved validation with flexible argument handling (min/max support)

  • Persistent history with timestamps

  • Optional history limit (history n)

  • Colored and structured output using chalk

  • Better error handling for invalid commands and expressions


Next steps:

  • Improve expression parsing (support more complex cases safely)
  • Possibly replace Function() with a safer custom parser
  • Add command chaining or multi-step calculations
  • Improve UI further (custom prompt, better formatting)
  • Maybe create a simple web version for easier demo access

Reflection:

This version feels like a big step forward. Before, the calculator was command-based and structured. Now it feels much more natural and flexible, especially with expressions and the ans feature. It’s starting to behave like an actual calculator instead of just a program that runs specific commands.


At the same time, the complexity is definitely increasing. It’s getting harder to manage everything cleanly which makes me realize how important structure and planning are as projects grow. It’s not perfect but it finally feels like something I could actually use. Not just something I built to learn.

0
1

Comments 0

No comments yet. Be the first!