Skip to main content

define_stdlib

Macro define_stdlib 

Source
macro_rules! define_stdlib {
    (
        $(
            $(#[$attr:meta])*
            $variant:ident($name:literal, [$($param:literal),* $(,)?], $body:literal)
        ),* $(,)?
    ) => { ... };
}
Expand description

Macro for defining standard library functions.

This macro generates the StdLib enum, its implementation, and the ALL constant from a single declarative definition. To add a new stdlib function, simply add a new entry to the macro invocation.

§Syntax

use grift_parser::define_stdlib;
define_stdlib! {
    /// Documentation comment
    VariantName("function-name", ["param1", "param2"], "lisp-body-code"),
    // ... more functions
}

§Example

To add a new function (my-func x y) that returns (+ x y):

use grift_parser::define_stdlib;
define_stdlib! {
    // ... existing functions ...
    /// (my-func x y) - Add two numbers
    MyFunc("my-func", ["x", "y"], "(+ x y)"),
}