Skip to content

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also .

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also .
...
  • 2 commits
  • 2 files changed
  • 0 commit comments
  • 1 contributor
Showing with 36 additions and 32 deletions.
  1. +22 −20 README.md
  2. +14 −12 index.html
View
42 README.md
@@ -14,8 +14,8 @@ write code in a tree structure.
## Hello World! in LispyScript.
-```lisp
-(console.log "Hello LispyScript!")
+```clojure
+(.log console "Hello LispyScript!")
```
A LispyScript program is made up of expressions in parenthesis. The first
@@ -26,7 +26,7 @@ LispyScript.
A more intricate Hello World!
-```lisp
+```clojure
(if (undefined? window)
(.log console "Hello LispyScript!")
(alert "Hello LispyScript!"))
@@ -38,13 +38,13 @@ You can have expressions within expressions.
An anonymous function in LispyScript.
-```lisp
+```clojure
(function [x] (* x x))
```
The first element in an expression can be an anonymous function.
-```lisp
+```clojure
((function [x] (* x x)) 2)
```
@@ -53,7 +53,7 @@ Functions return the last expression evaluated within the function.
You can set a variable name to a function.
-```lisp
+```clojure
(var square
(function [x]
(* x x)))
@@ -67,7 +67,7 @@ value to the third.
All Javascript functions, objects and literals can be used in LispyScript.
-```lisp
+```clojure
(.call Array.prototype.forEach (Array 1 2 3)
(function [elem index list]
(.log console elem)))
@@ -79,7 +79,7 @@ instead.
You can access object methods and properties using the ".-" notation.
-```lisp
+```clojure
(.log console (.-greet { greet: "hello" }))
```
@@ -89,25 +89,27 @@ property.
You can also use the 'get' expression to access a property of an object.
-```lisp
+```clojure
(.log console (get "greet" { greet: "hello" }))
(.log console (get (Array 1 2 3) 1))
```
You can 'set' variables too.
-```lisp
+```clojure
(set! window.onload (function [] (alert "Page Loaded")))
```
The node server example in LispyScript.
-```lisp
+```clojure
(def http (require "http"))
(def server
- (.createServer http
+ ;; Note: Conventional dash-dilimited lispy style traslates to
+ ;; convetional camelCase style in JS (P.S. you can use cameCase too).
+ (.create-server http
(function [request response]
- (.writeHead response 200 { "Content-Type": "text/plain" })
+ (.write-head response 200 { "Content-Type": "text/plain" })
(.end response "Hello World\n"))))
(.listen server 1337 "127.0.0.1")
(.log console "Server running at http://127.0.0.1:1337/")
@@ -122,7 +124,7 @@ support macros.
You can define a macro.
-```lisp
+```clojure
(defmacro array? [value]
`(= (.call Object.prototype.toString ~value) "[object Array]"))
```
@@ -133,7 +135,7 @@ element, and the fourth element is the template to which the macro will expand.
Now let us create a Lisp like `let` macro in LispyScript:
-```lisp
+```clojure
(defmacro let (names vals & body)
`((function ~names ~@body) ~@vals))
@@ -197,7 +199,7 @@ Note: `=` and `!=` work like `===` and `!==` in Javascript.
Adds up all the strings.
-```lisp
+```clojure
(var title "My Home Page")
(console.log
(str "<!DOCTYPE html>
@@ -248,7 +250,7 @@ not work in old browsers. For backwards compatibility use a library like
The above example using underscore.js.
-```lisp
+```clojure
(var _ (require 'underscore'))
(.each _ (Array 1 2 3)
(function (elem index list)
@@ -279,8 +281,8 @@ Try takes a set of expressions and evaluates them. The last expression must be
a function, that will be called in case an exception is thrown. The function is
called with the error object.
-```lisp
-(def fs (require 'fs'))
+```clojure
+(def fs (require "fs"))
(def outfile "text.txt")
(try
(.writeFileSync fs outfile "Hello World")
@@ -291,7 +293,7 @@ called with the error object.
### (template (argument expression) (string expressions) ... )
-```lisp
+```clojure
(var link
(template [data]
"<li><a href=" (.href data) ">" (.text data) "</a></li>\n"))
View
26 index.html
@@ -58,44 +58,46 @@
; Functions
;; An anonymous function in LispyScript
-(function (x) (* x x))
+(function [x] (* x x))
;; The first element in an expression can be an anonymous function.
-((function (x) (* x x)) 2)
+((function [x] (* x x)) 2)
;; You can set a variable name to a function.
(var square
- (function (x)
+ (function [x]
(* x x)))
(.log console (square 10))
; LispyScript is Javascript!
(Array.prototype.forEach.call (Array 1 2 3)
- (function (elem index list)
+ (function [elem index list]
(.log console elem)))
;; You can access object methods and properties using the ".-" notation.
-(.log console (.-greet {greet: "hello"}))
+(.log console (.-greet { greet: "hello" }))
;; You can also use the 'get' expression to access a property of an object.
-(.log console (get {greet: "hello"} "greet"))
+(.log console (get { greet: "hello" } "greet"))
(.log console (get (Array 1 2 3) 1))
;; You can 'set' variables too.
-(set! window.onload (function () (alert "Page Loaded")))
+(set! window.onload (function [] (alert "Page Loaded")))
; Node
;; The node server example in LispyScript.
(def http (require "http"))
(def server
- (.createServer http
+ ;; Note: How conventional dash-dilimited lispy style traslates to
+ ;; convetional camelCase style in JS (P.S. you can use cameCase too)
+ (.create-server http
(function [request response]
- (.writeHead response 200 { "Content-Type": "text/plain" })
+ (.write-head response 200 { "Content-Type": "text/plain" })
(.end response "Hello World\n"))))
(.listen server 1337 "127.0.0.1")
(.log console "Server running at http://127.0.0.1:1337/")
@@ -118,7 +120,7 @@
;; Conditions
-(if (= document.readyState "complete")
+(if (= document.ready-state "complete")
(.log console "loaded") ;; true expression
(.log console "loading")) ;; optional false expression
@@ -141,10 +143,10 @@
;; Exception handling
-(var fs (require 'fs'))
+(var fs (require "fs"))
(var outfile "text.txt")
(try
- (.writeFileSync fs outfile "Hello World")
+ (.write-file-sync fs outfile "Hello World")
(function (e)
(.log console (+ "Cannot write file " outfile)
(.exit process 1))))

No commit comments for this range

Something went wrong with that request. Please try again.