masak / bel

An interpreter for Bel, Paul Graham's Lisp language
GNU General Public License v3.0
27 stars 1 forks source link
interpreter lisp lisp-dialect lisp-interpreter macros

Language::Bel

CI

A Perl 5 implementation of Paul Graham's Bel. Bel is a self-hosting Lisp dialect, released October 2019.

There are many Lisp dialects in the world, but Bel distinguishes itself by defining a complete stack of features on a metacircular foundation. That includes the evaluator, the reader and printer, but also I/O, error handling, and a numeric tower; these are all specified as Bel code in the language itself. Bel is built on top of Bel; that's true of the language's specification, and increasingly true of this implementation.

Getting started

You need Perl installed.

Right now, the way to install and run Language::Bel is via GitHub.

$ git clone https://github.com/masak/bel.git
Cloning into 'bel'...
[...]
done.

At some point soon, I'll also upload this distribution to CPAN. Then you'll be able to install it using a CPAN installer, such as cpanm.

Usage

After downloading Bel, you can run it like this:

$ perl -Ilib bin/bel
Language::Bel 0.64 -- darwin.
>
> ;; loops
> (set n (len (apply append prims)))
16
> (each word `(there are ,n primitives) (prn word))
there
are
16
primitives
(there are 16 primitives)
>
> ;; sorting and de-duplication
> (sort < '(3 2 8 6 18 12 2 19 13 19))
(2 2 3 6 8 12 13 18 19 19)
> (dedup (sort < '(3 2 8 6 18 12 2 19 13 19)))
(2 3 6 8 12 13 18 19)
>
> ;; templates and places
> (tem vec2d x 0 y 0)
((x lit clo nil nil 0) (y lit clo nil nil 0))
> (set robot (make vec2d))
(lit tab (x . 0) (y . 0))
> robot!y
0
> (zap [+ 5 _] robot!y)
5
> robot!y
5
> (++ robot!y)
6
> ((of list robot) 'x 'y)
(0 6)
>
> ;; arrays
> (set I (array '(3 3) 0))
(lit arr (lit arr 0 0 0) (lit arr 0 0 0) (lit arr 0 0 0))
> (def diag (m n) (m n n))
> (for n 1 3 (set (diag I n) 1))
nil
> I
(lit arr (lit arr 1 0 0) (lit arr 0 1 0) (lit arr 0 0 1))

But is it feature-complete?

Language::Bel implements all of the global definitions from the specification.

However, there are still some non-negotiable features still waiting to be completed:

Contributing

If you'd like to contribute, please fork the repository and make changes as you'd like. Pull requests are warmly welcome.

License and copyright

This software is Copyright (c) 2019-2024 by Carl Mäsak.

This project is licensed under the GNU GPL 3.0. For details, see LICENSE.