Introducing Lingua: A Minimalist, Expressive Language for Creative Coding
(Inspired by Lisp, Python, and Forth)
Lingua combines symbolic expressiveness with functional simplicity. Here’s the full specification:
1. Core Principles
- Everything is an atom or a list:
(operator arg1 arg2 ...)
- No keywords: Operations are defined by symbols.
- Dynamic typing: Values carry their type.
- Concise syntax: Minimal punctuation.
2. Syntax & Data Types
; Atoms (immutable)
42 ; int
3.14 ; float
"hello" ; string
:quit ; symbol (interned)
; Lists (evaluated as operations)
(+ 1 2) ; → 3
(print "Hi") ; Output: Hi
3. Special Forms
| Form |
Meaning |
Example |
(def x 10) |
Define variable |
x → 10 |
(fn [a b] ...) |
Define function |
((fn [a b] (+ a b)) 2 3) → 5 |
(if cond T F) |
Conditional |
(if (> 3 2) "Y" "N") → "Y" |
(quote x) |
Prevent evaluation |
(quote (+ 1 2)) → (+ 1 2) |
'(a b c) |
Shorthand for (quote (a b c)) |
'(1 2 3) → list (1 2 3) |
4. Functions
; Named function
(def sq (fn [x] (* x x)))
(sq 4) ; → 16
; Anonymous function
(map (fn [x] (* x 2)) '(1 2 3)) ; → (2 4 6)
5. Conventions
- Arithmetic:
(+ 1 2 3) → 6 (n-ary)
- Comparison:
(> 5 3) → :true
- Logic:
(and :true :false) → :false
- Lists:
(head '(1 2 3)) → 1
(tail '(1 2 3)) → (2 3)
6. Memory Management
- Garbage-collected: No manual memory handling.
- Persistent data structures: All values immutable.
7. Standard Library
| Function |
Action |
(range 5) |
→ (0 1 2 3 4) |
(zip a b) |
Pair lists: (zip '(1 2) '(a b)) → ((1 a) (2 b)) |
(fold + 0 '(1 2 3)) |
→ 6 |
(io/write "file.txt" "data") |
Write to file |
8. Sample Program: Fibonacci
(def fib
(fn [n]
(if (< n 2)
n
(+ (fib (- n 1)) (fib (- n 2))))))
(print (fib 10)) ; → 55
9. Unique Features
- Homoiconicity: Code is data (manipulate code as lists).
- REPL-Driven: Interactive development.
- Macro System:
(defmacro unless [cond body]
(list 'if (list 'not cond) body))
(unless (> 3 4) (print "Safe!")) ; Prints "Safe!"
Why Lingua?
- Learn in 10 minutes: Syntax fits on a notecard.
- Extensible: Add features via macros.
- Embeddable: <200 KB runtime.
Example interpreter (Python):
def eval(expr, env):
if isinstance(expr, int): return expr
if expr[0] == '+': return eval(expr[1], env) + eval(expr[2], env)
# ...
Run it: lingua script.lg
Design your own dialects, explore symbolic programming, and create freely! 🚀
Introducing Lingua: A Minimalist, Expressive Language for Creative Coding
(Inspired by Lisp, Python, and Forth)
Lingua combines symbolic expressiveness with functional simplicity. Here’s the full specification:
1. Core Principles
(operator arg1 arg2 ...)2. Syntax & Data Types
3. Special Forms
(def x 10)x→ 10(fn [a b] ...)((fn [a b] (+ a b)) 2 3)→ 5(if cond T F)(if (> 3 2) "Y" "N")→ "Y"(quote x)(quote (+ 1 2))→(+ 1 2)'(a b c)(quote (a b c))'(1 2 3)→ list(1 2 3)4. Functions
5. Conventions
(+ 1 2 3)→ 6 (n-ary)(> 5 3)→:true(and :true :false)→:false(head '(1 2 3))→ 1(tail '(1 2 3))→(2 3)6. Memory Management
7. Standard Library
(range 5)(0 1 2 3 4)(zip a b)(zip '(1 2) '(a b))→((1 a) (2 b))(fold + 0 '(1 2 3))6(io/write "file.txt" "data")8. Sample Program: Fibonacci
(def fib (fn [n] (if (< n 2) n (+ (fib (- n 1)) (fib (- n 2)))))) (print (fib 10)) ; → 559. Unique Features
Why Lingua?
Example interpreter (Python):
Run it:
lingua script.lgDesign your own dialects, explore symbolic programming, and create freely! 🚀