Skip to main content

A custom interpreter for the Chotulang language.

Project description

Chotulang Interpreter

This is the official interpreter for the Chotulang programming language.

Installation

pip install chotulang

Basic syntax

========================================== CHOTULANG DEVELOPMENT GUIDE (Version 2.5.1)

Chotulang is a dynamic, Python-compatible language that emphasizes clean, readable syntax and supports powerful functional features like pipes and lambdas.


MODULE 1: CORE FUNDAMENTALS

  1. PRINTING AND VARIABLES Use 'out' to print. Use 'var' to declare a variable.

var name = "Alex" // String var count = 5 // Number var is_active = true // Boolean

out "Hello,", name, "!" out "The value is:", count

// User Input out "Enter a number:" var user_input = ask() // Reads a line of text out "You entered:", user_input

  1. COMMENTS Use the '#' symbol for comments.

This line is ignored by the interpreter


MODULE 2: OPERATOR PRECEDENCE

Understanding the order of operations ensures your calculations are correct.

Precedence Operator Description Example
Highest () Parentheses (Forces order) (5 + 2) * 3
2 ** Power/Exponent (Right-associative) 2 ** 3 ** 2 is 2 ** (3 ** 2) (512)
3 *, /, % Multiplication, Division, Modulo 10 / 2 * 5 (Left-to-right)
4 +, - Addition, Subtraction 3 + 4 - 1 (Left-to-right)
5 <, >, ==, != Comparison x > 5
6 &&,
Lowest =, +=, -=, *=, /= Assignment x = 10

// Power Operator Example (Exponent) var result_power = 8 ** 2 out "8 squared is:", result_power // 64

var complex_calc = 10 - 2 ** 3 * 2 // Order: 2**3 (8), then 8*2 (16), then 10-16 (-6) out "Complex calculation:", complex_calc


MODULE 3: CONTROL FLOW & LOOP JUMPS

  1. IF/ELSE STATEMENTS Conditional execution blocks. The curly braces {} are mandatory.

var temperature = 30

if temperature > 25 { out "It is hot." } else { out "It is mild." }

  1. LOOPS (ITERATION)

// The 'do' Loop (Similar to While) var i = 0 do i < 3 { out "Do loop iteration:", i i += 1 }

// The 'for' Loop (Iterates over a list or range) for number in 0..4 { out "Current number:", number }

  1. LOOP JUMP STATEMENTS

// WARNING: These must only be used inside a 'do' or 'for' loop!

// 'break' // Stops the current loop entirely and execution continues after the loop. do true { out "Running once..." break // Exits the 'do' loop }

// 'next' // Skips the rest of the code in the current loop body and starts the next iteration. for i in 1..5 { if i == 3 { next // Skip printing 3, go straight to 4 } out "Number:", i }


MODULE 4: DATA STRUCTURES

  1. LISTS (Ordered Collections)

var fruits = ["apple", "banana", "kiwi"] out fruits[1] // Access: banana fruits.append("grape") // Add to end

  1. DICTIONARIES (Key-Value Pairs)

var user = { "id": 101, "status": "online" }

out user["status"] // Access: online user.set("city", "London") // Add/Update a key


MODULE 5: FUNCTIONS AND PIPES

  1. STANDARD FUNCTIONS ('fn') Use 'fn' for reusable code blocks. Use 'ret' to return a value.

fn multiply(x, y) { ret x * y }

var product = multiply(8, 6) out "Product:", product

  1. LAMBDA FUNCTIONS (Anonymous Functions)

// Syntax: fn(params) => expression var is_even = fn(n) => n % 2 == 0 out is_even(4) // true

  1. THE PIPE OPERATOR (|>) Pass the result of one expression as the first argument to the next function.

fn increment(x) { ret x + 1 } fn double(x) { ret x * 2 }

var value = 10 |> increment |> double // (10 + 1) * 2 = 22 out value


MODULE 6: COMPLEX MATHEMATICAL OPERATIONS

  1. USING THE PYTHON MATH LIBRARY Import the standard Python 'math' module using the 'use' keyword.

use math

// Square Root var root = math.sqrt(64) out "Root of 64:", root

// Trigonometry and Constants var angle = math.radians(45) var sine_val = math.sin(angle) out "Sine of 45 deg:", sine_val out "Pi value:", math.pi // Access constant

  1. COMPLEX CALCULATION WITH PIPES

fn area_calc(r) { ret math.pi * r ** 2 } // Using ** for r squared fn round_2(n) { ret round(n, 2) }

var r = 5 var final_area = r |> area_calc |> round_2 // 5 -> area_calc -> round_2 out "Rounded Area:", final_area


PRACTICE PROJECTS

  1. THE GUESSING GAME Use the 'random' library (use random). Generate a random number. Use a 'do' loop and 'if/else' to let the user guess until correct, providing 'Too High' or 'Too Low' hints.

  2. MATH & DATA PIPELINE Create a list of numbers. Use map (or a loop) and a lambda to cube every number, then use the pipe operator to feed the resulting list to a function that calculates the sum of all elements.

  3. GEOMETRY FUNCTION Write a function that accepts two numbers (A and B). This function must check if A and B are positive numbers. If they are, it uses the 'math' library to calculate the perimeter of a rectangle (2A + 2B) and returns it. If not, it returns the string "Error: Invalid dimensions".

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

chotulang-0.0.5.tar.gz (4.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

chotulang-0.0.5-py3-none-any.whl (4.0 kB view details)

Uploaded Python 3

File details

Details for the file chotulang-0.0.5.tar.gz.

File metadata

  • Download URL: chotulang-0.0.5.tar.gz
  • Upload date:
  • Size: 4.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.1

File hashes

Hashes for chotulang-0.0.5.tar.gz
Algorithm Hash digest
SHA256 e79a69b3ea60d4727cadc569547c99850fc3945bed1420573fac3e5dd17d60bf
MD5 444ff401c61e0da908caf982b914c978
BLAKE2b-256 b29e29272721062936406d5a697ac6adde3ce8f1ec3529564f51b34891bcddcf

See more details on using hashes here.

File details

Details for the file chotulang-0.0.5-py3-none-any.whl.

File metadata

  • Download URL: chotulang-0.0.5-py3-none-any.whl
  • Upload date:
  • Size: 4.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.1

File hashes

Hashes for chotulang-0.0.5-py3-none-any.whl
Algorithm Hash digest
SHA256 ff6b2ee457505ee78b4c20e83caaf2de06e296a201b40210ee76333e1b75f543
MD5 63f91848fdc24c63fd6bef2b67463a35
BLAKE2b-256 6ec8256f919d7a90f9e20bfa38e42ea868840e1cc6cb86957dfebccbe54928d2

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page