Code Monkey home page Code Monkey logo

tulisp's Introduction

Tulisp

docs.rs Crates.io

Tulisp is a Lisp interpreter that can be embedded into Rust programs. The syntax tries to closely match that of Emacs Lisp. It was primarily designed to be a configuration language, but it also works well as a general purpose embedded scripting language.

One of the many benefits of using the Emacs Lisp syntax is that we can reuse its documentation for the builtin functions and macros. And for people who are already familiar with Emacs Lisp, there's no need to learn an extra language.

Getting started

Tulisp requires rustc version 1.70 or higher.

It is very easy to get started. Here's an example:

use tulisp::{TulispContext, tulisp_fn, Error};

fn main() -> Result<(), Error> {
    // Create a new Tulisp execution context.
    let mut ctx = TulispContext::new();

    // Add a function called `add_nums` to `ctx`.
    #[tulisp_fn(add_func = "ctx")]
    fn add_nums(num1: i64, num2: i64) -> i64 {
        num1 + num2
    }

    // Write a lisp program that calls `add_nums`
    let program = "(add_nums 10 20)";

    // Evaluate the program, and save the result.
    let sum: i64 = ctx.eval_string(program)?.try_into()?;

    assert_eq!(sum, 30);
    Ok(())
}

Features

  • defuns, defmacros and lambdas
  • intern to find/create symbols dynamically
  • Backquote/Unquote forms (for example `(answer . ,(+ 2 3)))
  • Threading macros (thread-first and thread-last)
  • Methods for reading from alists and plists
  • Lexical scopes and lexical binding
  • Tailcall Optimization
  • Proc macros for exposing rust functions to tulisp
  • Decl macros for creating lists and destructuring lists quickly.
  • Easy to use interpreter and objects
  • Backtraces for errors

Performance

Tulisp has a light-weight tree-walking interpreter with very low startup times and sufficient speed for many config/simulation needs.

Builtin functions

A list of currently available builtin functions can be found here.

Projects using Tulisp

  • slippy - a configuration tool for the Sway window manager.
  • microsim - a microgrid simulator.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.