Commit | Line | Data |
---|---|---|
a9993e0a JM |
1 | <!-- |
2 | Copyright (c) 2014 Joel Martin | |
3 | Copyright (c) 2012 Fogus, Jen Myers and Relevance Inc. | |
4 | All rights reserved. The use and distribution terms for this software | |
5 | are covered by the Eclipse Public License 1.0 | |
6 | (http://opensource.org/licenses/eclipse-1.0.php) which can be found in | |
7 | the file COPYING the root of this distribution. By using this | |
8 | software in any fashion, you are agreeing to be bound by the terms of | |
9 | this license. You must not remove this notice, or any other, from | |
10 | this software. | |
11 | --> | |
12 | ||
31690700 | 13 | <html> |
a9993e0a JM |
14 | <head> |
15 | <link rel="stylesheet" type="text/css" href="js/web/base.css" /> | |
16 | <link rel="stylesheet" type="text/css" href="js/web/layout.css" /> | |
17 | <link rel="stylesheet" type="text/css" href="js/web/skeleton.css" /> | |
18 | <link rel="stylesheet" type="text/css" href="js/web/himera.css" /> | |
19 | <link rel="stylesheet" type="text/css" href="js/web/ansi.css" /> | |
20 | <link rel="stylesheet" type="text/css" href="js/web/console.css" /> | |
21 | <style type="text/css" media="screen"> | |
22 | </style> | |
23 | <title>Mal Web RELP</title> | |
24 | </head> | |
25 | <body> | |
26 | <div class="container"> | |
27 | <h1 id="title"><a href="https://github.com/kanaka/mal"/>Mal</a></h1> | |
28 | ||
29 | <h2>Mal Web REPL</h2> | |
31690700 | 30 | |
a9993e0a JM |
31 | <!-- |
32 | <div id="editor-container" class="sixteen columns"> | |
33 | <div id="tiny-note" class="tiny-note"></div> | |
34 | <textarea class="editor" id="editor">;; Develop your Mal program here. | |
35 | ;; Ctrl+E/Cmd+E evaluates file in the REPL.</textarea> | |
36 | </div> | |
37 | --> | |
38 | ||
39 | <div id="console-container" class="sixteen columns"> | |
40 | <div class="console" id="console"></div> | |
41 | </div> | |
42 | <div class="eight columns"> | |
43 | <!-- | |
44 | <h3><span style="cursor: pointer" class="doc-link" id="toggle-editor">Show file editor</span></h3> | |
45 | --> | |
46 | <h3><span style="cursor: pointer" class="doc-link"> </span></h3> | |
47 | </div> | |
48 | <div class="eight columns"> | |
49 | <div class="source"> | |
50 | <a href="http://github.com/kanaka/mal">View source on Github <img src="js/web/github-icon.png" /></a></p> | |
51 | </div><!-- /source --> | |
52 | </div> | |
53 | ||
54 | <div class="rule sixteen columns"></div> | |
31690700 | 55 | |
a9993e0a JM |
56 | <div class="sixteen columns"> |
57 | <h3>Mal at a glance</h3> | |
58 | </div> | |
59 | ||
60 | <div class="cheat-box-container eight columns"> | |
61 | <div class="cheat-box"> | |
62 | <h4>Datatypes</h4> | |
63 | <table> | |
64 | <tr class="row-one"> | |
65 | <td class="row-label">Maps</td> | |
66 | <td>{"key1" "val1", "key2" 123}</td> | |
67 | </tr> | |
68 | <tr class="row-one"> | |
69 | <td class="row-label">Lists</td> | |
70 | <td>(1 2 3 "four")</td> | |
71 | </tr> | |
72 | <tr> | |
73 | <td class="row-label">Vectors</td> | |
74 | <td>[1 2 3 4 "a" "b" "c" 1 2]</td> | |
75 | </tr> | |
76 | <tr> | |
77 | <td class="row-label">Scalars</td> | |
78 | <td>a-symbol, "a string", 123, nil, true, false</td> | |
79 | </tr> | |
80 | </table> | |
81 | </div><!-- /cheat-box --> | |
82 | <div class="cheat-box"> | |
83 | <h4>Functions</h4> | |
84 | <table> | |
85 | <tr class="row-one"> | |
86 | <td class="row-label">Calling</td> | |
87 | <td>(<span class="ebnf"><function></span> | |
88 | <span class="ebnf"><args*></span>)</td> | |
89 | </tr> | |
90 | <tr> | |
91 | <td class="row-label">Defining named functions</td> | |
92 | <td>(def! <span class="ebnf"><name></span> | |
93 | (fn* | |
94 | [<span class="ebnf"><args*></span>] | |
95 | <span class="ebnf"><action*></span>))</td> | |
96 | </tr> | |
97 | <tr class="row-one"> | |
98 | <td class="row-label">Anonymous function</td> | |
99 | <td>(fn* <span class="ebnf">|name|</span> | |
100 | [<span class="ebnf"><args*></span>] | |
101 | <span class="ebnf"><action*></span>)</td> | |
102 | </tr> | |
103 | </table> | |
104 | </div><!-- /cheat-box --> | |
105 | <div class="cheat-box"> | |
106 | <h4>Useful Macros and Special Forms</h4> | |
107 | <table> | |
108 | <tr class="row-one"> | |
109 | <td class="row-label">Conditionals</td> | |
110 | <td>if cond or</td> | |
111 | </tr> | |
112 | <!-- | |
113 | <tr> | |
114 | <td class="row-label">Nesting, chaining, and Interop</td> | |
115 | <td>-> ->> doto .. .</td> | |
116 | </tr> | |
117 | --> | |
118 | <tr> | |
119 | <td class="row-label">Multiple Actions (side-effects)</td> | |
120 | <td>(do | |
121 | <span class="ebnf"><action*></span>...)</td> | |
122 | </tr> | |
123 | <tr class="row-one"> | |
124 | <td class="row-label">Defining things</td> | |
125 | <td>def! defmacro! let*</td> | |
126 | </tr> | |
127 | </table> | |
128 | </div> | |
129 | </div><!-- /cheat-box-container --> | |
31690700 | 130 | |
a9993e0a JM |
131 | <div class="cheat-box-container eight columns"> |
132 | <div class="cheat-box"> | |
133 | <h4>Useful Functions</h4> | |
134 | <table> | |
135 | <tr class="row-one"> | |
136 | <td class="row-label">Math</td> | |
137 | <td>+ - * /</td> | |
138 | </tr> | |
139 | <tr> | |
140 | <td class="row-label">Comparison/Boolean</td> | |
141 | <td>= < > <= >= not</td> | |
142 | </tr> | |
143 | <tr class="row-one"> | |
144 | <td class="row-label">Predicates</td> | |
145 | <td>nil? true? false? symbol? list? vector? map? sequential?</td> | |
146 | </tr> | |
147 | <tr> | |
148 | <td class="row-label">Data processing</td> | |
149 | <td>map apply</td> | |
150 | </tr> | |
151 | <tr class="row-one"> | |
152 | <td class="row-label">Data create</td> | |
153 | <td>list vector hash-map</td> | |
154 | </tr> | |
155 | <tr> | |
156 | <td class="row-label">Data inspection</td> | |
157 | <td>first rest get keys vals count get nth contains? empty?</td> | |
158 | </tr> | |
159 | <tr class="row-one"> | |
160 | <td class="row-label">Data manipulation</td> | |
161 | <td>conj cons concat assoc dissoc</td> | |
162 | </tr> | |
163 | <tr> | |
164 | <td class="row-label">Lists and Vectors</td> | |
165 | <td>first rest nth</td></td> | |
166 | </tr> | |
167 | <tr class="row-one"> | |
168 | <td class="row-label">Hash Maps</td> | |
169 | <td>get keys vals contains?</td></td> | |
170 | </tr> | |
171 | </table> | |
172 | </div><!-- /cheat-box --> | |
173 | <div class="cheat-box"> | |
174 | <h4>JavaScript Interop</h4> | |
175 | <table> | |
176 | <tr class="row-one"> | |
177 | <td class="row-label">Evaluate JavaScript</td> | |
178 | <td>(js* "JS string to eval")</td> | |
179 | </tr> | |
180 | <tr> | |
181 | <td class="row-label">Method call/access</td> | |
182 | <td>(. js-fn arg...)</td> | |
183 | </tr> | |
184 | </table> | |
185 | </div> | |
186 | </div><!-- /cheat-box-container --> | |
187 | ||
188 | <div class="rule sixteen columns"></div> | |
189 | ||
190 | <div class="column footer-logo"> | |
191 | <div>Mal © 2013 Joel Martin</div> | |
192 | <div>Himera design © 2012-2013 <a ref="http://www.fogus.me">Fogus</a>, <a href="http://jenmyers.net/">Jen Myers</a> and <a href="http://www.thinkrelevance.com">Relevance Inc.</a></div> | |
193 | </div> | |
194 | ||
195 | </div><!-- / container --> | |
196 | <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script> | |
197 | <script type="text/javascript" src="js/web/jqconsole.min.js"></script> | |
198 | <script type="text/javascript" src="js/web/mal.js"></script> | |
199 | <script> | |
200 | $(function() { | |
201 | // Creating the console. | |
202 | window.jqconsole = $('#console').jqconsole(null, 'user> '); | |
203 | ||
204 | printer.println = function () { | |
205 | var str = Array.prototype.join.call(arguments, " ") | |
206 | jqconsole.Write(str + "\n", 'jqconsole-output'); | |
207 | } | |
208 | ||
209 | rep("(println (str \"Mal [\" *host-language* \"]\"))"); | |
210 | ||
b58698b2 JM |
211 | jq_load_history(jqconsole); |
212 | ||
a9993e0a JM |
213 | // Abort prompt on Ctrl+C. |
214 | jqconsole.RegisterShortcut('C', function() { | |
215 | jqconsole.AbortPrompt(); | |
216 | handler(); | |
217 | }); | |
218 | // Move to line start Ctrl+A. | |
219 | jqconsole.RegisterShortcut('A', function() { | |
220 | jqconsole.MoveToStart(); | |
221 | handler(); | |
222 | }); | |
223 | // Move to line end Ctrl+E. | |
224 | jqconsole.RegisterShortcut('E', function() { | |
225 | jqconsole.MoveToEnd(); | |
226 | handler(); | |
227 | }); | |
228 | jqconsole.RegisterMatching('{', '}', 'brace'); | |
229 | jqconsole.RegisterMatching('(', ')', 'paren'); | |
230 | jqconsole.RegisterMatching('[', ']', 'bracket'); | |
231 | jqconsole.RegisterMatching('"', '"', 'dquote'); | |
232 | // Handle a command. | |
233 | var handler = function(line) { | |
234 | if (line) { | |
235 | try { | |
236 | jqconsole.Write(rep(line) + '\n', 'jqconsole-return'); | |
237 | } catch (exc) { | |
238 | if (exc instanceof reader.BlankException) { return; } | |
239 | if (exc.stack) { | |
240 | jqconsole.Write(exc.stack + '\n', 'jqconsole-error'); | |
241 | } else { | |
242 | jqconsole.Write(exc + '\n', 'jqconsole-error'); | |
e4393504 JM |
243 | } |
244 | } | |
b58698b2 | 245 | jq_save_history(jqconsole); |
a9993e0a JM |
246 | } |
247 | jqconsole.Prompt(true, handler); | |
248 | /* | |
249 | jqconsole.Prompt(true, handler, function(command) { | |
250 | // Continue line if can't compile the command. | |
251 | try { | |
252 | Function(command); | |
253 | } catch (e) { | |
254 | if (/[\[\{\(]$/.test(command)) { | |
255 | return 1; | |
256 | } else { | |
257 | return 0; | |
e4393504 | 258 | } |
a9993e0a JM |
259 | } |
260 | return false; | |
261 | }); | |
262 | */ | |
263 | }; | |
31690700 | 264 | |
a9993e0a JM |
265 | // Initiate the first prompt. |
266 | handler(); | |
267 | }); | |
268 | </script> | |
269 | ||
270 | </body> | |
31690700 | 271 | </html> |