trying out new arrows for function literals -> is a function, => is a bound function

This commit is contained in:
Jeremy Ashkenas
2010-01-26 10:52:05 -05:00
parent 55df898112
commit a9f016e292
54 changed files with 259 additions and 259 deletions

View File

@@ -2,7 +2,7 @@
# The implementation of binary search that is tested.
# Return the index of an element in a sorted list. (or -1, if not present)
index: (list, target) =>
index: (list, target) ->
[low, high]: [0, list.length]
while low < high
mid: (low + high) >> 1

View File

@@ -1,7 +1,7 @@
# Beautiful Code, Chapter 3.
# Produces the expected runtime of Quicksort, for every integer from 1 to N.
runtime: (N) =>
runtime: (N) ->
[sum, t]: [0, 0]
for n in [1..N]
sum += 2 * t

View File

@@ -3,7 +3,7 @@
# '.', '^', '$', and '*'.
# Search for the regexp anywhere in the text.
match: (regexp, text) =>
match: (regexp, text) ->
return match_here(regexp.slice(1), text) if regexp[0] is '^'
while text
return true if match_here(regexp, text)
@@ -11,7 +11,7 @@ match: (regexp, text) =>
false
# Search for the regexp at the beginning of the text.
match_here: (regexp, text) =>
match_here: (regexp, text) ->
[cur, next]: [regexp[0], regexp[1]]
if regexp.length is 0 then return true
if next is '*' then return match_star(cur, regexp.slice(2), text)
@@ -20,7 +20,7 @@ match_here: (regexp, text) =>
false
# Search for a kleene star match at the beginning of the text.
match_star: (c, regexp, text) =>
match_star: (c, regexp, text) ->
while true
return true if match_here(regexp, text)
return false unless text and (text[0] is c or c is '.')