A small interpreted language with expressive syntax, functional pipelines, ranges, and first-class functions.
Pinkerton is an experimental programming language featuring:
- Clean and readable syntax
- Functional-style pipelines (
|>) - Range expressions (
0..10,'a'..'z') - First-class functions
- One-line function declarations
- Arrays and indexing
- Control flow statements
- Native and user-defined functions
function isEven(x) := x mod 2 = 0
function powTwo(x) := pow(x, 2)
let result :=
0..20
|> filter(isEven)
|> map(powTwo)
|> sorted()
writeln join(result, ';')
let x := 10
let name := "Pinkerton"
let flag := true
let a := 5 + 2 * 3
let b := (5 + 2) * 3
let c := 10 mod 3
let d := 2 ^ 8
let e := true and not false
let numbers := 0..10
let stepRange := 0..20 step 2
let lowercase := 'a'..'z'
let uppercase := 'A'..'Z'
Ranges can also be combined:
let letters := ('a'..'z') ^ ('A'..'Z')
Pipeline operator |> passes the result of the left expression
as the first argument of the function on the right.
let result :=
0..50
|> filter(isEven)
|> map(powTwo)
|> sorted()
Equivalent to:
sorted(map(filter(0..50, isEven), powTwo))
function square(x) := x * x
function factorial(n)
begin
if n = 0 then
return 1
return n * factorial(n - 1)
end
Functions are first-class values and can be passed as arguments.
let arr := [1; 2; 3; 4]
writeln arr[0]
let letters := 'a'..'z'
if 'c' in letters then
writeln "Found!"
let result := select if x > 0 then "positive" else "negative"
if x > 10 then
writeln "Big"
else
writeln "Small"
while x > 0 do
begin
writeln x
x := x - 1
end
Pinkerton encourages functional composition:
let alphabet :=
('a'..'z')
|> filter(isLetter)
|> sorted()
Pinkerton is implemented as:
- Lexer
- Recursive descent parser
- AST interpreter
- Support for native and user-defined functions
Pipeline expressions are transformed at parse time into regular function calls.
Pinkerton> run File.pink- Minimal syntax
- Expressive range operations
- Functional composition
- Simple interpreter architecture
- Educational compiler/interpreter project
function isPrime(n)
begin
if n < 2 then return false
let i := 2
while i * i <= n do
begin
if n mod i = 0 then
return false
i := i + 1
end
return true
end
let primes :=
2..100
|> filter(isPrime)
writeln join(primes, ';')
MIT