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 numbers
  • float - Floating-point numbers
  • str - Strings (text)
  • bool - Boolean values (True or False)
  • None - Represents the absence of a value

Collection Data Types

  • list - Ordered, mutable collection
  • tuple - Ordered, immutable collection
  • dict - Key-value pairs
  • set - 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

OperatorDescriptionExample
+Additionx + y
-Subtractionx - y
*Multiplicationx * y
/Divisionx / y
%Modulusx % y
**Exponentiationx ** y
//Floor Divisionx // y

Comparison Operators

OperatorDescriptionExample
==Equalx == y
!=Not equalx != y
>Greater thanx > y
<Less thanx < y
>=Greater than or equal tox >= y
<=Less than or equal tox <= y

Logical Operators

OperatorDescriptionExample
andLogical ANDx and y
orLogical ORx or y
notLogical NOTnot 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

FunctionDescriptionExample
print()Prints objects to the consoleprint("Hello, World!")
input()Reads a line from inputname = input("Enter your name: ")
open()Opens a filefile = 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:

Math Module

Provides mathematical functions and constants.

View Documentation →

String Module

Advanced string manipulation functions.

View Documentation →

Date and Time

Functions for working with dates and times.

View Documentation →

File I/O

File input/output operations.

View Documentation →

Advanced Topics

Once you're comfortable with the basics, explore these advanced features of Soplang:

Decorators

Decorators provide a way to modify the behavior of functions or classes.

Learn More →

Generators and Iterators

Create memory-efficient sequences and custom iteration behavior.

Learn More →

Context Managers

Use the 'with' statement for resource management.

Learn More →

Need Help?

If you can't find what you're looking for in the reference, try these resources: