MØSS

From Esolang
Jump to navigation Jump to search

MØSS(pronounced as /mœs/ where /œ/ is a rounded /e/) is designed by PSTF and his AI friend.

This language is an interpreted language, formally called 'Meaningful Object-oriented Simple Syntax', and is usually abbreviated as 'MossLang' (not 'MOSS', to distinguish it from something with the same name in a certain science fiction novel).

Language Overview

# Variable Declaration (Weakly Typed)
name = "Alice"
age = 25
is_student = true

# List (Mutable Array)
numbers = [1, 2, 3, 4, 5]
fruits = ["apple", "banana", "orange"]

# Object (Prototype-Based OOP)
Person = {
    init = func(name, age) {
        this.name = name
        this.age = age
    },
    
    greet = func() {
        print("Hello, I'm "   this.name)
    }
}

# Create Object Instance
alice = new Person("Alice", 30)
alice.greet()

Complete Syntax Specification

Basic Command Flow

# Comments start with #

# Variable assignment
variable_name = expression

# Conditional statements
if (condition) {
    # code block
} else if (condition) {
    # code block
} else {
    # code block
}

# Loop
while (condition) {
    # code block
}

for (variable in list) {
    print(variable)
}

# Function definition
function_name = func(param1, param2) {
    # function body
    return value
}

Data Type

# Basic Types
Numbers: 42, 3.14
Strings: "hello", 'world'
Booleans: true, false
Nil: nil

# Composite Types
List: [1, 2, 3]
Object: {key = "value", method = func() {}}

Turing-Completeness Proof

MØSS achieves Turing completeness through the following constructions:

# 1. Sequential execution (implicit)
a = 1
b = 2
c = a + b

# 2. Conditional branching
if (x > 0) {
  # Branch 1
} else {
  # Branch 2
}

# 3. Loop (can implement an infinite loop)
while (true) {
  # Execute indefinitely
}

# 4. Function recursion (supports arbitrary depth)
factorial = func(n) {
  if (n <= 1) {
    return 1
  }
  return n * factorial(n - 1)
}

# 5. Memory (through variables and data structures)
memory = [] # Can serve as the tape of a Turing machine

Although the indentation here is two spaces, in formal situations, the indentation should be four spaces. However, regardless of how many spaces you use for indentation, you should ensure that the number of spaces for each level of indentation and the difference in spaces between adjacent levels are consistent, otherwise the consequences can be disastrous.

I/O System

# Standard output
print("Hello, World!")
print(42)
print([1, 2, 3])

# Formatted output
name = "Alice"
age = 25
print(f"Name: {name}, Age: {age}")

# Input
name = input("Enter your name: ")
number = int(input("Enter a number: "))

# File operations
file = open("data.txt", "r")
content = file.read()
file.close()

# Write to file
file = open("output.txt", "w")
file.write("Hello, File!")
file.close()

List Operations

# Create a list
list1 = [1, 2, 3]
list2 = ["a", "b", "c"]
list3 = [] # Empty list

# Access elements
first = list1[0] # 1
last = list1[-1] # 3
sublist = list1[1:3] # [2, 3]

# Modify the list
list1[0] = 10 # [10, 2, 3]
list1.append(4) # [10, 2, 3, 4]
list1.remove(2) # [10, 3, 4]

# List method
length = len(list1) # Get the length
list1.sort() # sort
list1.reverse() # invert
contains = list1.contains(3) # Check for inclusions

# List derivation
squares = [x * x for x in [1, 2, 3, 4, 5] if x % 2 == 0]
# Results: [4, 16]

Object-oriented Programming

# Class definition (prototypal)
Animal = {
    # Constructor
    init = func(name, species) {
        this.name = name
        this.species = species
    },
    
    # Instance method
    speak = func() {
        print("${this.name} makes a sound")
    },
    
    # Class variable
    is_alive = true
}

# Inheritance
Dog = {
    # Set prototype
    __proto__ = Animal,
    
    # Override constructor
    init = func(name) {
        Animal.init(name, "Dog")
        this.breed = "Unknown"
    },
    
    # Override method
    speak = func() {
        print("${this.name} says: Woof!")
    },

    # New method
    wag_tail = func() {
        print("${this.name} is wagging tail")
    }
}

# Using objects
buddy = new Dog("Buddy")
buddy.speak() # Buddy says: Woof!
buddy.wag_tail() # Buddy is wagging tail

# Polymorphism
animals = [new Dog("Rex"), new Animal("Generic", "Unknown")]
for animal in animals {
    animal.speak() # Calls respective methods
}

# Access control (by convention)
Person = {
    init = func(name) {
        this._private_data = "secret" # Considered private by convention
        this.public_name = name # Public
    }
}

Standard Library

# Mathematical Operations
import math
result = math.sqrt(16) # 4
result = math.sin(3.1415926535897932384626433832795)

# String Operations
import string
formatted = string.format("Hello, {}", "World")

# Time
import time
current = time.now()
time.sleep(1) # Pause for 1 second

# Random Numbers
import random
num = random.randint(1, 100)
choice = random.choice(["a", "b", "c"])}

Example Programs

Simple To-Do App

Task = {
    init = func(title, priority = 1) {
        this.title = title
        this.priority = priority
        this.completed = false
        this.created_at = time.now()
    },
    
    complete = func() {
        this.completed = true
        this.completed_at = time.now()
    },
    
    display = func() {
        status = this.completed ? "✓" : "□"
        print("${status} ${this.title} (priority: ${this.priority})")
    }
}

TodoList = {
    init = func() {
        this.tasks = []
    },
    
    add_task = func(title, priority) {
        task = new Task(title, priority)
        this.tasks.append(task)
        print("Task added: ${title}")
    },
    
    show_tasks = func() {
        print("\n=== Your Tasks ===")
        for task in this.tasks {
            task.display()
        }
    },
    
    complete_task = func(index) {
        if (index >= 0 and index < len(this.tasks)) {
            this.tasks[index].complete()
            print("Task completed!")
        }
    }
}

# Main program
def main() {
    my_list = new TodoList()
    
    # Add task
    my_list.add_task("Buy groceries", 2)
    my_list.add_task("Learn MØSS programming", 1)
    my_list.add_task("Call mom", 3)
    
    # Display
    my_list.show_tasks()
    
    # Complete task
    my_list.complete_task(1)
    
    # Display again
    my_list.show_tasks()
    
    # Get user input
    new_task = input("\nAdd a new task: ")
    if (new_task != "") {
        my_list.add_task(new_task, 2)
        my_list.show_tasks()
    }
}

# Execute program
main()

Categories, Notes, and References