An example repository to demonstrate collaboration on projects with GitHub pull requests.
This calculator aims to implement a python-based compiler for a Scheme-like syntax for simple arithmetic operations. This Scheme-like syntax uses parentheses and prefix notation to indicate functional operations. For example:
Operation | Python Syntax | Scheme-like Syntax |
---|---|---|
addition | a + b |
(+ a b) |
subtraction | a - b |
(- a b) |
multiplication | a * b |
(* a b) |
division | a / b |
(/ a b) |
Further, operations can be nested as follows:
Python Syntax | Scheme-like Syntax |
---|---|
(a + b) * c |
(* (+ a b) c) |
I have already implemented the addition operation, and it is up to you to implement one of the other operations and contribute to this project. Here's how:
-
First fork this repository to your own GitHub account online.
-
Clone that forked repository to your computer.
-
Create and check out a new branch for the operation you choose to implement.
-
Make edits to the
operations.py
file.# SUBTRACTION Operation Entry ############################## # Desired Functionality: (- a b) = {{1. YOUR OPERATION IMPLEMENTATION}} def subtract(a, b): return {{2. YOUR OPERATION IMPLEMENTATION}} sym_dict['-'] = ('{{3. IMPLEMENTATION FUNCTION}}', '{{4. YOUR NAME}}') ############################################################
- Add comments to indicate how your implementation works.
- Add the implementation in the return statement
- Add the implementation function name (e.g. subtract).
- Add your name as the author.
-
Commit those edits and push them back up to your GitHub repository.
-
Create a Pull Request to merge these changes into the original repository.
See Exercise 2 in my Git and GitHub Tutorial for more information.
When you think your implementation is working take the following steps to test it
- Navigate to the repository folder and start up a python3 console.
- Type the following at the python prompt:
from calculator import compute
- To test the addition operation (already implemented) type:
You should then see:
compute('(+ 1 3)')
>>> compute('(+ 1 3)') Thanks for the "+" function, Corban S.! (+ 1 3) = 4
- Now test your own implementation and nested implementations (as demonstrated in the second table above).