Giter Site home page Giter Site logo

lispy's Introduction

Lispy

Lispy is a toy programming language. It is an interpreted language, and uses a LISP-like dialect. I mostly wrote this as a proof-of-concept and as a challenge to myself.

I am publishing it publicly on GitHub for portfolio purposes, as well as educational for anyone who may come across it. I would of course not recommend that anyone seriously use it for anything other than playing around or learning.

If you like the idea of using a LISP-style programming language, please take a look at Clojure.

How to use

For information regarding the "core library" please visit docs/core.md.

Building

$ mkdir .build
$ meson setup .build
$ cd .build && ninja

You should have an executable called lisp ready to use!

Basic Usage

Running lisp will open a REPL where you can write Lispy code. State is maintained throughout the session until an EOL (Ctrl+D) signal is sent to the program, at which point it will exit.

Here are some example inputs to help you get started:

(+ 1 2)
;; => 3
(defn square [x] (* x x))
(square 5)
;; => 25
(defn sum [a b] (+ a b))
(sum 12 30)
;; => 42
(defn square [x] (* x x))
(map square [1 2 3])
;; => [ 1 4 9 ]
(defn more_than_one_digit [n] (> n 9))
(filter more_than_one_digit [4 9 18 42 3])
;; => [ 18 42 ]
(filter more_than_one_digit (map square [1 2 3 4 5]))
;; => [ 16 25 ]
(def the_answer 42)
(if (= the_answer 42) (true) (false))
;; => true

Right now, the interpreter does not allow multiline input. I may add that in the future because the below program is about as complex as one can reasonably program in one line. Also loading a file would be nice.

(defn game [guess answer] (if (= answer guess) (0) (if (> guess answer) (1) (-1))))
(game 50 42)
;; => 1 (too high)
(game 24 42)
;; => -1 (too low)
(game 42 42)
;; => 0 (just right!)

Summary

There are some cool things that the interpreter can do! This is due to the fact that the parser is really easy to build because of the simplistic nature of LISP-style code, but also because everything is just a stack. Outside of a key- value store for globals, it's all the stack. Which makes it super easy to reuse code all over the place because you really only need one implementation everywhere.

lispy's People

Contributors

jonahisadev 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.