-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.html
654 lines (527 loc) · 17.8 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
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>LiveScript talk</title>
<meta name="description" content="LiveScript talk at Functional Programmers Paris Meetup, November 26th 2013">
<meta name="author" content="NEWTON" >
<meta name="apple-mobile-web-app-capable" content="yes" />
<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
<link rel="stylesheet" href="css/reveal.min.css">
<link rel="stylesheet" href="css/theme/sky.css" id="theme">
<!-- For syntax highlighting -->
<link rel="stylesheet" href="lib/css/zenburn.css">
<!-- If the query includes 'print-pdf', use the PDF print sheet -->
<script>
document.write( '<link rel="stylesheet" href="css/print/' + ( window.location.search.match( /print-pdf/gi ) ? 'pdf' : 'paper' ) + '.css" type="text/css" media="print">' );
</script>
<!--[if lt IE 9]>
<script src="lib/js/html5shiv.js"></script>
<![endif]-->
</head>
<body>
<div class="reveal">
<!-- Any section element inside of this container is displayed as a slide -->
<div class="slides">
<section>
<h1>LiveScript presentation</h1> <br />
<h3>by <a href="http://www.sportzinteractive.net/"> Ankit Shukla && Aun Rizvi</a></h3>
<!--
<h3><a href="http://twitter.com/Dj3bbZ">@Dj3bbZ</a></h3>
-->
</section>
<!--
<section>
<h3>We Are ?</h3>
<img src="s.jpg" alt="">
</section>
-->
<section>
<h3>We work On JavaScript </h3>
<img src="r.jpg" alt="">
</section>
<section>
<h2>Javascript Again ?</h2>
<img src="js.jpg" alt="Javascript is a slut" width="500" height="600">
<!-- <p>Who knows/doesn't know it ?</p>
<p><small>Used it in prod, I mean</small></p>
<p>What do you think about it ?</p>-->
</section>
<section>
<h2>A TRIP DOWN MEMORY LANE...</h2><br/>
<ul>
<li><a href="http://www.oreillynet.com/pub/a/javascript/2001/04/06/js_history.html">Created by Brendan Eich Netscape 1995</a></li>
<a href="http://www.computer.org/csdl/mags/co/2012/02/mco2012020007.html">In <em>10 days !</em></a>
<br />
♥ Had to look like Java
♥ Be dynamic
<br />
♥ Have objects without classes <br
<br /> ♥ Scheme functional side
<br /> ♥ Self object side (prototype-based objects)
</section>
<section>
<h2>Problems with Javascript</h2>
<a href="http://coding.smashingmagazine.com/2011/05/30/10-oddities-and-secrets-about-javascript/">1. JavaScript sucks</a></li> :
The depths to which JavaScript sucks is well-documented and well-understood.<br />
<a href = "http://www.haskell.org/haskellwiki/The_JavaScript_Problem">2. We need JavaScript</a> : Using it for what it is good for, i.e. providing a platform for browser development.
<br />
<!-- <a href="http://www.crockford.com/javascript/javascript.html">The World's Most Misunderstood Programming Language</a><em>
- Douglas Crockford</em>
-->
<aside class="notes">Lisp in C clothing ; community recently understood its functional power</aside>
</section>
<section>
<h2>The functional side of Javascript</h2>
<ul>
<li>Functions as first-class citizens</li>
<li><code>map</code>, <code>reduce</code> and <code>filter</code> only recently arrived in the language</li>
<li>But not available in all browsers <a href="http://kangax.github.io/es5-compat-table/#ie9">(IE <= 8)</a></li>
<li>Where's the rest ?</li>
</ul>
</section>
<section>
<h2><a href="http://underscorejs.org/">Underscore.js</a> ?</h2>
<ul>
<li><q cite="">"is a utility-belt library for JavaScript that provides a lot of the functional programming support [...] "</q></li>
<li>Cross-browser<sup>*</sup></li>
<li>The "Most Depended Upon" lib on <a href="https://npmjs.org/">npm</a></li>
</ul>
<pre><code data-trim contenteditable>
_.map, _.reduce, _.pluck, _.debounce, _.memoize
// lot of goodies inside
</code></pre>
<small style="margin-top:50px;"><sup>*</sup> : Almost, its fork <a href="http://lodash.com/">Lo-Dash</a> is better.</small>
</section>
<section>
<h2>Underscore, but...</h2>
<ul>
<li>Not that functional : currying ? order of arguments ? composition ? extensibility ?
Check this <a href="http://www.youtube.com/watch?v=m3svKOdZijA">talk</a> (and the <a href="http://www.slideshare.net/drboolean/underscore-18211797">slides</a>)</li>
</ul>
<pre><code>
_.curry() // doesn't exist, even though _.partial exists
_.map(collection, fun) // why not the opposite order ?
_.compose(*functions) // not that useful because of previous points
</code></pre>
</section>
<section>
<h2>CoffeeScript, maybe ?</h2>
<ul>
<li>Very popular language that compiles to Javascript</li>
<li>Same semantics with syntactic sugar</li>
<li><a href="http://www.infoq.com/news/2013/03/Language-Expressiveness">One of the most expressive general-purpose language</a>, along with Haskell and Clojure</li>
</ul>
<pre><code data-trim contenteditable>
# CoffeeScript
f = (a, b) ->
a + b
</code></pre>
<pre><code>// Resulting Javascript
var f = function(a, b) {
return a + b;
};
</code></pre>
<p>Tries to push a more functional style, but doesn't go far enough...</p>
<aside class="notes" data-markdown>
Some CoffeeScript's features :
- all functions return their last statement
- almost everything is an expression
- for comprehensions
- default arguments
- object desctructuring
- sugar for classes (bof...)
</aside>
</section>
<section>
<h2>Enter LiveScript</h2>
<ul>
<a href="http://livescript.net/" > <li>LiveScript is a fork of Coco </li></a>
<li>An indirect descendant of CoffeeScript</li>
<li>Mostly compatible</li>
<li>Inspired mainly by Haskell and F# , with a bit of LISP</li>
<li>Full of functional idioms</li>
</ul>
</section>
<section>
<h2>Features highlight</h2>
<h4>Personal selection. LiveScript has *A LOT*</h4>
<ul>
<li>Easy currying</li>
<li>Partial application</li>
<li>Function composition</li>
<li>Pipes ! Unix/F#-like</li>
<li>Pattern matching</li>
<li>Backcalls</li>
<li>Prelude.ls : an underscore-like shipped with LiveScript, very rich</li>
</ul>
</section>
<section>
<h2>Similarity Comparison</h2><br />
<a href= "http://coffeescript.org/">CoffeeScript</a> : Python ::<a href="http://www.typescriptlang.org/" > TypeScript</a> : OCaml
<br />
<br />
<a href="http://livescript.net/">LiveScript</a> : Haskell :: <a href="http://redscript.org/" > RedScript</a> : Ruby
</section>
<section>
<h2>Show me the code, dude!</h2>
<img src="meme.png" alt="'Hello World', I'm a fucking genius" width="650" height="500">
</section>
<section>
<h3>Easy currying of user-defined functions</h3>
<pre><code>
# No currying
f = (a, b) -> a + b
# Easy currying, with double arrow -->
f = (a, b) --> a + b
g = f 1 # curried f
g 2 # → 3
</code></pre>
</section>
<section>
<h3>Partial application</h3>
<h4>A.k.a how to solve one of Underscore's problems</h4>
<pre><code>
# using _ as a placeholder argument for data
# Operators as functions (yes!)
biggerThanThree = _.map _, (> 3)
# [1 2 3 4 5] will be used in place of _
biggerThanThree [1 2 3 4 5] // → [true,true,false,false,false]
</code></pre>
</section>
<section>
<h3>Function composition</h3>
<p><small>yes!</small></p>
<pre><code>
# Forward composition
add-two-times-two = (+ 2) >> (* 2)
add-two-times-two 3 # → (3+2)*2 → 10
# Backward composition
times-two-add-two = (+ 2) << (* 2)
times-two-add-two 3 # → (3*2)+2 → 8
# Haskell style, equivalent to <<
times-two-add-two = (+ 2) . (* 2)
</code></pre>
<aside class="notes">
Le highlighter ne fonctionne pas encore avec LiveScript, un patch est en cours
</aside>
</section>
<section>
<h3>Pipes !</h3>
<h4>Unix/F# style. Avoids nesting calls</h4>
<pre><code>
# (.length) is a shortcut to access property
[1 2 3] |> filter (> 2) |> (.length) # → 1
</code></pre>
</section>
<section>
<h3>Pattern matching</h3>
<pre><code>
# empty function from Prelude.ls (coming after)
# Guard syntax (|) translates to switch in JS
sum = ([x, ...xs]:list) ->
| empty list => 0
| empty xs => x
| otherwise => x + sum xs
</code></pre>
<aside class="notes">
Est-ce vraiment du pattern matching ?
</aside>
</section>
<section>
<h3>Bound functions</h3>
Bound functions have this lexically bound, not dynamically bound as normally.
<pre><code>
- obj = new
- @x = 10
- @normal = -> @x
- @bound = ~> @x
-
- obj2 = x: 5
- obj2.normal = obj.normal
- obj2.bound = obj.bound
-
- obj2.normal! #=> 5
- obj2.bound! #=> 10
</code></pre>
</section>
<section>
<h3>Backcalls</h3>
<h4>A way to avoid pyramid of callbacks in async programming</h4>
<pre><code>
x <- map _, [1 to 3]
x * 2
# → [2,4,6]
# Translates to
map(function(x){
return x * 2;
}, [1, 2, 3]);
# the ! suppresses the return of the function
data <-! $.get 'my-ajax-url.com'
$ '.result' .html data
</code></pre>
</section>
<section>
<h3>Improved scoping</h3>
= Always declares variable in current scope, use := for redeclaration of outer scope variables
<pre><code>
x = 1
y = 1
do ->
x = 2
y := 2
x #=> 1
y #=> 2
</code></pre>
</section>
<!--
<section>
<h3>Real Design Choices</h3>
JS '==' in LiveScript is '~=', and '===' enables
object and array comparisons, and also stricter comparison
<pre><code>
2 == "2" # => false
2 ~= "2" # => true
[1,2,3] == [1,2,3] # => false
[1,2,3] === [1,2,3] # => true
</code></pre>
Functions which take no arguments are called<br />
with a bang!
<pre><code> two = -> 2
two!
</code></pre>
</section>
-->
<!--
<section>
<h3>Design Choice</h3>
A function may be curried by using a long arrow rather than a short one ;
<pre><code>
add = (left, right) -- left + right
add1 = add 1
add1 2 # => 3
</code></pre>
You could use it to clone a particular argument to avoid side-effects :
<pre><code>
copy = (^^target, source) ->
for k,v of source => target[k] = v
target
a = { a: 1 }
copy a, { b: 2 } # => { a: 1, b: 2 }
a # => { a: 1 }
</code></pre>
</section>
-->
<section>
<h3>Prelude.ls</h3>
<h4>The missing Javascript API's, shipped with LiveScript</h4>
What you would expect from a functional language
<pre><code># 60+ functions for arrays
head, first, tail, last, compact, partition, concat, <br />
intersection, scan, take-while, zip, ...
# ~15 functions for objects (maps)
keys, values, pairs-to-obj, reject, find, ...
# ~20 functions for strings
split, join, words, unwords, reverse, repeat, ...
# 30+ functions for Math (yes!)
min, max, tau, odd, even, quot, rem, sin, signum, is-it-NaN
# of course, functions functions
apply, curry, flip, fix
</code></pre>
</section>
<section>
<h3><a href ="http://preludels.com/"> Prelude.ls</a> </h3>
<ul>
<li>Easy to install : <code>npm install -g livescript</code></li>
<li>Has a CLI and a REPL : <code>lsc</code> or <code>livescript</code></li>
</ul><br />
<br /><a href="http://preludels.com/"> It is powerful and flexible</a><br />
<!--
<pre><code>
[1 to 5] |> map (^2) |> filter even |> fold (+), 0
#=> 20
</code></pre>-->
Almost all of its functions are curried.
<pre><code>
fold (+), 0, [1 2 3] #=> 6
sum = fold (+), 0
sum [1 2 3] #=> 6
sum [4 5 6] #=> 15
</code></pre>
</section>
<section>
<h3> Redscript </h3>
# Block-like anonymous functions
<pre><code>
app.get '/users/:name', do |res, req|
puts req.params.name
end
</code></pre>
# Make constructors quack like a duck
<pre><code>
class Duck < Animal
def init(name)
super foo, bar
@name = name
end,
def sayHi
puts 'Hello!'
end
end
</code></pre>
</section>
<section>
<h3>Laziness is the mother of nine inventions out of ten.</h3>
<img src="f.jpg" alt="">
</section>
<section>
<h3><a href="http://danieltao.com/lazy.js/"> Lazy.js</a></h3>
Lazy.js it a utility library for JavaScript,
similar to Underscore and Lo-Dash but with one important difference: " Lazy evaluation " .
<img src="l.png" alt="">
</section>
<section>
<h3><a href="http://danieltao.com/lazy.js/docs/"> A different paradigm</a></h3>
<i> Core of Lazy.js is function composition <br /></i>
Array transformation :
<pre><code>
f ( [x , y , ...] ) → [ x', y', ...]
</code></pre>
</section>
<section>
<h3><a href="http://www.haskell.org/haskellwiki/MapReduce_as_a_monad"> Map</a></h3>
map from Underscore:
<pre><code>
var array1 = [1, 2, 3, 4, 5];
var array2 = _.map(array1, function(x) { return x + array1.length; });
</code></pre>
map from Lazy.js
<pre><code>
var array = [1, 2, 3, 4, 5];
var sequence = Lazy(array).map(function(x) { return x + array.length;});
</code></pre>
</section>
<section>
<h3>Asynchronous iteration</h3>
<pre><code>
var asyncSequence = Lazy(array)
.async(100) // specifies a 100-millisecond interval between each element
.map(inc)
.filter(isEven)
.take(20);
</code></pre>
<pre><code>
// This function returns immediately and begins iterating
over the sequence asynchronously.
asyncSequence.each(function(e) {
console.log(new Date().getMilliseconds() + ": " + e);
});
</code></pre>
</section>
<section>
Array containing 1000 integers
<pre><code>
var array = Lazy.range(1000).toArray();
</code></pre>
Do things and take first 5 results :
<pre><code>
function square(x) { return x * x; }
function inc(x) { return x + 1; }
function isEven(x) { return x % 2 === 0; }
</code></pre>
</section>
<section>
<h3> Underscore way : </h3>
<pre><code>
var result = _.chain(array).map(square).map(inc).filter(isEven).take(5).value();
</code></pre>
<pre><code>
map(square): Iterates over the array & creates
a new 1000-element array
map(inc): Iterates over the new array,creating
another new 1000-element array
filter(isEven): Iterates over that array,creating
yet another new (500-element) array
take(5): All that just for 5 elements!
</code></pre>
</section>
<section>
<h3>Escape route :</h3>
For Performance and/or efficiency , go the procedural route
<pre><code>
var results = [];
for (var i = 0; i < array.length; ++i) {
var value = (array[i] * array[i]) + 1;
if (value % 2 === 0) {
results.push(value);
if (results.length === 5) {
break;
}
}
}
</code></pre>
</section>
<section>
<h3>Lazyjs time !</h3>
<pre><code>
var result = Lazy(array).map(square).map(inc).filter(isEven).take(5);
</code></pre>
No iteration takes place until you call each, and no intermediate arrays are created.
</section>
<!--
<section>
<h3>Examples</h3>
<pre><code>
var Lazy = require('lazy');
var lazy = new Lazy;
lazy
.filter(function (item) {
return item % 2 == 0
})
.take(5)
.map(function (item) {
return item*2;
})
.join(function (xs) {
console.log(xs);
});
</code></pre>
<p>Emit 'data' events with data in them at some point later.</p>
<pre><code>
[0,1,2,3,4,5,6,7,8,9,10].forEach(function (x) {
lazy.emit('data', x);
});
</code></pre>
</section>
-->
<section>
<h2>That's all folks !</h2>
<h3>Questions ?</h3>
<img src="j.jpg" alt="'Hello World', I'm a fucking genius" width="700" height="480">
</section>
</div>
</div>
<script src="lib/js/head.min.js"></script>
<script src="js/reveal.min.js"></script>
<script>
Reveal.initialize({
controls: true,
progress: true,
history: true,
center: true,
theme: Reveal.getQueryHash().theme, // available themes are in /css/theme
transition: Reveal.getQueryHash().transition || 'default', // default/cube/page/concave/zoom/linear/fade/none
// Optional libraries used to extend on reveal.js
dependencies: [
{ src: 'lib/js/classList.js', condition: function() { return !document.body.classList; } },
{ src: 'plugin/markdown/marked.js', condition: function() { return !!document.querySelector( '[data-markdown]' ); } },
{ src: 'plugin/markdown/markdown.js', condition: function() { return !!document.querySelector( '[data-markdown]' ); } },
{ src: 'plugin/highlight/highlight.js', async: true, callback: function() { hljs.initHighlightingOnLoad(); } },
{ src: 'plugin/zoom-js/zoom.js', async: true, condition: function() { return !!document.body.classList; } },
{ src: 'plugin/notes/notes.js', async: true, condition: function() { return !!document.body.classList; } }
]
});
</script>
</body>
</html>