m28

command module
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 6, 2025 License: MIT Imports: 11 Imported by: 0

README

M28 - A Lispy-Pythonic Programming Language

Version License Go Version

M28 is a modern programming language that blends the elegant s-expression syntax of Lisp with the pragmatic design and extensive ecosystem of Python. It offers the best of both worlds: the power of homoiconic code and macros with Python's clean semantics and familiar keywords.

Quick Start

# Variables use = (never def)
(= message "Hello, M28!")
(print message)

# Functions use def
(def greet (name)
  (print "Hello," name))

(greet "World")

# Python-style data structures with Lisp syntax
(= numbers [1, 2, 3, 4, 5])
(= doubled (map (lambda (x) (* x 2)) numbers))
(print doubled)  # [2, 4, 6, 8, 10]

Installation

# Clone the repository
git clone https://github.com/mmichie/m28.git
cd m28

# Build the interpreter
make build

# Run the REPL
./bin/m28

# Run a script
./bin/m28 script.m28

Language Features

S-Expression Syntax

Everything is an expression in prefix notation:

(+ 1 2 3)           # 6
(print "Hello")     # Hello
(if (> x 0) "positive" "non-positive")
Python Semantics
  • # for comments (Python-style)
  • def only for functions
  • = only for variables
  • Python keywords: if, elif, else, for, in, while, try, except, class, import, etc.
  • Python built-ins: len, range, sum, map, filter, print, etc.
Modern Data Structures
# Lists
(= fruits ["apple", "banana", "orange"])

# Dictionaries  
(= person {"name": "Alice", "age": 30})

# Sets
(= unique {1, 2, 3})

# Tuples
(= point (10, 20))
Object-Oriented Programming
(class Person
  (def __init__ (self name)
    (= self.name name))
  
  (def greet (self)
    (print f"Hi, I'm {self.name}")))

(= alice (Person "Alice"))
(alice.greet)  # Hi, I'm Alice
Functional Programming
# First-class functions
(= numbers [1, 2, 3, 4, 5])
(= evens (filter (lambda (x) (== (% x 2) 0)) numbers))
(= squared (map (lambda (x) (* x x)) evens))

# List comprehensions
(= squares [x**2 for x in (range 10) if (even? x)])
Exception Handling
(try
  (risky-operation)
  (except ValueError as e
    (print "Error:" e))
  (finally
    (cleanup)))
Module System
(import math)
(import pandas as pd)
(from datetime import date)

(= root (math.sqrt 16))
(= df (pd.DataFrame data))

Documentation

Examples

Hello World
(print "Hello, World!")
Factorial
(def factorial (n)
  (if (<= n 1)
      1
      (* n (factorial (- n 1)))))

(print (factorial 5))  # 120
File I/O
(with (open "data.txt" "r") as f
  (for line in f
    (print (strip line))))
Web Server (using Python interop)
(from flask import Flask)
(= app (Flask __name__))

(app.route "/" 
  (lambda ()
    "Hello from M28!"))

(app.run)

Why M28?

  1. S-expressions - Code is data, enabling powerful metaprogramming
  2. Python semantics - Familiar and pragmatic design choices
  3. Prefix notation - Consistent, unambiguous syntax
  4. Python interop - Access to Python's vast ecosystem
  5. Modern features - List comprehensions, context managers, async/await
  6. Simple implementation - Easy to understand and extend

Contributing

Contributions are welcome! Please read our Contributing Guide for details.

License

M28 is licensed under the MIT License. See LICENSE for details.

Acknowledgments

M28 stands on the shoulders of giants:

  • Lisp for s-expressions and homoiconicity
  • Python for pragmatic design and clear semantics
  • Scheme for minimalism and elegance
  • Clojure for modern Lisp innovations

Documentation

The Go Gopher

There is no documentation for this package.

Directories

Path Synopsis
Package builtin provides standard library functions for the M28 language.
Package builtin provides standard library functions for the M28 language.
Package core provides the fundamental types and interfaces for the M28 language.
Package core provides the fundamental types and interfaces for the M28 language.
m28shell command
Package eval provides the evaluation system for M28 expressions.
Package eval provides the evaluation system for M28 expressions.
Package parser provides a parser for the M28 programming language.
Package parser provides a parser for the M28 programming language.
Package repl provides the read-eval-print loop for interactive M28 sessions.
Package repl provides the read-eval-print loop for interactive M28 sessions.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL