Reference
Soplang Language Reference
This reference manual describes the syntax and core functionality of the Soplang programming language. Use the navigation menu to find specific information.
Syntax
Variables and Data Types
Soplang is dynamically typed, which means you don't need to declare the type of a variable when you create it. The interpreter infers the type based on the value assigned.
# Basic variable assignment
name = "Soplang" # String
version = 1.2 # Float
is_new = True # Boolean
# Multiple assignment
x, y, z = 1, 2, 3
# Constants (by convention, use uppercase)
PI = 3.14159
MAX_USERS = 100
Primitive Data Types
int
- Integer numbersfloat
- Floating-point numbersstr
- Strings (text)bool
- Boolean values (True or False)None
- Represents the absence of a value
Collection Data Types
list
- Ordered, mutable collectiontuple
- Ordered, immutable collectiondict
- Key-value pairsset
- Unordered collection of unique elements
# List (mutable, ordered)
fruits = ["apple", "banana", "cherry"]
fruits.append("orange") # Add an item
# Tuple (immutable, ordered)
coordinates = (10, 20)
# Dictionary (key-value pairs)
person = {
"name": "John",
"age": 30,
"city": "New York"
}
# Set (unique elements)
unique_numbers = {1, 2, 3, 4, 5}
unique_numbers.add(6) # Add an item
Operators
Arithmetic Operators
Operator | Description | Example |
---|---|---|
+ | Addition | x + y |
- | Subtraction | x - y |
* | Multiplication | x * y |
/ | Division | x / y |
% | Modulus | x % y |
** | Exponentiation | x ** y |
// | Floor Division | x // y |
Comparison Operators
Operator | Description | Example |
---|---|---|
== | Equal | x == y |
!= | Not equal | x != y |
> | Greater than | x > y |
< | Less than | x < y |
>= | Greater than or equal to | x >= y |
<= | Less than or equal to | x <= y |
Logical Operators
Operator | Description | Example |
---|---|---|
and | Logical AND | x and y |
or | Logical OR | x or y |
not | Logical NOT | not x |
Control Flow
Conditional Statements
# If statement
if condition:
# code to execute if condition is True
# If-else statement
if condition:
# code to execute if condition is True
else:
# code to execute if condition is False
# If-elif-else statement
if condition1:
# code to execute if condition1 is True
elif condition2:
# code to execute if condition1 is False and condition2 is True
else:
# code to execute if both conditions are False
# Ternary operator
result = value_if_true if condition else value_if_false
Loops
# For loop
for item in iterable:
# code to execute for each item
# For loop with range
for i in range(5): # 0, 1, 2, 3, 4
# code to execute for each number
# While loop
while condition:
# code to execute while condition is True
# Loop control statements
for item in iterable:
if condition:
break # Exit the loop
if another_condition:
continue # Skip to the next iteration
Match Statement (Pattern Matching)
# Match statement (similar to switch in other languages)
match value:
case pattern1:
# code for pattern1
case pattern2:
# code for pattern2
case _:
# default case
This is just a sample of the reference documentation. The full reference includes detailed information on all language features.
Built-in Functions
Soplang provides a rich set of built-in functions that are always available. Here are some of the most commonly used ones:
Input/Output Functions
Function | Description | Example |
---|---|---|
print() | Prints objects to the console | print("Hello, World!") |
input() | Reads a line from input | name = input("Enter your name: ") |
open() | Opens a file | file = open("data.txt", "r") |
Standard Library
Soplang comes with a comprehensive standard library that provides modules for common tasks. Here's an overview of some key modules:
Advanced Topics
Once you're comfortable with the basics, explore these advanced features of Soplang:
Generators and Iterators
Create memory-efficient sequences and custom iteration behavior.
Learn More →Need Help?
If you can't find what you're looking for in the reference, try these resources: