GithubHelp home page GithubHelp logo

lisptojs's Introduction

lispToJS

Translator from lisp to JS (just for fun, or not?)

Intro

This app is implemented in Node, so you need to install Node.js(preferably the latest version) and npm on your machine.

Installation

git clone [email protected]:Guseyn/lispToJS.git
cd lispToJS
npm install

Run

npm run start

You can open it on http://localhost:8000/

Test

npm test

Interface

Left editor is for typing in lisp. Right area is for JS code. JS area displays updates from backend as you type lisp code. But it does not update hightlighing of lisp code(because it slows down app), and you have to click somewhere outside of lisp editor to update highlighting of lisp code.

Features

Nested Lists

lisp

(x (y (z) (a)))

js

[x, [y, [z],
  [a]
]]

Arithmetic Expressions

lisp

(+ a (- b (* c (/ d e))) (+ f g) )

js

(a + (b - (c * (d / e))) + (f + g))

Variables Declaration (only local)

lisp

(let ((var1 val1) (var2 val2)) ())

js

let var1 = val1
let var2 = val2

Function Declaration

lisp

(defun name (v1 v2) (+ v1 v2))

js

function sum(v1, v2) {
  return (v1 + v2)
}

Function Call

lisp

(defun sum (v1 v2) (+ v1 v2))(sum (10, 10))

js

function sum(v1, v2) {
  return (v1 + v2)
}
sum(10, 10)

Only format function is supported by default. So, if you want to the system detect your functions you must declare them first.

Loop (only this type)

lisp

(loop for x in ("tom" "dick" "nina") do (format (t "~s" x)))

js

for (let x in ['tom', 'dick', 'nina']) {
  format(t, '~s', x)
}

Branches (only basic if)

lisp

(if (< a 20) (format (t "~% a is less than 20")) (format(t "~% a is more than 20"))) 

js

if ((a < 20)) {
  return format(t, '~% a is less than 20')
}
return format(t, '~% a is more than 20')

Lambdas

lisp

(lambda (x y) (+ x 10))

js

(x, y) => {
  return (x + 10)
}

Simple Example

Max Of Two Vars

lisp

(defun max (v1 v2) 
  (if (> v1 v2) v1 v2))

js

function max(v1, v2) {
  if ((v1 > v2)) {
    return v1
  }
  return v2
}

REST API

/isValidLisp

Request

POST request with plain text body like (defun max (v1 v2) (if (> v1 v2) v1 v2))

Possible Responses

{
    "isValid": true
}
{
    "isValid": false
}

/convertToJS

Request

POST request with plain text body like (defun max (v1 v2) (if (> v1 v2) v1 v2))

Possible Responses

{
    "js": "function max(v1, v2) {\n  if ((v1 > v2)) {\n    return v1\n  }\n  return v2\n}"
}
{
  "js": "Not Valid Lisp"
}

lisptojs's People

Contributors

guseyn avatar

Stargazers

 avatar

Watchers

James Cloos avatar  avatar  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.