GithubHelp home page GithubHelp logo

oraqlle / lispy Goto Github PK

View Code? Open in Web Editor NEW
1.0 2.0 0.0 227 KB

C implementation of Lispy

Home Page: https://oraqlle.github.io/lispy/

License: MIT License

C 75.20% CMake 22.31% C++ 2.49%
c interpreter lisp

lispy's Introduction

Lispy

The original implementation of Lispy in C. Lispy is a small but robust programming language that inherits many features from Lisp. Lispy comes with a REPL as well as an interpreter. Like other Lisps, Lispy uses macros-like objects called Q-expressions to build out unevaluated code whose structure and content can be manipulated and then later evaluated.

Example

; Fibonacci (this is a comment)

; `()` denotes a S-expression which will evaluate immediately
; `{}` denotes a Q-expression which will remain unevaluated
; Define a function `fib` taking an parameter called `n`.
; `fun` takes two Q-expressions the first being the name and parameters,
; the second is the body of the function
(fun {fib n} {
    ; `select` expressions evaluate the first element (here a S-expression),
    ; returning the evaluated the second element if the first evaluates to true
    ; continues until a selection is made, `otherwise` is reached or no 
    ; selection is made which result in an `error`.
    select
        { (== n 0) 0 }
        { (== n 1) 1 }
        { otherwise (+ (fib (- n 1)) (fib (- n 2))) }
})

; Create list of numbers and apply `fib` to each element
; Yielding a new list
(print (map fib {0 1 2 3 4 5 6 7 8 9}))

Examples

Prerequisites

# Building
C11 compliant compiler (GCC, Clang, MSVC)
CMake >= 3.15.0
vcpkg

# Testing, coverage
C++11 compliant compiler
lcov

# Linting, formatting and spelling
clang-format
clang-tidy
cppcheck >= 2.7.0
codespell >= 2.2.4

# Docs
doxygen
python >= 3.6
jinja2
Pygments

Building

cmake --preset=dev
cmake --build --preset=dev

This project contains a few prebuilt presets for cross-platform configuration in the CMakePresets.json. It is common then to create your own presets in a CMakeUserPresets.json file to configure the project to your setup and for debugging. A sample one has been provided in CMakeUserPresets-Sample.json which contains the presets for different platforms in the form of dev-<platform>. There is also a plain dev preset which is an alias for dev-linux, which can be modified for your default platform. There are also dev presets for building and testing which simply require the dev preset.

Running

REPL

$ ./build/dev/lispy_interpreter
Lispy v0.3.1
Press Ctrl+D to exit.

Lispy>

Interpreter

./build/dev/lispy_interpreter examples/hello.lpy
"hello world!"

Tests

ctest --preset=dev

#  ... or
cmake --build --preset=dev -t test

Note

I haven't really written any tests yet.

Installing

If you wish to install the interpreter run the above build commands followed this command:

cmake --install build/dev --prefix="path/to/install/location"

Note

You can omit the --prefix= flag to install to the default location however this may require sudo/admin access.

Warning

This will install the debug/dev configuration of the interpreter. You can build one of the ci- presets to generate a release build configuration and run:

cmake --build build/ci-<platform>
cmake --install build/ci-<platform> --prefix="path/to/install/location"

Credit

This implementation of Lispy is based on Daniel Holden's book Build Your Own Lisp Book/Blog. If you are interested in creating your own programming language or even just learning C, I highly recommend giving it a read.

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.