A programming language that only uses emojis as syntax.
Project description
๐ spamoji
A programming language that only uses emojis as syntax and encourages writing spaghetti code.
๐ Example
๐๏ธ A function to calculate factorial
โ๏ธ ๐ขโ๐ซธ๐ฐ๐ซท
๐ ๐ ๐ซด 1
๐ ๐ฐ ๐ค 1
๐ ๐ซด ๐ โ๏ธ ๐ฐ
๐ฐ ๐ซด ๐ฐ โ 1
โฉ๏ธ ๐
๐ญ๐ซธ๐คEnter a number to calculate the factorial: ๐ค๐ซท
๐ ๐ ๐ซด ๐ข๐ซธโจ๏ธโ๐ซท
๐ค ๐ ๐ฐ โ ๏ธ
๐
๐ฌ๐ซธ๐คInvalid input.๐ค๐ซท
๐
๐ฌ๐ซธ๐คThe factorial of ๐ค โ ๐ โ ๐ค is ๐ค โ ๐ขโ๐ซธ๐๐ซท๐ซท
๐ญ What's this all about?
This language is a learning project. Since it lacks many features of a typical programming language, it is not recommended for production use. If this experiment is successful, I might move on and begin working on Esore, a more serious language I've been designing in the past 2 years.
๐ฆ Installation
To install the spamoji interpreter, you will need to have Python 3.10 or higher installed on your machine. You can download Python from the official website.
Once you have Python installed, you can install the spamoji interpreter using pip:
pip install spamoji
๐ Usage
To run a spamoji program, you will need to use the spamoji interpreter.
You can provide a spamoji file (with the .๐ extension) as input to run it. For example:
spamoji my_program.๐
If no file is supplied, the interactive REPL will start, which allows to enter and evaluate expressions directly.
If the above command doesn't work, you can also run the interpreter using Python's -m flag:
python -m spamoji my_program.๐
๐ Syntax
[!IMPORTANT] The emojis used in the syntax were entered on a Windows machine. While they should work on other platforms, some emojis might not render correctly or might be replaced with different emojis. If you encounter any issues, please try copying and pasting the emojis from this documentation into your code.
โ Statements
Each line of code starts with an emoji that indicates the type of statement. Each statement is followed by the relevant information, separated by spaces. Statements include:
- ๐๏ธ Comment: Text in this line will be ignored
- ๐ Variable declaration: Followed by the variable assignment
- ๐ค If statement: Followed by the condition
- ๐ If true block
- ๐ Else block
- ๐ Loop: Followed by the loop variable and condition
- โ Break statement: Used to exit the loop
- โคด๏ธ Continue statement: Used to skip to the next iteration of the loop
- โ๏ธ Function definition: Followed by the function name and parameters
- โฉ๏ธ Return statement: Followed by the value to return
- ๐ Class definition: Followed by the class name and members
- ๐งฉ Import statement: Followed by a file name, it loads that file as a module
Statements starting with any other character are going to be considered as expressions and be evaluated directly.
Some statements can be nested, such as if statements and loops. Indentation is used to indicate the scope of these statements. Indented blocks are considered part of the previous statement until the indentation level decreases.
๐ง Expressions
An expression is a piece of code that produces a value and/or executes actions. Function calls, variables, and operations are all expressions and can be used on their own or inside of other expressions or statements.
๐ซธ and ๐ซท can be used to group expressions and control the order of evaluation.
๐ฃ Operators
The language supports basic operators for logical and arithmetic operations. These can be used between two values to perform calculations.
- โ: Addition
- โ: Subtraction or negation
- โ๏ธ: Multiplication
- โ: Division
- ๐ฐ: Equal
- ๐: Not equal
- ๐ค: Greater than
- ๐ค: Less than
- ๐ค๐ฐ: Greater than or equal
- ๐ค๐ฐ: Less than or equal
- ๐ค: Logical AND
- ๐คฒ: Logical OR
- ๐ : Logical NOT
Operators can also be combined with variable assignment to perform an operation and assign the result to the variable in one step. Supported compound forms are ๐ซดโ, ๐ซดโ, ๐ซดโ๏ธ, and ๐ซดโ:
๐ x ๐ซด 5
x ๐ซดโ 3 ๐๏ธ -> x is 8 now
๐ค Strings
Strings are sequences of characters enclosed in ๐ค on each side. They can contain any characters, including emojis. Strings can be used in variable assignments, printed to the console, and concatenated using the โ operator.
To use the ๐ค character in a string, write ๐ง๐ค instead. To use the ๐ง character, write ๐ง๐ง instead.
๐ค Conditions
The ๐ค statement allows to run different code depending on a certain condition:
๐ค condition
๐
this line runs if condition is true
๐
this line runs if condition is false
Both the ๐ and ๐ branches are optional. If a branch has only 1 statement, it can be written in the same line as the ๐/๐. Conditions can also be nested inside of other conditions:
๐ค condition 1
๐
this line runs if condition 1 is true
๐ ๐ค condition 2
๐ this line runs if condition 1 is false and condition 2 is true
Conditions can also be used inside of other expressions:
๐ซธ๐ค condition ๐ a ๐ b ๐ซท
Here, if condition is true, a will be returned, otherwise b. It is important to note that inline conditions like this require both a ๐ and a ๐, otherwise an error will be raised.
๐ Loops
The ๐ statement can be used to run code repeatedly while a certain condition is true.
๐ condition
this code runs while condition is true
Additionally, the โ and โคด๏ธ statements can be used to control the loop execution. โ stops the loop immediately, regardless of the condition. โคด๏ธ jumps back to the beginning of the loop.
๐ Variables
Variables are declared using the ๐ emoji, followed by the variable assignment expression. An assignment expression starts with the variable name, followed by ๐ซด and a value. For example:
๐ x ๐ซด 1
The declaration and assignment can also be on separate lines. Any unassigned variables will start with value ๐ซฅ.
Variable names can be any combination of letters, numbers, and emojis, but must start with a letter or emoji and cannot contain statement characters.
Variables declared inside of a block are only accessible inside of that block and any nested blocks.
โ๏ธ Functions
Functions are defined using the โ๏ธ emoji, followed by the function name and parameters. The function body is indented and can contain any valid statements. The function can return a value using the โฉ๏ธ emoji.
Functions can be called by using their name followed by the arguments, separated by ๐ธ, between ๐ซธ and ๐ซท. Functions with no arguments can also be called with the โ emoji.
Here's an example of a function definition and call:
โ๏ธ greetAndAsk ๐ซธfirstName ๐ธ lastName๐ซท
๐ฌ๐ซธ๐คHello, ๐ค โ firstName โ ๐ค ๐ค โ lastName โ ๐ค ! Please enter a number...๐ค๐ซท
โฉ๏ธ โจ๏ธโ ๐๏ธ Return the user input
๐ x ๐ซด greetAndAsk๐ซธ๐คJohn๐ค๐ธ๐คDoe๐ค๐ซท
๐ฌ๐ซธ๐คYou entered: ๐ค โ x๐ซท
In some cases, functions can be called without parentheses:
๐ฌ ๐คHello!๐ค
๐ฌ 1 โ 2
๐ Classes
Classes are defined using the ๐ emoji. The class body is indented and can contain any valid statements. Any function statements directly in the class body will be added to the class as methods.
Class instances are created by calling the class name, like a function. When an instance is created, the special method โจ will be called.
Inside of methods, the ๐ค emoji can be used to refer to the current instance.
๐ MyClass
โ๏ธ โจ๐ซธname๐ซท
๐ค๐name ๐ซด name
โ๏ธ greetโ
๐ฌ๐ซธ๐คHello, I am ๐ค โ ๐ค๐name โ ๐ค!๐ค๐ซท
Classes can inherit methods from other classes (superclasses). Superclass names can be written between ๐ซธ and ๐ซท, separated by ๐ธ, after the class name in the definition. The first superclass can be accessed with the ๐ emoji in methods.
๐ MyClass ๐ซธsuperclass1๐ธsuperclass2๐ซท
โ๏ธ superclassNameโ
โฉ๏ธ ๐๐name
๐งฉ Imports
The ๐งฉ emoji can be used to include code from another file in the current code:
๐งฉ robots.๐
๐ bot ๐ซด robots๐Robot๐ซธname๐ซท
๐ Built-ins
The language includes several built-in functions and values for common operations.
๐ฌ Built-in functions
- ๐ฌ๐ซธstring๐ซท: Print string to a new line in the console
- ๐ญ๐ซธstring๐ซท: Print string to the console without creating a new line
- โจ๏ธโ: Get user input from the console
- โณ๐ซธtime๐ซท: Wait for a specified number of seconds
- ๐ข๐ซธvalue๐ซท: Convert value to a number, return โ ๏ธ if the conversion fails
- ๐ฒ๐ซธmin๐ธmax๐ซท: Get a random integer from min to max
- ๐ฐ๏ธโ: Get time since epoch in seconds
- ๐โ: Stop the program
โ Built-in values
- โ : true
- โ: false
- ๐ซฅ: unassigned/null/no value
- โ ๏ธ: error/invalid value
๐ Python interoperability
โก๏ธ Inline evaluation
The ๐ function allows to directly evaluate Python expressions within Spamoji code. The results of these evaluations can be stored in variables and used in Spamoji. For example, the following code prints the modulo of x and y:
๐ x ๐ซด 10
๐ y ๐ซด 2
๐ z ๐ซด ๐๐ซธ๐ค๐ค โ x โ ๐ค%๐ค โ y โ ๐ค๐ซท
๐ฌ๐ซธz๐ซท
๐ค Exporting functions from Python
To make a Python function available in Spamoji, you can use the spamoji_function decorator. This decorator takes an emoji as an argument, which will be used to call the function in Spamoji code. For example, the following Python function can be called in Spamoji using the ๐ emoji:
import math
from spamoji import spamoji_function
@spamoji_function("๐")
def sine(x):
return math.sin(x)
๐ฅ Importing Python functions
The ๐๐งฉ function can be used to import functions from Python files into a Spamoji program. For example:
๐๐งฉ๐ซธ๐คexamples/sine.py๐ค๐ซท
๐ฌ๐ซธ๐คThe sine of 3 is: ๐ค โ ๐๐ซธ3๐ซท๐ซท
๐ซ Credits
Thanks to Robert Nystrom for his book "Crafting Interpreters" which inspired the design of this language and provided guidance on how to implement it.
Also thanks to Hack Club for providing a supportive community and motivating me to work on this project.
This documentation was entirely written by hand. AI tools were used for assistance while writing the interpreter.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file spamoji-0.4.0.tar.gz.
File metadata
- Download URL: spamoji-0.4.0.tar.gz
- Upload date:
- Size: 28.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f3e02fe47fdf49a48bfb92ac965ca405ab37d26265a62aed8a1fd343707ad9b7
|
|
| MD5 |
ab2289bc905fe717123410f0447f5c3f
|
|
| BLAKE2b-256 |
25117424a5369186d59b5c90e4afb8ae3233a5edefa8a8624a724ca6c3f8bda7
|
Provenance
The following attestation bundles were made for spamoji-0.4.0.tar.gz:
Publisher:
publish.yml on iqnite/spamoji
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
spamoji-0.4.0.tar.gz -
Subject digest:
f3e02fe47fdf49a48bfb92ac965ca405ab37d26265a62aed8a1fd343707ad9b7 - Sigstore transparency entry: 1959310601
- Sigstore integration time:
-
Permalink:
iqnite/spamoji@eef5003486bf0c43201256606745644fd7c644f5 -
Branch / Tag:
refs/tags/v0.4.0 - Owner: https://github.com/iqnite
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@eef5003486bf0c43201256606745644fd7c644f5 -
Trigger Event:
push
-
Statement type:
File details
Details for the file spamoji-0.4.0-py3-none-any.whl.
File metadata
- Download URL: spamoji-0.4.0-py3-none-any.whl
- Upload date:
- Size: 27.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4610e1dc601893a819248b97613daf8ec6f5c23bbfc9285e2d4a53247b8b23f7
|
|
| MD5 |
019be7dc038061c65af5ee55ce2c42b6
|
|
| BLAKE2b-256 |
e44d0b7f3dea66078ee411985ed05bb313e32ea19e2ea3bdc3d25244bb25ac48
|
Provenance
The following attestation bundles were made for spamoji-0.4.0-py3-none-any.whl:
Publisher:
publish.yml on iqnite/spamoji
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
spamoji-0.4.0-py3-none-any.whl -
Subject digest:
4610e1dc601893a819248b97613daf8ec6f5c23bbfc9285e2d4a53247b8b23f7 - Sigstore transparency entry: 1959310661
- Sigstore integration time:
-
Permalink:
iqnite/spamoji@eef5003486bf0c43201256606745644fd7c644f5 -
Branch / Tag:
refs/tags/v0.4.0 - Owner: https://github.com/iqnite
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@eef5003486bf0c43201256606745644fd7c644f5 -
Trigger Event:
push
-
Statement type: