Permalink
...
Comparing changes
Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also .
Open a pull request
Create a new pull request by comparing changes across two branches. If you need to, you can also .
Choose a Base Repository
jashkenas/coffeescript
CDR2003/coffee-script-lua
CreamCoderz/coffee-script
Crylock/coffee-script
GeoffreyBooth/coffeescript
Gregg/coffee-script
JulianBirch/coffee-script-1
JustinTulloss/coffee-script
MichaelBlume/coffee-script
NightMigera/coffeescript
PandaWood/coffee-script
ProximaMonkey/coffee-script
Remcoman/coffee-script
RicardoSaracino/coffee-script
SE7ENSKY/matescript
STRd6/coffee-script
ShawnFumo/coffee-script
StanAngeloff/coffee-script
Xepo/coffee-script
abi/coffee-script
agnoster/coffee-script
ahjohannessen/coffee-script
akiellor/coffee-script
alanning/coffee-script
allanberger/coffee-script
almost/coffee-script
alubbe/coffee-script
andrehjr/coffee-script
andrewschaaf/coffee-script
andreypopp/coffee-script
apanda/coffee-script
baoshitang/coffee-script
barberboy/coffee-script
benatkin/coffee-script
benbria/coffee-script
benekastah/coffee-script
bjouhier/coffee-script
blahutka/coffee-script
blossom/coffee-script
bolinfest/coffee-script
breckinloggins/coffee-script
carmelyne/contracts.coffee
chajath/coffee-script
charles-cai/coffee-script
charliesome/coffee-script
chetan51/coffee-script
chip/coffee-script
codelahoma/coffee-script
coffee-js/coffee-script
coffee-void/coffeescript
collin/coffee-script
danemorgridge/coffee-script
daveclarke/coffee-script
daveyoon/coffee-script
dbrans/coffee-script
deadprogram/coffee-script
devongovett/coffee-script
dget/coffee-script
disnet/contracts.coffee
dmohl/coffee-script
dohse/coffee-script
dqminh/coffee-script
drewlesueur/coffee-script
eventualbuddha/coffee-script
evilpie/coffee-script
excellentdrums/coffee-script
fitzgen/coffee-script
fizx/coffee-script
geraldalewis/coffee-script
germanocaldeira/coffee-script
gfodor/coffee-script
ghuntley/coffee-script
goodwink/coffee-script
gxela/coffee-script
hayeah/coffee-script
hbt/coffee-script
helixbass/copheescript
hleumas/coffee-script
holtwick/moccacino
hugs/coffee-script
ianthehenry/protoscript
ich/caffeine
janlelis/angular-coffee-script
jaredwy/coffee-script
jasonyandell/coffee-script
jawj/coffee-script
jbca/coffeescript
jiangmiao/toffee-script
jlstr/coffee-script
joelturnbull/coffee-script
johnsang/coffee-script
joliss/coffee-script
jondistad/coffee-script
joshprice/coffee-script
jstrachan/coffee-script
jugglinmike/irene-script
juilyoon/coffee-script
keichii/coffee-script
keithnorm/coffee-script
kewinwang/coffee-script
khaled/coffee-script
leeight/coffee-script
level1/coffee-script
lfendy/coffee-script
loganfsmyth/coffee-script
loopinfinito/coffeescript.com.br
lorensr/coffee-script
loveencounterflow/coffy-script
lukhnos/doubleshot
lynaghk/coffee-script
martco/coffee-script
maxtaco/coffee-script
mbbx6spp/coffee-script
mblinn/coffee-script
mehmeta/coffee-script
melcher/coffee-script
mental/coffee-script
mhart/coffee-script
michaelficarra/coffee-script
misfo/coffee-script
mizchi/coffee-script
mlinderm/coffee-script
mrlauer/coffee-script-monads
muratmeran/coffee-script
myang/coffee-script
nanqiu/coffee-script
neobine/coffee-script
netconstructor/coffee-script
nickjs/coffee-script
nihar/coffee-script
onilabs/coffee-script
paiq/blackcoffee
parkerl/coffee-script
paulmars/coffee-script
peick/coffee-script
pjaspers/coffee-script
plambert/coffee-script
poutyface/coffee-script
pschyska/coffee-script
ptoomey3/coffee-script
quangv/coffee-script
revence27/coffee-script
rkJun/coffee-script
robarondaz/coffee-script
robotlolita/coffee-script
rolftimmermans/coffee-script
rpl/coffee-script
runeb/coffee-script
rwaldron/coffee-script
rymohr/coffee-script
ryszard/coffee-script
samcday/coffee-script
sarang25491/coffee-script
satyr/coffee-script
seedjs/coffee-script
sequoiar/coffee-script
sgraham/coffee-script
shariefsk/coffee-script
shesek/coffee-script
shimaore/cake
siefkenj/gjscoffee-script
smhanov/coffee-script
soutaro/coffee-script
spaghetticode/coffee-script
sparecycles/coffee-script
spencerelliott/coffee-script
sstephenson/coffee-script
stephank/coffee-script
strangemonad/coffee-script
swistak/coffee-script
syg/heap.coffee
taku0/coffee-script
tanob/coffee-script
tglines/coffee-script
thdtjsdn/coffee-script
theIntuitionist/coffee-script
thedeeno/coffee-script
thejh/coffee-script
timruffles/coffee-script
tkpage/coffee-script
tlrobinson/coffee-script
tmishra/coffee-script
tobee/coffee-script
tomelam/coffee-script
tosh/coffee-script
tswicegood/coffee-script
ttilley/coffee-script
twilson63/coffee-script
up2u0609/coffee-script
vanviegen/coffee-script
vjpr/coffee-script
vol4ok/coffee-script
walski/coffee-script
wearefractal/yerbascript
willmoffat/coffee-script
xixixao/coffee-script
yihuang/coffee-script
zaach/coffee-script
zmthy/coffee-script
zot/coffee-script
Nothing to show
Choose a base branch
Choose a Head Repository
jashkenas/coffeescript
CDR2003/coffee-script-lua
CreamCoderz/coffee-script
Crylock/coffee-script
GeoffreyBooth/coffeescript
Gregg/coffee-script
JulianBirch/coffee-script-1
JustinTulloss/coffee-script
MichaelBlume/coffee-script
NightMigera/coffeescript
PandaWood/coffee-script
ProximaMonkey/coffee-script
Remcoman/coffee-script
RicardoSaracino/coffee-script
SE7ENSKY/matescript
STRd6/coffee-script
ShawnFumo/coffee-script
StanAngeloff/coffee-script
Xepo/coffee-script
abi/coffee-script
agnoster/coffee-script
ahjohannessen/coffee-script
akiellor/coffee-script
alanning/coffee-script
allanberger/coffee-script
almost/coffee-script
alubbe/coffee-script
andrehjr/coffee-script
andrewschaaf/coffee-script
andreypopp/coffee-script
apanda/coffee-script
baoshitang/coffee-script
barberboy/coffee-script
benatkin/coffee-script
benbria/coffee-script
benekastah/coffee-script
bjouhier/coffee-script
blahutka/coffee-script
blossom/coffee-script
bolinfest/coffee-script
breckinloggins/coffee-script
carmelyne/contracts.coffee
chajath/coffee-script
charles-cai/coffee-script
charliesome/coffee-script
chetan51/coffee-script
chip/coffee-script
codelahoma/coffee-script
coffee-js/coffee-script
coffee-void/coffeescript
collin/coffee-script
danemorgridge/coffee-script
daveclarke/coffee-script
daveyoon/coffee-script
dbrans/coffee-script
deadprogram/coffee-script
devongovett/coffee-script
dget/coffee-script
disnet/contracts.coffee
dmohl/coffee-script
dohse/coffee-script
dqminh/coffee-script
drewlesueur/coffee-script
eventualbuddha/coffee-script
evilpie/coffee-script
excellentdrums/coffee-script
fitzgen/coffee-script
fizx/coffee-script
geraldalewis/coffee-script
germanocaldeira/coffee-script
gfodor/coffee-script
ghuntley/coffee-script
goodwink/coffee-script
gxela/coffee-script
hayeah/coffee-script
hbt/coffee-script
helixbass/copheescript
hleumas/coffee-script
holtwick/moccacino
hugs/coffee-script
ianthehenry/protoscript
ich/caffeine
janlelis/angular-coffee-script
jaredwy/coffee-script
jasonyandell/coffee-script
jawj/coffee-script
jbca/coffeescript
jiangmiao/toffee-script
jlstr/coffee-script
joelturnbull/coffee-script
johnsang/coffee-script
joliss/coffee-script
jondistad/coffee-script
joshprice/coffee-script
jstrachan/coffee-script
jugglinmike/irene-script
juilyoon/coffee-script
keichii/coffee-script
keithnorm/coffee-script
kewinwang/coffee-script
khaled/coffee-script
leeight/coffee-script
level1/coffee-script
lfendy/coffee-script
loganfsmyth/coffee-script
loopinfinito/coffeescript.com.br
lorensr/coffee-script
loveencounterflow/coffy-script
lukhnos/doubleshot
lynaghk/coffee-script
martco/coffee-script
maxtaco/coffee-script
mbbx6spp/coffee-script
mblinn/coffee-script
mehmeta/coffee-script
melcher/coffee-script
mental/coffee-script
mhart/coffee-script
michaelficarra/coffee-script
misfo/coffee-script
mizchi/coffee-script
mlinderm/coffee-script
mrlauer/coffee-script-monads
muratmeran/coffee-script
myang/coffee-script
nanqiu/coffee-script
neobine/coffee-script
netconstructor/coffee-script
nickjs/coffee-script
nihar/coffee-script
onilabs/coffee-script
paiq/blackcoffee
parkerl/coffee-script
paulmars/coffee-script
peick/coffee-script
pjaspers/coffee-script
plambert/coffee-script
poutyface/coffee-script
pschyska/coffee-script
ptoomey3/coffee-script
quangv/coffee-script
revence27/coffee-script
rkJun/coffee-script
robarondaz/coffee-script
robotlolita/coffee-script
rolftimmermans/coffee-script
rpl/coffee-script
runeb/coffee-script
rwaldron/coffee-script
rymohr/coffee-script
ryszard/coffee-script
samcday/coffee-script
sarang25491/coffee-script
satyr/coffee-script
seedjs/coffee-script
sequoiar/coffee-script
sgraham/coffee-script
shariefsk/coffee-script
shesek/coffee-script
shimaore/cake
siefkenj/gjscoffee-script
smhanov/coffee-script
soutaro/coffee-script
spaghetticode/coffee-script
sparecycles/coffee-script
spencerelliott/coffee-script
sstephenson/coffee-script
stephank/coffee-script
strangemonad/coffee-script
swistak/coffee-script
syg/heap.coffee
taku0/coffee-script
tanob/coffee-script
tglines/coffee-script
thdtjsdn/coffee-script
theIntuitionist/coffee-script
thedeeno/coffee-script
thejh/coffee-script
timruffles/coffee-script
tkpage/coffee-script
tlrobinson/coffee-script
tmishra/coffee-script
tobee/coffee-script
tomelam/coffee-script
tosh/coffee-script
tswicegood/coffee-script
ttilley/coffee-script
twilson63/coffee-script
up2u0609/coffee-script
vanviegen/coffee-script
vjpr/coffee-script
vol4ok/coffee-script
walski/coffee-script
wearefractal/yerbascript
willmoffat/coffee-script
xixixao/coffee-script
yihuang/coffee-script
zaach/coffee-script
zmthy/coffee-script
zot/coffee-script
Nothing to show
Choose a head branch
1
contributor
Commits on Jan 14, 2010
|
|
jashkenas |
slightly shorter generated code for ==>
|
001cc29
|
|||
|
|
jashkenas |
adding coffee-haml-filter to the resources section
|
8dc5da9
|
Commits on Jan 16, 2010
Commits on Jan 17, 2010
Unified
Split
Showing
with
644 additions
and 255 deletions.
- +1 −0 .gitignore
- +2 −2 coffee-script.gemspec
- +5 −0 documentation/coffee/comparisons.coffee
- +8 −1 documentation/coffee/existence.coffee
- +1 −1 documentation/coffee/functions.coffee
- +42 −7 documentation/index.html.erb
- +2 −1 documentation/js/arguments.js
- +5 −0 documentation/js/comparisons.js
- +1 −1 documentation/js/conditionals.js
- +2 −1 documentation/js/existence.js
- +1 −1 documentation/js/expressions_assignment.js
- +6 −9 documentation/js/long_arrow.js
- +1 −1 documentation/js/splats.js
- +1 −2 documentation/js/super.js
- +16 −0 examples/beautiful_code/binary_search.coffee
- +13 −0 examples/beautiful_code/quicksort_runtime.coffee
- +34 −0 examples/beautiful_code/regular_expression_matcher.coffee
- +84 −28 index.html
- +1 −1 lib/coffee-script.rb
- +34 −39 lib/coffee_script/CoffeeScript.tmbundle/Syntaxes/CoffeeScript.tmLanguage
- +12 −8 lib/coffee_script/grammar.y
- +3 −2 lib/coffee_script/lexer.rb
- +14 −11 lib/coffee_script/narwhal/lib/coffee-script.js
- +191 −119 lib/coffee_script/nodes.rb
- +6 −5 lib/coffee_script/scope.rb
- +14 −0 lib/coffee_script/value.rb
- +1 −1 package.json
- +8 −0 test/fixtures/execution/test_arguments.coffee
- +0 −8 test/fixtures/execution/test_assign_to_try_catch.coffee
- +23 −0 test/fixtures/execution/test_assignment.coffee
- +29 −1 test/fixtures/execution/test_existence.coffee
- +30 −0 test/fixtures/execution/test_expressions.coffee
- +27 −1 test/fixtures/execution/test_functions.coffee
- +18 −0 test/fixtures/execution/test_operations.coffee
- +8 −4 test/unit/test_execution.rb
View
1
.gitignore
| @@ -3,4 +3,5 @@ test.coffee | ||
| parser.output | ||
| lib/coffee_script/parser.rb | ||
| test/fixtures/underscore | ||
| +examples/beautiful_code/parse.coffee | ||
| *.gem | ||
View
4
coffee-script.gemspec
| @@ -1,7 +1,7 @@ | ||
| Gem::Specification.new do |s| | ||
| s.name = 'coffee-script' | ||
| - s.version = '0.2.5' # Keep version in sync with coffee-script.rb | ||
| - s.date = '2010-1-13' | ||
| + s.version = '0.2.6' # Keep version in sync with coffee-script.rb | ||
| + s.date = '2010-1-17' | ||
| s.homepage = "http://jashkenas.github.com/coffee-script/" | ||
| s.summary = "The CoffeeScript Compiler" | ||
View
5
documentation/coffee/comparisons.coffee
| @@ -0,0 +1,5 @@ | ||
| +cholesterol: 127 | ||
| + | ||
| +healthy: 200 > cholesterol > 60 | ||
| + | ||
| + |
View
9
documentation/coffee/existence.coffee
| @@ -1 +1,8 @@ | ||
| -solipsism: true if mind? and not world? | ||
| +solipsism: true if mind? and not world? | ||
| + | ||
| +speed ?= 140 | ||
| + | ||
| + | ||
| + | ||
| + | ||
| + |
View
2
documentation/coffee/functions.coffee
| @@ -1,2 +1,2 @@ | ||
| square: x => x * x | ||
| -cube: x => square(x) * x | ||
| +cube: x => square(x) * x |
View
49
documentation/index.html.erb
| @@ -51,7 +51,7 @@ | ||
| <p> | ||
| <b>Latest Version:</b> | ||
| - <a href="http://gemcutter.org/gems/coffee-script">0.2.5</a> | ||
| + <a href="http://gemcutter.org/gems/coffee-script">0.2.6</a> | ||
| </p> | ||
| <h2>Table of Contents</h2> | ||
| @@ -65,7 +65,7 @@ | ||
| <a href="#objects_and_arrays">Objects and Arrays</a><br /> | ||
| <a href="#lexical_scope">Lexical Scoping and Variable Safety</a><br /> | ||
| <a href="#conditionals">Conditionals, Ternaries, and Conditional Assignment</a><br /> | ||
| - <a href="#existence">The Existence Operator</a><br /> | ||
| + <a href="#existence">The Existential Operator</a><br /> | ||
| <a href="#aliases">Aliases</a><br /> | ||
| <a href="#splats">Splats...</a><br /> | ||
| <a href="#arguments">Arguments are Arrays</a><br /> | ||
| @@ -80,6 +80,7 @@ | ||
| <a href="#embedded">Embedded JavaScript</a><br /> | ||
| <a href="#switch">Switch/When/Else</a><br /> | ||
| <a href="#try">Try/Catch/Finally</a><br /> | ||
| + <a href="#comparisons">Chained Comparisons</a><br /> | ||
| <a href="#strings">Multiline Strings and Heredocs</a><br /> | ||
| <a href="#resources">Resources</a><br /> | ||
| <a href="#contributing">Contributing</a><br /> | ||
| @@ -258,7 +259,8 @@ coffee --print app/scripts/*.coffee > concatenation.js</pre> | ||
| <b class="header">Functions and Invocation</b> | ||
| Functions are defined by a list of parameters, an arrow, and the | ||
| function body. The empty function looks like this: <tt>=></tt>. All | ||
| - functions in CoffeeScript are named, for the benefit of debug messages. | ||
| + functions in CoffeeScript are named by default, for the benefit of debug messages. | ||
| + If you'd like to create an anonymous function, just wrap it in parentheses. | ||
| </p> | ||
| <%= code_for('functions', 'cube(5)') %> | ||
| @@ -329,14 +331,18 @@ coffee --print app/scripts/*.coffee > concatenation.js</pre> | ||
| </p> | ||
| <p id="existence"> | ||
| - <b class="header">The Existence Operator</b> | ||
| + <b class="header">The Existential Operator</b> | ||
| It's a little difficult to check for the existence of a variable in | ||
| JavaScript. <tt>if (variable) ...</tt> comes close, but fails for zero, | ||
| - the empty string, and false. The existence operator <tt>?</tt> returns true unless | ||
| + the empty string, and false. The existential operator <tt>?</tt> returns true unless | ||
| a variable is <b>null</b> or <b>undefined</b>, which makes it analogous | ||
| to Ruby's <tt>nil?</tt> | ||
| </p> | ||
| - <%= code_for('existence') %> | ||
| + <p> | ||
| + It can also be used for safer conditional assignment than <tt>||=</tt> | ||
| + provides, for cases where you may be handling numbers or strings. | ||
| + </p> | ||
| + <%= code_for('existence', 'speed') %> | ||
| <p id="aliases"> | ||
| <b class="header">Aliases</b> | ||
| @@ -473,6 +479,12 @@ coffee --print app/scripts/*.coffee > concatenation.js</pre> | ||
| into a function call: | ||
| </p> | ||
| <%= code_for('expressions_try', true) %> | ||
| + <p> | ||
| + There are a handful of statements in JavaScript that can't be meaningfully | ||
| + converted into expressions: <tt>break</tt>, <tt>continue</tt>, | ||
| + and <tt>return</tt>. If you make use of them within a block of code, | ||
| + CoffeeScript won't try to perform the conversion. | ||
| + </p> | ||
| <p id="inheritance"> | ||
| <b class="header">Inheritance, and Calling Super from a Subclass</b> | ||
| @@ -575,6 +587,15 @@ coffee --print app/scripts/*.coffee > concatenation.js</pre> | ||
| </p> | ||
| <%= code_for('try') %> | ||
| + <p id="comparisons"> | ||
| + <b class="header">Chained Comparisons</b> | ||
| + CoffeeScript borrows | ||
| + <a href="http://docs.python.org/reference/expressions.html#notin">chained comparisons</a> | ||
| + from Python — making it easy to test if a value falls within a | ||
| + certain range. | ||
| + </p> | ||
| + <%= code_for('comparisons', 'healthy') %> | ||
| + | ||
| <p id="strings"> | ||
| <b class="header">Multiline Strings and Heredocs</b> | ||
| Multiline strings are allowed in CoffeeScript. | ||
| @@ -610,6 +631,12 @@ coffee --print app/scripts/*.coffee > concatenation.js</pre> | ||
| that includes CoffeeScript helpers, | ||
| bundling and minification. | ||
| </li> | ||
| + <li> | ||
| + <a href="http://github.com/inem/coffee-haml-filter">coffee-haml-filter</a><br /> | ||
| + A custom <a href="http://haml-lang.com/">HAML</a> filter, by | ||
| + <a href="http://github.com/inem">Ivan Nemytchenko</a>, that embeds | ||
| + snippets of CoffeeScript within your HAML templates. | ||
| + </li> | ||
| </ul> | ||
| <h2 id="contributing">Contributing</h2> | ||
| @@ -646,6 +673,14 @@ coffee --print app/scripts/*.coffee > concatenation.js</pre> | ||
| <h2 id="change_log">Change Log</h2> | ||
| <p> | ||
| + <b class="header" style="margin-top: 20px;">0.2.6</b> | ||
| + Added Python-style chained comparisons, the conditional existence | ||
| + operator <tt>?=</tt>, and some examples from <i>Beautiful Code</i>. | ||
| + Bugfixes relating to statement-to-expression conversion, arguments-to-array | ||
| + conversion, and the TextMate syntax highlighter. | ||
| + </p> | ||
| + | ||
| + <p> | ||
| <b class="header" style="margin-top: 20px;">0.2.5</b> | ||
| The conditions in switch statements can now take multiple values at once — | ||
| If any of them are true, the case will run. Added the long arrow <tt>==></tt>, | ||
| @@ -697,7 +732,7 @@ coffee --print app/scripts/*.coffee > concatenation.js</pre> | ||
| <b class="header" style="margin-top: 20px;">0.2.0</b> | ||
| Major release. Significant whitespace. Better statement-to-expression | ||
| conversion. Splats. Splice literals. Object comprehensions. Blocks. | ||
| - The existence operator. Many thanks to all the folks who posted issues, | ||
| + The existential operator. Many thanks to all the folks who posted issues, | ||
| with special thanks to | ||
| <a href="http://github.com/kamatsu">Liam O'Connor-Davis</a> for whitespace | ||
| and expression help. | ||
View
3
documentation/js/arguments.js
| @@ -1,7 +1,8 @@ | ||
| (function(){ | ||
| var backwards; | ||
| backwards = function backwards() { | ||
| - return alert(Array.prototype.slice.call(arguments, 0).reverse()); | ||
| + var arguments = Array.prototype.slice.call(arguments, 0); | ||
| + return alert(arguments.reverse()); | ||
| }; | ||
| backwards("stairway", "to", "heaven"); | ||
| })(); |
View
5
documentation/js/comparisons.js
| @@ -0,0 +1,5 @@ | ||
| +(function(){ | ||
| + var cholesterol, healthy; | ||
| + cholesterol = 127; | ||
| + healthy = (200 > cholesterol) && (cholesterol > 60); | ||
| +})(); |
View
2
documentation/js/conditionals.js
| @@ -1,5 +1,5 @@ | ||
| (function(){ | ||
| - var date, mood; | ||
| + var date, expensive, mood; | ||
| if (singing) { | ||
| mood = greatly_improved; | ||
| } | ||
View
3
documentation/js/existence.js
| @@ -1,6 +1,7 @@ | ||
| (function(){ | ||
| - var solipsism; | ||
| + var solipsism, speed; | ||
| if ((typeof mind !== "undefined" && mind !== null) && !(typeof world !== "undefined" && world !== null)) { | ||
| solipsism = true; | ||
| } | ||
| + speed = (typeof speed !== "undefined" && speed !== null) ? speed : 140; | ||
| })(); |
View
2
documentation/js/expressions_assignment.js
| @@ -1,4 +1,4 @@ | ||
| (function(){ | ||
| var one, six, three, two; | ||
| - six = (one = 1) + (two = 2) + (three = 3); | ||
| + six = ((one = 1)) + ((two = 2)) + ((three = 3)); | ||
| })(); |
View
15
documentation/js/long_arrow.js
| @@ -1,20 +1,17 @@ | ||
| (function(){ | ||
| var Account; | ||
| Account = function Account(customer, cart) { | ||
| - var __a, __b; | ||
| - var __this = this; | ||
| + var __a; | ||
| this.customer = customer; | ||
| this.cart = cart; | ||
| - __a = $('.shopping_cart').bind('click', (function() { | ||
| - __b = function(event) { | ||
| - var __c; | ||
| - __c = this.customer.purchase(this.cart); | ||
| - return Account === this.constructor ? this : __c; | ||
| + __a = $('.shopping_cart').bind('click', (function(__this) { | ||
| + var __func = function(event) { | ||
| + return this.customer.purchase(this.cart); | ||
| }; | ||
| return (function() { | ||
| - return __b.apply(__this, arguments); | ||
| + return __func.apply(__this, arguments); | ||
| }); | ||
| - })()); | ||
| + })(this)); | ||
| return Account === this.constructor ? this : __a; | ||
| }; | ||
| })(); |
View
2
documentation/js/splats.js
| @@ -1,6 +1,6 @@ | ||
| (function(){ | ||
| var contenders, gold, medalists, silver, the_field; | ||
| - gold = silver = the_field = "unknown"; | ||
| + gold = (silver = (the_field = "unknown")); | ||
| medalists = function medalists(first, second) { | ||
| var rest; | ||
| rest = Array.prototype.slice.call(arguments, 2); | ||
View
3
documentation/js/super.js
| @@ -1,7 +1,6 @@ | ||
| (function(){ | ||
| var Animal, Horse, Snake, __a, __b, sam, tom; | ||
| - Animal = function Animal() { | ||
| - }; | ||
| + Animal = function Animal() { }; | ||
| Animal.prototype.move = function move(meters) { | ||
| return alert(this.name + " moved " + meters + "m."); | ||
| }; | ||
View
16
examples/beautiful_code/binary_search.coffee
| @@ -0,0 +1,16 @@ | ||
| +# Beautiful Code, Chapter 6. | ||
| +# 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 => | ||
| + [low, high]: [0, list.length] | ||
| + while low < high | ||
| + mid: (low + high) >> 1 | ||
| + val: list[mid] | ||
| + return mid if val is target | ||
| + if val < target then low: mid + 1 else high: mid | ||
| + return -1 | ||
| + | ||
| +print(2 is index([10, 20, 30, 40, 50], 30)) | ||
| +print(4 is index([-97, 35, 67, 88, 1200], 1200)) | ||
| +print(0 is index([0, 45, 70], 0)) |
View
13
examples/beautiful_code/quicksort_runtime.coffee
| @@ -0,0 +1,13 @@ | ||
| +# Beautiful Code, Chapter 3. | ||
| +# Produces the expected runtime of Quicksort, for every integer from 1 to N. | ||
| + | ||
| +runtime: N => | ||
| + [sum, t]: [0, 0] | ||
| + for n in [1..N] | ||
| + sum += 2 * t | ||
| + t: n - 1 + sum / n | ||
| + t | ||
| + | ||
| +print(runtime(3) is 2.6666666666666665) | ||
| +print(runtime(5) is 7.4) | ||
| +print(runtime(8) is 16.92142857142857) |
View
34
examples/beautiful_code/regular_expression_matcher.coffee
| @@ -0,0 +1,34 @@ | ||
| +# Beautiful Code, Chapter 1. | ||
| +# Implements a regular expression matcher that supports character matches, | ||
| +# '.', '^', '$', and '*'. | ||
| + | ||
| +# Search for the regexp anywhere in the text. | ||
| +match: regexp, text => | ||
| + return match_here(regexp.slice(1), text) if regexp[0] is '^' | ||
| + while text | ||
| + return true if match_here(regexp, text) | ||
| + text: text.slice(1) | ||
| + false | ||
| + | ||
| +# Search for the regexp at the beginning of the 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) | ||
| + if cur is '$' and not next then return text.length is 0 | ||
| + if text and (cur is '.' or cur is text[0]) then return match_here(regexp.slice(1), text.slice(1)) | ||
| + false | ||
| + | ||
| +# Search for a kleene star match at the beginning of the 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 '.') | ||
| + text: text.slice(1) | ||
| + | ||
| +print(match("ex", "some text")) | ||
| +print(match("s..t", "spit")) | ||
| +print(match("^..t", "buttercup")) | ||
| +print(match("i..$", "cherries")) | ||
| +print(match("o*m", "vrooooommm!")) | ||
| +print(match("^hel*o$", "hellllllo")) |
Oops, something went wrong.