2025-04-16 14:23:53 -05:00
2025-05-22 16:46:30 -05:00
2025-05-26 17:56:07 -05:00
2025-05-22 16:46:30 -05:00
2025-05-22 16:46:30 -05:00
2025-02-08 10:24:14 -06:00
2025-02-08 10:24:14 -06:00
2024-12-18 19:15:56 -06:00

tricu

Introduction

tricu (pronounced "tree-shoe") is a purely functional interpreted language implemented in Haskell. It is fundamentally based on the application of Tree Calculus terms, but minimal syntax sugar is included.

This experiment has concluded. tricu will see no further development or bugfixes.

tricu is the word for "tree" in Lojban: (x1) is a tree of species/cultivar (x2).

Acknowledgements

Tree Calculus was discovered by Barry Jay.

treecalcul.us is an excellent website with an intuitive Tree Calculus code playground created by Johannes Bader that introduced me to Tree Calculus.

Features

  • Tree Calculus operator: t
  • Immutable definitions: x = t t
  • Lambda abstraction: id = (a : a)
  • List, Number, and String literals: [(2) ("Hello")]
  • Function application: not (not false)
  • Higher order/first-class functions: map (a : append a "!") [("Hello")]
  • Intensionality blurs the distinction between functions and data (see REPL examples)
  • Content-addressed store: save, version, tag, and recall your tricu terms.

REPL examples

tricu < -- Anything after `--` on a single line is a comment
tricu < id = (a : a) -- Lambda abstraction is eliminated to tree calculus terms
tricu < head (map (i : append i " world!") [("Hello, ")])
tricu > "Hello,  world!"
tricu < id (head (map (i : append i " world!") [("Hello, ")]))
tricu > "Hello,  world!"

tricu < -- Intensionality! We can inspect the structure of a function or data.
tricu < triage = (a b c : t (t a b) c)
tricu < test = triage "Leaf" (z : "Stem") (a b : "Fork")
tricu < test (t t)
tricu > "Stem"
tricu < -- We can even convert a term back to source code (/demos/toSource.tri)
tricu < toSource not?
tricu > "(t (t (t t) (t t t)) (t t (t t t)))"
tricu < -- or calculate its size (/demos/size.tri)
tricu < size not?
tricu > 12

tricu < !help 
tricu version 0.20.0
Available commands:
    !exit        - Exit the REPL
    !clear       - Clear the screen
    !reset       - Reset preferences for selected versions
    !help        - Show tricu version and available commands
    !output      - Change output format (tree|fsl|ast|ternary|ascii|decode)
    !definitions - List all defined terms in the content store
    !import      - Import definitions from file (definitions are stored)
    !watch       - Watch a file for changes (definitions are stored)
    !versions    - Show all versions of a term by name
    !select      - Select a specific version of a term for subsequent lookups
    !tag         - Add or update a tag for a term by hash or name

Content Store

tricu uses a "content store" SQLite database that saves and versions your definitions persistently.

  • Persistent definitions: Any term you define in the REPL is automatically saved.
  • Content-addressed: Terms are stored based on a SHA256 hash of their content. This means identical terms are stored only once, even if they have different names.
  • Versioning and history: If you redefine a name, the Content Store keeps a record of previous definitions associated with that name. You can explore the history of a term and access older versions.
  • Tagging: You can assign tags to versions of your terms to organize and quickly switch between related function versions.
  • Querying: The store allows you to search for terms by name, hash, or tags.

Installation and Use

You can easily build and run this project using Nix.

  • Quick Start (REPL):
    • nix run git+https://git.eversole.co/James/tricu
  • Build executable in ./result/bin:
    • nix build git+https://git.eversole.co/James/tricu

./result/bin/tricu --help

tricu Evaluator and REPL

tricu [COMMAND] ... [OPTIONS]
  tricu: Exploring Tree Calculus

Common flags:
  -? --help       Display help message
  -V --version    Print version information

tricu [repl] [OPTIONS]
  Start interactive REPL

tricu eval [OPTIONS]
  Evaluate tricu and return the result of the final expression.

  -f --file=FILE  Input file path(s) for evaluation.
                    Defaults to stdin.
  -t --form=FORM  Optional output form: (tree|fsl|ast|ternary|ascii|decode).
                    Defaults to tricu-compatible `t` tree form.

tricu decode [OPTIONS]
  Decode a Tree Calculus value into a string representation.

  -f --file=FILE  Optional input file path to attempt decoding.
                    Defaults to stdin.
Description
An interpreted language for exploring Tree Calculus
Readme ISC 863 KiB
Languages
Haskell 97.9%
Nix 2.1%