microsoft / microsoft/calculator

Support Reverse Polish Notation (RPN)

Open
#128 29 comments 63 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Enhancement help wanted needs spec Pri: 2
Dominant language
C#
Stars
31.1k
Forks
5.8k
PR merge metrics
No merged PRs in 30d

Description

Problem Statement

Reverse Polish Notation / RPN / Postfix mode is an alternate calculator entry mode that is very powerful (leveraging a stack does this!) and should be simple enough to implement.

This behaviour can be seen in physical HP scientific calculators, or the calc mode in Emacs.

image

Evidence or User Insights

It's a simple addition with minimal overhead that would please some potential users that right now need to seek other solutions.

Goals

Users can toggle an RPN mode of entry
Low-Fidelity Concept

Simple psuedocode:

#! python3

# Or a function list, or something to check if input is "function" or "input"
functionMap = { 
    "+": lambda x, y: x + y,
    # ....
    "mod": lambda x, y: x % y
}

stack = []
while True:
    userInput = getInput()
    # If it's not a function, add it to the stack
    if userInput not in functionMap.keys():
        stack.append(userInput)
    else:
        # Evaluate the last two items on the stack.
        # In real usage, the last stack item is often implicit, eg, 
        # 27 [enter] 3 / 
        # rather than
        # 27 [enter] 3 [enter] /
        b = stack.pop()
        a = stack.pop()
        stack.append(functionMap[userInput](a, b))

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with docs/NewFeatureProcess.md for the project's feature-pitch expectations, then review the RPN description and pseudocode in this issue. Done should mean users can toggle an RPN entry mode and use stack-based operands and operators as described; the issue does not name implementation files or tests.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp
Domain
desktop
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.