(modal)
modal [mōd′l] (adjective): of or relating to structure as opposed to substance
Modal is a flexible general purpose programming language based on the concept of rewriting. It was created in 2018 as a response to the rise in implementation complexity for high-level languages. The language has a single operation: * Find a pattern. * Replace that pattern with another pattern. All Modal code is phrased in terms of "rules", which specify a pattern and a replacement. Modal programs "evolve" over the course of multiple replacement operations, replacing parts of themselves and morphing into a final "result" where no more rules may be applied. Modal programs manipulate a global "tree" structure, similar to (term rewriting systems). All search-and-replace operations happen on this single, global tree.
A simple rule that replaces "1" with "2".
<> 1 2 1
There are multiple styles of writing Modal, as the language is flexible enough to express any and all abstractions the programmer may desire. However, writing those abstractions is very much like specifying the laws of physics for a small tree-structured universe. A common pattern is the "cursor", or "particle", where rules focus on specifying how a piece of data moves around other pieces of data. In this pattern, data can "carry" other data around, collide with other data elements, and interact in complex ways. Common algorithms like search involve a "cursor" traversing data, then relaying it back to a cursor waiting for a result.
A "particle", reflecting between walls forever.
<> (> _) (_ >) <> (> |) (< |) <> (_ <) (< _) <> (| <) (| >) | > _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ |
Modal, being a fully homoiconic language, may define special syntax forms, morphing the language into a fusion of a parser, compiler, and interpreter. Modal may be used as a meta-language, or a language that allows you to define new languages. It's been classified as a "mimic" by many of its users.
A "factorial" function, with some simple Lisp-like syntax.
<> ((defun ?n ?p ?b)) (defun ?n ?p ?b) <> (defun ?n ?p ?b) (<> (?n ?p) ?b) <> (q ?x) (q ?x) <> ((unwrap ?x)) (unwrap ?x) <> (unwrap ((?x))) (unwrap (?x)) <> (unwrap ?x) ?x <> (if ?c ?t ?f) (if/q ?c q ?t q ?f) <> (if/q (true) q ?t q ?f) (unwrap ?t) <> (if/q (false) q ?t q ?f) (unwrap ?f) <> (== (?x) (?x)) (true) <> (== (?x) (?y)) (false) <> (math ?: ?0 ?1) ?: <> (+ (?x) (?y)) (math + ?x ?y) <> (- (?x) (?y)) (math - ?x ?y) <> (* (?x) (?y)) (math * ?x ?y) (defun factorial (?n) (if (== (?n) (1)) (?n) (* (?n) (factorial (- (?n) (1)))))) (factorial (5))
Modal's execution model is tailored towards an easy implementation. Modal does not utilize garbage collection or complex reference patterns. Modal can fit in a static memory footprint, and is amenable to implementation in hardware via hardware description languages. The language was, originally, an exploration of functional programming/term rewriting on "bare metal", or without any surrounding dependencies such as an operating system. Modal currently has 2 primary implementations, (the original implementation) in Python and (an optimized implementation) in C by Devine Lu Linvega of (Hundred Rabbits). Modal also has a work-in-progress extension called (Thuesday), also authored by Devine. This extension adds numerous things, including graphics, in a pure way.
"What is Modal?"
what is modal <> (?x <-> ?y) (<> ?x ?y) (what is ?x) <-> (is ?x a (programming language)) (is ?x a ?y) <-> (or, is ?x (a virtual machine)) (or, is ?x ?y) <-> (?x is ?y <> ?y (a meta-language)) ((a meta-language)) <-> modal (?x is ?x) <-> (?(?: ?:) ?x)
Modal is what you make of it. Thanks to Devine for convincing me that Modal was worth sharing.
(wryl/modal) (rabbits/modal) (rabbits/thuesday) (modal wiki entry on wiki.xxiivv.com) (modal wiki entry on concatenative.org) -------- (back)
...... ... .. ... .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. ... .. ... ......
wryl © 2025