Marigold Language Documentation
website·Indexed 30 days ago
https://marigold-language.vercel.appA Lambda Calculus DSL designed for a simple, quick coding experience. Documentation covers installation via pipx, language fundamentals including variables, booleans, numbers, lists, and pairs, as well as advanced concepts like pipelines, guards, recursive functions, and anonymous functions/lambdas.
What's inside Marigold
- Marigold is a Domain Specific Language (DSL) built on $\lambda$-Calculus. In Marigold, every element—including numbers, booleans, and other datatypes—is represented as a function. The language implements pure lambda calculus patterns while applying modifications to improve code readability.
Overview of Marigold language design goals
Marigold is designed as a supporting language for lambda calculus, aiming to preserve core functional patterns while remaining accessible to humans. Its primary design pillars include:
- Faithfulness to Lambda Calculus: Preserves essential patterns such as fixed point recursion, Church encodings, and the fundamental logic of lambda calculus.
- Human-Friendliness: Prioritizes readability over strict adherence to lambda calculus notation. For example, it implements operators like addition in a way that is easier to read and write than the standard
function argument argumentpattern. - Lightweight Syntax: Minimizes boilerplate and avoids excessive keywords to provide a streamlined coding experience.
Represent numbers in Marigold
Numbers in Marigold are represented as Church Numerals, which represent natural numbers (positive integers only, no decimals). A numbernis represented as a lambda that takes a functionfand a valuex, applyingftoxexactlyntimes.Understand variable behavior in Marigold
In Marigold, variables do not store data; they act as nicknames for expressions. Because they are not storage containers, referencing a variable multiple times will re-evaluate the underlying expression each time. For example, if a variable is assigned the result of anaskcommand and used twice, the user will be prompted twice. All variables in Marigold are immutable, meaning there are no in-place operations. To achieve behavior similar to mutation, use the->operator.Use pipelines for data flow in Marigold
Marigold uses the
|operator to create pipelines, allowing values to be passed as the first argument to a function. This reduces the need for deeply nested function applications and creates a cleaner data flow.- A single pipe
a | b c dis equivalent tob a c d. - Chained pipes
a | b | care equivalent toc (b a).
// Equivalent to b a c d a | b c d // Equivalent to c (b a) a | b | c- A single pipe
Create and use Pairs in Marigold
Pairs are datatypes in Marigold used to hold two values. They are particularly useful for recursive functions and folds as a more efficient alternative to two-item lists.([item 1],[item 2]) // Or using builtin function notation (primarily for pipelines) PAIR [item 1] [item 2]Define and use functions in Marigold
Functions in Marigold are defined using thedefkeyword. Although all functions are technically unary, the compiler automatically curries arguments, allowing for functions of any arity. A function returns the last value evaluated; this is typically the last line of the function, but if statements and pipelines also act as return values.def [function_name]([comma seperated arguments]) { [multiline expression] }Install Marigold CLI from source
Marigold is installed globally usingpipx. Before proceeding, ensurepipxis installed on your system. To install Marigold, clone the repository, install the local directory via pipx, and inject thelarkdependency.git clone https://github.com/CaseyMasonek/marigold.git cd marigold pipx install . pipx inject marigold larkPrevent function nesting using the guard keyword
Theguardkeyword in Marigold acts as an early return mechanism. It wraps the subsequent lines of a function in an implicit if statement, allowing developers to handle edge cases or invalid conditions early and avoid excessive nesting of the main logic.guard ([condition]) [value];Implement conditional logic using Booleans
Because booleans in Marigold are functions that select one of two arguments, you can create a conditional by placing the condition before the two possible outcomes:
[condition] [value if true] [value if false]If the condition is
true, it returns the first value; iffalse, it returns the second.Implement multiple conditions using elif in Marigold
Theelif(else if) keyword provides a shorthand for nesting multiple if statements. It allows for a chain of conditions before a finalelsevalue.// Shorthand version if (condition1) value1 elif (condition2) value2 else value3 // Equivalent to nested version: if (condition1) value1 else { if (condition2) value2 else value3 }Perform Right Folds on lists
Marigold uses Church list encoding, which forces a right fold. A fold reduces a list to a single value using an accumulation function and an initial value. In a right fold, the accumulation starts from the last item of the list.
Structure:
[list] [accumulation function] [initial r value]Accumulation Function: Typically takes the head
hand the accumulatorr, returning a new value forrfor the next item.// Example: Summing a list // Accumulation function: @hr.h+r // Initial value: 0