Skip to main content

Website Pypi Crates.io Chat with me on irc GitHub license CircleCI Build Status codecov

Mangle

An exolang (a scripting programming language just for fun) without any reserved keywords that can run any utf8 text as valid code. Meaning is derived entirely from word lengths and punctuation, never from the words themselves.

Installation

cargo install mangle

Python bindings

Python bindings are available for python > 3.7. You can install them with:

pip install mangle

Then you can evaluate mangle from python:

import mangle
mangle.eval("cat is fat")
>> '5'

More info at: https://github.com/matheusfillipe/mangle/tree/master/python

How it works

There are only labels, variables and operators. All variables are globally scoped within a single program; there are no locals or classes. All variables are dynamically typed and shadowed on reassignment.

Sentences

The only kind of scope is the sentence. Sentences are delimited by the punctuation marks .,;:?!. Any other token is interpreted as an operator, a variable name, or a literal. Text with no punctuation runs as a single sentence.

Labels

A sentence's label is its last word before the punctuation mark — except for the first sentence, which is main and needs no label. Labels name subroutines you can jump to. The first sentence runs automatically; after it finishes, execution falls through to the next sentence in order, unless a jump redirects it.

Data types

There are two types: ints and stacks.

A word's numeric value is its grapheme length: "a" evaluates to 1, "cat" to 3. A word is also a variable name; when a word is looked up as a value and is unbound, its length is used.

A stack is a Vec<int>. Pushing onto an unbound variable creates a fresh stack. Popping an empty stack yields 0.

The it register

After every operation the interpreter stores its result in the variable it. This is the only way to carry a computed value into a later operation (since assign only reads a single word). For example take cat cat add it fat subtracts 3 - 3 = 0 into it, then adds it + fat = 0 + 3 = 3.

Operators

The first word of each clause is the operator, dispatched by its grapheme length, nothing else. There are no keywords: is, be, as, of — every 2-letter word — is the assign operator, and so on. Pick whichever word of the right length makes your prose read best; the word's meaning is irrelevant, only its length matters. Lengths are assigned by frequency: the most common English word lengths (3, 4, 2, 5, 6 ...) map to the most-used operators, so natural prose tends to compile into useful programs. The operator consumes as many following words as its arity, then the next word is another operator, and so on until the sentence ends.

Word length Operator Arity Example word (any word this length works) Effect
1 literal 1 a evaluates to its argument's length
2 assign 2 is x := value
3 sum 2 add a + b
4 if-zero 2 when jump when value is 0
5 goto 1 leaps jump to a label
6 print 1 output prints a number
7 subtract 2 reduces a - b
8 multiply 2 multiply a * b
9 divide 2 quotients a / b
10 pop 1 everything pop the top of a stack
11 push 2 environment push a value onto a stack
12 modulo 2 subsequently a % b
13 puttext 1 communicating prints one literal word
14 phrase rest affectionately prints the rest of the sentence as text

Division by zero, unknown labels, unknown operator lengths, arity mismatches and infinite loops (capped at one million operations) all raise errors.

But then spaces are keywords heh?

Well... In some interpretation yes, I guess I lied then, sorry about it. You can still pass the -F argument to change the word separator (like field separator in awk) to any other character.

Metadata

Release files for mangle 1.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for mangle 1.0.0
File Size Uploaded
mangle-1.0.0.tar.gz 18.6 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for mangle 1.0.0
File Interpreter ABI Platform
mangle-1.0.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl CPython 3.9 CPython 3.9 Linux glibc 2.17+ x86-64 Details

Total release size: 260.6 kB

Release files / mangle-1.0.0.tar.gz

Download URL mangle-1.0.0.tar.gz
Size 18.6 kB
Tags Source
SHA-256 checksum
How to use checksums
ffec944d1b72dcd5ed9476401679f247d83836a92dc079a4aae2616f89ff476a
BLAKE2b-256 checksum
How to use checksums
69df1382aee1ed7b898a8f27dec91954ae8918cb5d20b4846db1d8c3431ba75f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via maturin/1.14.1

Release files / mangle-1.0.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL mangle-1.0.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 242.0 kB
Tags CPython 3.9 Linux glibc 2.17+ x86-64
SHA-256 checksum
How to use checksums
ccd437b51528169085ddf40bd61d1d2f0d233f80aebfdca820a5abecbb0ebb30
BLAKE2b-256 checksum
How to use checksums
2f853421d312ab3fb27097b80a663643036f555402442888d074d48795adafdb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via maturin/1.14.1

Release history Release notifications | RSS feed

This release

1.0.0 This release

2 release files

0.0.5

6 release files

0.0.4

6 release files

0.0.3

6 release files

0.0.2

6 release files

0.0.1

6 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page