PitchHut
Log in / Sign up
termlisp
25 views
Empowering computation through pattern-driven transformation.
Pitch

Introducing term-lisp, a pioneering language for term processing that emphasizes first-class pattern matching and term rewriting. By focusing on transformations over traditional variables, term-lisp allows for elegant and flexible coding. With lazy evaluation and an undefined term approach, it fosters innovative problem-solving in computing for the modern programmer.

Description

term-lisp is an innovative programming language designed for term processing with a unique focus on first-class pattern matching. Inspired by renowned languages such as Pie, Haskell, and Agda, term-lisp takes a different approach to computation, leaning heavily on term rewriting rather than state mutation. This distinctive feature allows it to define functions as rules for replacing terms without the need for traditional variables, encouraging a cleaner and more expressive coding style.

Key Features

Term Rewriting

In term-lisp, computation is conceptualized through the transformation of terms using predefined equations akin to Lambda Calculus, ensuring a robust foundation for functional programming. An example of this syntax is illustrated below:

(true = Bool True)
(false = Bool False)

In this case, when encountering the term true, it seamlessly transforms into Bool True. Notably, terms can remain undefined without causing errors, allowing for greater flexibility during development.

First-class Pattern Matching

One of the standout features of term-lisp is its ability to support first-class pattern matching, enabling functions that can return patterns. For instance, the if expression can be succinctly defined as follows:

(if (:literal true) a b = a)
(if (:literal false) a b = b)

Here, true and false are automatically interpreted, streamlining the coding process.

Lazy Evaluation

To address the challenges posed by functions performing side effects—such as print statements—term-lisp employs lazy evaluation. This ensures that expressions are only executed when truly needed, preventing unexpected behavior. An example function is shown below:

(assertEqual a b = (if (eq a b) () (print (error a is-not-equal-to b))))

Language Structure

term-lisp maintains its foundation on atoms and lists, employing a distinctive syntax. The language utilizes constructors for custom data types, enabling developers to define and manipulate data structures flexibly.

For instance, you can define pairs like this:

(cons a b = Pair a b)
(car (Pair a b) = a)
(cdr (Pair a b) = b)

Functional Applications

Functional application follows traditional Lisp conventions, allowing expressions like (car (cons foo bar)) to effectively resolve to their return values.

Enhanced Function Definitions

Function definitions in term-lisp are rich and versatile, supporting destructuring, type-checking, value-matching, and even inline lambda expressions, making it easier to compose reusable components.

For example:

(print-pair (Pair a b) = print (Pair a b))

This results in a function specifically designed to operate only on Pair types.

Running term-lisp

To run term-lisp and evaluate your scripts, use the following command in the project root directory:

node termlisp.js <file>

This action will execute the prelude module and your specified file, launching you into REPL mode for interactive coding.

For more details, refer to the prelude.

In conclusion, term-lisp invites enthusiasts and developers to explore a novel approach to Lisp with its term rewriting capabilities and advanced pattern matching features, paving the way for innovative programming solutions. Enjoy your journey into the expressive world of term-lisp!