Coconut is a functional programming language that compiles to Python. Since all valid Python is valid Coconut, using Coconut will only extend and enhance what you're already capable of in Python.
For my software development class, our team develop an online interpreter for Coconut programming language using React, Flask, and Amazon Lambda. Our application supports many following features.
- Code Editor: The code editor, which is on the left side of the webpage, is where the user types in their Coconut code. The editor has line numbers and Coconut-specific syntax highlighting.
- Compilation Settings: Clicking the settings gear will display a settings drawer. From within the drawer, the user can select which version of Python the Coconut code will compile to. By default, the latest version of Python 3 is selected.
- Saving to a Coconut File: Clicking the save icon will download the contents of the code editor into a Coconut file called
coconut.coco
.
- Code Execution: Clicking
RUN
or using the keyboard shortcutCtrl + Enter
for Windows or⌘ + Enter
for Mac will compile and execute the program.
- Showing the Compiled Python: Checking the box labeled
PYTHON
will replace the output with the compiled Python, which is the output of the Coconut compiler. The Python code will be displayed using Python syntax highlighting.
- Code Execution Output: The code execution output is on the right side of the webpage.
- Traceback Highlighting: If an error came from the Coconut compiler, the offending Coconut line will be highlighted in red in the code editor. If an error occurred at runtime, then the offending line will be highlighted in red in the Python code, if the Python checkbox is checked:
Figure 1: Converting a Coconut code to Python code
Figure 2: Executing a Coconut code
For more details, please see our team’s final report here.
Last updated: Jan 18, 2022