Git Product home page Git Product logo

nixlisp's Introduction

nix-lisp

A lisp implementation written in Nix.

Features

  • No IFD. Just plain Nix.
  • Macros (non-hygienic)
  • Nix interop
    • Shares most of its data types with Nix
    • Contains syntax support and helpers to use Nix lists and attrsets
    • Can call Nix functions seamlessly
    • Can export functions that can be called from Nix

Example

(import ./default.nix).eval {} ''
  (define nixpkgs
    (fetchTarball
       'url "https://github.com/nixos/nixpkgs/archive/a39ee95a86b1fbdfa9edd65f3810b23d82457241.tar.gz"
       'sha256 "11sk5hz51189g6a5ahq3s1y65145ra8kcgzfjkmrjp1jzn7h68q8"))
  (define pkgs (import nixpkgs (attrs)))

  ((pkgs 'haskellPackages 'ghcWithPackages)
      (lambda (ps) (vector (ps 'relude) (ps 'pipes))))
  ''

Current state

It's kinda-sorta working. It can use Nix values and call Nix functions. It is probably not very performant, and is easy to hit the stack limit. There standard library is pretty minimal, but since it's easy to use Nix builtins and nixpkgs functions, I do not expect it to be the biggest problem. PR's very welcome.

Docs

Standard library

See stdlib.nixlisp. It is also the best place look for examples.

Defining a function

(defun myDouble (x) 
  (define two 2)
  (+ x two))

defun is a macro; the above function expands to:

(define myDouble (lambda (x) 
  (begin
    (define two 2)
    (+ x two))))

Defining a macro

(defmacro cond args
  (defun go (xs)
    (if
      (nil? xs) 'nil
      (begin
        (define clause (car xs))
        (define condition (car clause))
        (define value (car (cdr clause)))
        (list 'if condition value (go (cdr xs))))))
  (go args))

Defining an attribute set

(attrs
  'firstKey "foo"
  'anotherKey 12
  'yetAnotherKey (vector 1 2 3))

Types

Nix Nixlisp
int int
string string
bool bool
null nil
function nix-function
attrs attrs
list vector
- lambda
- symbol
- cons
- macro
float (not implemented yet)
path (not implemented yet)

Nix compatibility

  • Types that are unique to Nixlisp are implemented as attribute sets with a special tag on Nix side. They are not meant to be accessed, but you can pass them back to Nixlisp.
  • Nixlisp lambda's can be called as normal functions from the Nix side, but they have to have at least one named parameter, and can not have variable numbero of arguments. Macros can not be called from Nix.
  • nix-function's can be called just as lambda's within Nixlisp. Since they are curried by default, all of the parameters will be passed to them one after another.
  • Attribute sets behave like functions, where you can pass them strings or symbols and they can do a lookup.
  • Beware that a Nixlisp "list" (a nil-terminated cons-list) is not a Nix "list". A Nix list is called a "vector", and you can use the vector, or list->vector functions to construct them.

Thanks

nixlisp's People

Contributors

utdemir avatar

Watchers

 avatar

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.