
So Yesterday I released the source code of a Lisp-like language called "LispLike" (Creativity runs in my blood) that transpiles to Javascript.
Why?
Because Why Not?
It helped me better understand the logic behind most scripting languages (including JavaScript itself). This helped me understand "recursion" better. Overall it was a good mental exercise.
The Language
This language is a combination of Javascript and Lisp. It's syntax is similar to Lisp but uses operators and dot notation similar to Javascript. Because it is transpiled to Javascript and uses dot notation, you can use methods and classes offered by Javascript. The Good thing is that you can use Lisp code highlighting, by saving the code with ".lisp" extension. To transpile it, just import "lispLike" function from the "transpiler.js" module and pass the LispLike code as a string and it will output the transpiled code.
Here is a Good Old "Hello World" example:
(;; Progam Begins(print"Hello world");; its how you do it in LispLike);; Program Ends
Javascript code:
console.log("Hello world")
Basic Maths
((print(+12(-56))))
Javascript Code:
console.log(1+2+5-6)
Variables
((letname"World")(print(+"Hello "name));; prints "Hello World"(=name"Universe")(print(+"Hello "name));; prints "Hello Universe")
Javscript code:
letname="World"console.log("Hello"+name)name="Universe"console.log("Hello"+name)
Functions
((defungreet(name)(do(print(+"Hello "name))(return"something")))(greet"World");; prints "Hello World"(greet"Universe");; prints "Hello Universe")
Javascript Code:
functiongreet(name){console.log("Hello"+name)return"something"}greet("World")greet("Universe")
Arrays and Foreach loop
((letnames(array"Ram""Shyam""Mohan"))(loopnames(keyvalue)(do(print(+"Hello "value)))));; output;; Hello Ram;; Hello Shyam;; Hello Mohan
Javscript Code:
letnames=["Ram","Shyam","Mohan"]names.forEach((value,key)=>{console.log("Hello"+value)})
While Loop
Apart from foreach loop, while loop is also available. "for" loop is not available yet.
(;; it prints numbers from 1 to 10(leti1)(while(<=i10)(do(printi)(+=i1))))
Javascript Code:
leti=1while(i<=10){console.log(i)i+=1}
If-Else Statement
((letage18)(if(<age18);; condition(do;; if block(print"You are below 18 years of age"))(;; else block(print"You age is 18 years or above"))))
Javascript Code:
letage=18if(age<18){console.log("You are below 18 years of age")}else{console.log("You age is 18 years or above")}
OOP
((defunStudent(namerollnocls)(do(=this.namename)(=this.rollnorollno)(=this.clscls)(=this.greet(defun(name)(do(print(+"Hello "name"!")))))))(letjohn(newStudent("John Doe"1234"High school")))(printjohn.name);; John Doe(john.greet"Joe");; Hello Joe!)
It gets transpiled to
functionStudent(name,rollno,cls){this.name=namethis.rollno=rollnothis.cls=clsthis.greet=function(name){console.log("Hello"+name+"!")}}letjohn=newStudent("John Doe",1234,"High school")console.log(john.name)john.greet("Joe")
Top comments(0)
For further actions, you may consider blocking this person and/orreporting abuse