Last active
August 29, 2015 14:07
-
-
Save iamblue/6a66945bfd527e117e94 to your computer and use it in GitHub Desktop.
livescript basic language
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# var xs = [1,2,3] | |
# doubleMe(doubleMe(doubleMe(xs))) | |
#這樣寫法有很多缺點,太多層次要把全部層次讀完才能知道最後結果。 | |
#在墮性語言之中 | |
#我們要做到調用 doubleMe 時並不會立即求值,它會說“嗯嗯,待會兒再做!” | |
#在真正執行時只會是一個平面,像 xs *2 *2 *2; | |
(a, b, c) --> a * b * c | |
#代替了 | |
(a) -> (b) -> (c) -> a * b * c | |
#舉例 | |
#var times = function(x) { | |
# return function(y) { | |
# return x*y; | |
# } | |
#} | |
#console.log(time(2)(3)) // 6 | |
times = (x, y) --> x * y | |
times 2, 3 #=> 6 (参数足够时是一个普通的函数,返回计算后的结果) | |
double = times 2 #参数不够时,会返回一个部分应用函数.相当于JavaScript中的double = times.bind(null,2) | |
double 5 #=> 10 (相当于times(2)(5)) | |
look at p.69 | |
http://www.slideshare.net/ihower/fp-osdc2012v2 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment