-
Notifications
You must be signed in to change notification settings - Fork 57
/
index.html
236 lines (188 loc) · 6.7 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
<!DOCTYPE html>
<html lang="en">
<head>
<title>Try LispyScript</title>
<link href="../bootstrap/css/bootstrap.css" rel="stylesheet"/>
<style type="text/css">
body {
padding-top: 60px;
}
</style>
<link href="../bootstrap/css/bootstrap-responsive.css" rel="stylesheet"/>
<!-- Le HTML5 shim, for IE6-8 support of HTML5 elements -->
<!--[if lt IE 9]>
<script src='http://html5shim.googlecode.com/svn/trunk/html5.js'></script>
<![endif]-->
<script src="./lib/codemirror.js"></script>
<script src="./lib/scheme.js"></script>
<script src="./lib/javascript.js"></script>
<link rel="stylesheet" href="./lib/codemirror.css">
<script data-main="lib/browser" type="text/javascript" src="./lib/require.js"></script>
<script>
require.config({
paths: {
"underscore": "underscore-min"
},
shim: {
underscore: {
exports: '_'
}
}
})
</script>
<script type="application/lispyscript" src="./src/macros.ls"></script>
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-8490402-6']);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
</script>
</head>
<body>
<div class="navbar navbar-fixed-top">
<div class="navbar-inner">
<div class="container">
<a class="btn btn-navbar" data-toggle="collapse" data-target=".nav-collapse">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</a>
<a class="brand" href="#">LispyScript!</a>
<div class="nav-collapse">
<ul class='nav'>
<li>
<a href='../'>Home</a>
</li>
<li class='active'>
<a href='#'>Try It!</a>
</li>
<li>
<a href='../docs'>Docs</a>
</li>
<li>
<a href='http://lispyscript.blogspot.in/'>Blog</a>
</li>
<li>
<a href='https://github.com/santoshrajan/lispyscript'>View Source</a>
</li>
</ul>
</div>
</div>
</div>
</div>
<div class='container'>
<div class='page-header'>
<h1><img src="../images/logo32.png"/> Try LispyScript</h1>
<p>A javascript With Lispy Syntax And Macros!</p>
</div>
<div class='row'>
<div class='span6'>
<textarea id="input" name="input"">
;; Hello World! in LispyScript.
(console.log "Hello LispyScript!")
;; A more intricate Hello World!
(if (undefined? window)
(console.log "Hello LispyScript!")
(alert "Hello LispyScript!"))
; Functions
;; An anonymous function in LispyScript
(function (x) (* x x))
;; The first element in an expression can be an anonymous function.
((function (x) (* x x)) 2)
;; You can set a variable name to a function.
(var square
(function (x)
(* x x)))
(console.log (square 10))
; LispyScript is Javascript!
(Array.prototype.forEach.call [1, 2, 3]
(function (elem index list)
(console.log elem)))
;; You can access object methods and properties using the "." notation.
(console.log (.greet {greet: "hello"}))
;; You can also use the 'get' expression to access a property of an object.
(console.log (get "greet" {greet: "hello"}))
(console.log (get 1 [1, 2, 3]))
;; You can 'set' variables too.
(set window.onload (function () (alert "Page Loaded")))
; Node
;; The node server example in LispyScript.
(var http (require "http"))
(var server
(http.createServer
(function (request response)
(response.writeHead 200 {'Content-Type': 'text/plain'})
(response.end "Hello World\n"))))
(server.listen 1337 "127.0.0.1")
(console.log "Server running at http://127.0.0.1:1337/")
; Macros
;; You can define a macro.
(macro array? (obj)
(= (toString.call ~obj) "[object Array]"))
;; Now let us create a Lisp like 'let' macro in LispyScript.
(macro let (names vals rest...)
((function ~names ~rest...) ~@vals))
(let (name email tel) ("John" "john@example.org" "555-555-5555")
(console.log name)
(console.log email)
(console.log tel))
;; Conditions
(if (= document.readyState "complete")
(console.log "loaded") ;; true expression
(console.log "loading")) ;; optional false expression
;; Do expression
(if (= process.argv.length 2)
(do
(process.stdin.resume)
(process.stdin.setEncoding "utf8")
(compile process.stdin process.stdout (process.cwd))))
;; Each macro
(each [1, 2, 3]
(function (elem index list)
(console.log elem)))
;; Exception handling
(var fs (require 'fs'))
(var outfile "text.txt")
(try
(fs.writeFileSync outfile "Hello World")
(function (e)
(console.log (+ "Cannot write file " outfile)
(process.exit 1))))
</textarea>
</div>
<div class='span6'>
<textarea id="output" name="output"></textarea>
<script>
function updatePreview(editor) {
output.setValue(require('../lib/ls')._compile(editor.getValue()))
}
var input = CodeMirror.fromTextArea(document.getElementById("input"), {
lineNumbers: true,
mode: "scheme",
autofocus: true,
onChange: updatePreview
});
var output = CodeMirror.fromTextArea(document.getElementById("output"), {
lineNumbers: true,
mode: "javascript",
readOnly: "nocursor"
});
setTimeout(updatePreview, 1000, input)
</script>
</div>
</div>
<footer class="footer" style="margin-top: 45px; padding: 35px 0 36px;border-top: 1px solid #e5e5e5;">
<p class="pull-right"><a href="#">Back to top</a></p>
<p>Code licensed under the <a href="https://github.com/santoshrajan/lispyscript/blob/master/LICENSE" target="_blank">MIT License</a>. Documentation licensed under <a href="http://creativecommons.org/licenses/by/3.0/">CC BY 3.0</a>.</p>
<p>Logo Icon from <a href="http://www.designcontest.com">DesignContest</a>, licensed under <a href="http://creativecommons.org/licenses/by/3.0/">CC BY 3.0</a>.</p>
</footer>
</div>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"
type="text/javascript"></script>
<script type="text/javascript" src="../bootstrap/js/bootstrap.js"></script>
</body>
</html>