Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 167 lines (127 sloc) 3.069 kb
f51972a Jeremy Ashkenas line cleaning -- arglists are broken broken
authored
1 # Functions:
da6ea27 Jeremy Ashkenas most of the examples converted to symbology.
authored
2 square = (x) -> x * x
cedb925 Jeremy Ashkenas down to the last shift reduce conflict -- leading and trailing whitespac...
authored
3
da6ea27 Jeremy Ashkenas most of the examples converted to symbology.
authored
4 sum = (x, y) -> x + y
cedb925 Jeremy Ashkenas down to the last shift reduce conflict -- leading and trailing whitespac...
authored
5
da6ea27 Jeremy Ashkenas most of the examples converted to symbology.
authored
6 odd = (x) -> x % 2 isnt 0
cedb925 Jeremy Ashkenas down to the last shift reduce conflict -- leading and trailing whitespac...
authored
7
da6ea27 Jeremy Ashkenas most of the examples converted to symbology.
authored
8 even = (x) -> x % 2 is 0
cedb925 Jeremy Ashkenas down to the last shift reduce conflict -- leading and trailing whitespac...
authored
9
da6ea27 Jeremy Ashkenas most of the examples converted to symbology.
authored
10 run_loop = ->
a9f016e Jeremy Ashkenas trying out new arrows for function literals -> is a function, => is a bo...
authored
11 fire_events((e) -> e.stopPropagation())
cedb925 Jeremy Ashkenas down to the last shift reduce conflict -- leading and trailing whitespac...
authored
12 listen()
5659d1b Jeremy Ashkenas adding ')' as a SINGLE_CLOSER, although it's probably unsafe
authored
13 wait()
cedb925 Jeremy Ashkenas down to the last shift reduce conflict -- leading and trailing whitespac...
authored
14
15 # Objects:
da6ea27 Jeremy Ashkenas most of the examples converted to symbology.
authored
16 dense_object_literal = {one: 1, two: 2, three: 3}
5153ef7 Jeremy Ashkenas a smarter lexer brings us down to three shift/reduces
authored
17
da6ea27 Jeremy Ashkenas most of the examples converted to symbology.
authored
18 spaced_out_multiline_object =
91ac495 Jeremy Ashkenas moving right along
authored
19 pi: 3.14159
e3c667d Jeremy Ashkenas number examples
authored
20 list: [1, 2, 3, 4]
1a8311b Jeremy Ashkenas allowing inner slashes in regexes
authored
21 regex: /match[ing](every|thing|\/)/gi
7d79d73 Jeremy Ashkenas allowing paren-less instance creation, a la 'new Class'
authored
22 three: new Idea
5153ef7 Jeremy Ashkenas a smarter lexer brings us down to three shift/reduces
authored
23
da6ea27 Jeremy Ashkenas most of the examples converted to symbology.
authored
24 inner_obj:
a9f016e Jeremy Ashkenas trying out new arrows for function literals -> is a function, => is a bo...
authored
25 freedom: -> _.freedom()
91ac495 Jeremy Ashkenas moving right along
authored
26
27 # Arrays:
da6ea27 Jeremy Ashkenas most of the examples converted to symbology.
authored
28 stooges = [{moe: 45}, {curly: 43}, {larry: 46}]
91ac495 Jeremy Ashkenas moving right along
authored
29
da6ea27 Jeremy Ashkenas most of the examples converted to symbology.
authored
30 exponents = [((x) -> x), ((x) -> x * x), ((x) -> x * x * x)]
91ac495 Jeremy Ashkenas moving right along
authored
31
da6ea27 Jeremy Ashkenas most of the examples converted to symbology.
authored
32 empty = []
cedb925 Jeremy Ashkenas down to the last shift reduce conflict -- leading and trailing whitespac...
authored
33
da6ea27 Jeremy Ashkenas most of the examples converted to symbology.
authored
34 multiline = [
68bc68c Jeremy Ashkenas many more comments, plus a fix for inner-assignment indentation
authored
35 'line one'
36 'line two'
37 ]
38
91ac495 Jeremy Ashkenas moving right along
authored
39 # Conditionals and ternaries.
40 if submarine.shields_up
41 full_speed_ahead()
b093a43 Jeremy Ashkenas fixing object assignment indentation
authored
42 fire_torpedos()
049358d Jeremy Ashkenas after a lot of grammar wrestling, got the if-else chains to parse unambi...
authored
43 else if submarine.sinking
44 abandon_ship()
91ac495 Jeremy Ashkenas moving right along
authored
45 else
5659d1b Jeremy Ashkenas adding ')' as a SINGLE_CLOSER, although it's probably unsafe
authored
46 run_away()
91ac495 Jeremy Ashkenas moving right along
authored
47
da6ea27 Jeremy Ashkenas most of the examples converted to symbology.
authored
48 eldest = if 25 > 21 then liz else marge
91ac495 Jeremy Ashkenas moving right along
authored
49
da6ea27 Jeremy Ashkenas most of the examples converted to symbology.
authored
50 decoration = medal_of_honor if war_hero
5dd295b Jeremy Ashkenas got postfix if and unless onboard
authored
51
52 go_to_sleep() unless coffee
53
91ac495 Jeremy Ashkenas moving right along
authored
54 # Returning early:
da6ea27 Jeremy Ashkenas most of the examples converted to symbology.
authored
55 race = ->
91ac495 Jeremy Ashkenas moving right along
authored
56 run()
57 walk()
58 crawl()
5659d1b Jeremy Ashkenas adding ')' as a SINGLE_CLOSER, although it's probably unsafe
authored
59 if tired then return sleep()
60 race()
8e9d637 Jeremy Ashkenas initial commit of the mystery language
authored
61
6050cad Jeremy Ashkenas moved the TextMate bundle into the gem, added a command to install it
authored
62 # Conditional assignment:
b18d7fb Jeremy Ashkenas removing the last traces of half-assignments. Issue #541.
authored
63 good or= evil
64 wine and= cheese
896440d Jeremy Ashkenas more more, including &&=, ||=
authored
65
4e64416 Jeremy Ashkenas reduce/reduce conflicts are gone
authored
66 # Nested property access and calls.
68bc68c Jeremy Ashkenas many more comments, plus a fix for inner-assignment indentation
authored
67 ((moon.turn(360))).shapes[3].move({x: 45, y: 30}).position['top'].offset('x')
4e64416 Jeremy Ashkenas reduce/reduce conflicts are gone
authored
68
da6ea27 Jeremy Ashkenas most of the examples converted to symbology.
authored
69 a = b = c = 5
4480900 Jeremy Ashkenas a bit more underscore
authored
70
f7a0bf1 Jeremy Ashkenas with shelling out to javascript
authored
71 # Embedded JavaScript.
72 callback(
73 `function(e) { e.stop(); }`
74 )
75
8c8fb44 Jeremy Ashkenas lots of goodies -- smart reducing of redunant parentheses, auto function...
authored
76 # Try/Catch/Finally/Throw.
fdc7514 Jeremy Ashkenas with try-catch working
authored
77 try
78 all_hell_breaks_loose()
79 dogs_and_cats_living_together()
8c8fb44 Jeremy Ashkenas lots of goodies -- smart reducing of redunant parentheses, auto function...
authored
80 throw "up"
fdc7514 Jeremy Ashkenas with try-catch working
authored
81 catch error
5659d1b Jeremy Ashkenas adding ')' as a SINGLE_CLOSER, although it's probably unsafe
authored
82 print(error)
8c8fb44 Jeremy Ashkenas lots of goodies -- smart reducing of redunant parentheses, auto function...
authored
83 finally
5659d1b Jeremy Ashkenas adding ')' as a SINGLE_CLOSER, although it's probably unsafe
authored
84 clean_up()
8e9d637 Jeremy Ashkenas initial commit of the mystery language
authored
85
5659d1b Jeremy Ashkenas adding ')' as a SINGLE_CLOSER, although it's probably unsafe
authored
86 try all_hell_breaks_loose() catch error then print(error) finally clean_up()
d68a4fc Jeremy Ashkenas first draft of array comprehensions, but they stink.
authored
87
3ffbf54 Jeremy Ashkenas removed class checks in favor of statement?
authored
88 # While loops, break and continue.
d68a4fc Jeremy Ashkenas first draft of array comprehensions, but they stink.
authored
89 while demand > supply
90 sell()
5659d1b Jeremy Ashkenas adding ')' as a SINGLE_CLOSER, although it's probably unsafe
authored
91 restock()
d68a4fc Jeremy Ashkenas first draft of array comprehensions, but they stink.
authored
92
5659d1b Jeremy Ashkenas adding ')' as a SINGLE_CLOSER, although it's probably unsafe
authored
93 while supply > demand then buy()
d68a4fc Jeremy Ashkenas first draft of array comprehensions, but they stink.
authored
94
0222d90 Jeremy Ashkenas adding a 'loop' keyword to CoffeeScript. Takes an expression or a block....
authored
95 loop
3ffbf54 Jeremy Ashkenas removed class checks in favor of statement?
authored
96 break if broken
5659d1b Jeremy Ashkenas adding ')' as a SINGLE_CLOSER, although it's probably unsafe
authored
97 continue if continuing
3ffbf54 Jeremy Ashkenas removed class checks in favor of statement?
authored
98
d68a4fc Jeremy Ashkenas first draft of array comprehensions, but they stink.
authored
99 # Unary operators.
b1f3ad2 Jeremy Ashkenas added git st with the new operator regex
authored
100 !!true
d68a4fc Jeremy Ashkenas first draft of array comprehensions, but they stink.
authored
101
c7691ec Jeremy Ashkenas got lexical scoping working -- even fancier returns with assignment as t...
authored
102 # Lexical scoping.
da6ea27 Jeremy Ashkenas most of the examples converted to symbology.
authored
103 v_1 = 5
104 change_a_and_set_b = ->
105 v_1 = 10
106 v_2 = 15
107 v_2 = 20
c7691ec Jeremy Ashkenas got lexical scoping working -- even fancier returns with assignment as t...
authored
108
aebcc50 Jeremy Ashkenas add free variable name lookup. Now that we have lexical scope, array com...
authored
109 # Array comprehensions.
da6ea27 Jeremy Ashkenas most of the examples converted to symbology.
authored
110 supper = food.capitalize() for food in ['toast', 'cheese', 'wine']
aebcc50 Jeremy Ashkenas add free variable name lookup. Now that we have lexical scope, array com...
authored
111
da6ea27 Jeremy Ashkenas most of the examples converted to symbology.
authored
112 drink bottle for bottle, i in ['soda', 'wine', 'lemonade'] when even i
e48d49d Jeremy Ashkenas got case statements wokring
authored
113
0dc4451 Jeremy Ashkenas removed the 'default' keyword in favor of an 'else'
authored
114 # Switch statements ("else" serves as a default).
da6ea27 Jeremy Ashkenas most of the examples converted to symbology.
authored
115 activity = switch day
5659d1b Jeremy Ashkenas adding ')' as a SINGLE_CLOSER, although it's probably unsafe
authored
116 when "Tuesday" then eat_breakfast()
117 when "Sunday" then go_to_church()
118 when "Saturday" then go_to_the_park()
119 when "Wednesday"
120 if day is bingo_day
121 go_to_bingo()
122 else
123 eat_breakfast()
124 go_to_work()
125 eat_dinner()
126 else go_to_work()
2753648 Jeremy Ashkenas two more shift/reduces down, 8 to go
authored
127
128 # Semicolons can optionally be used instead of newlines.
da6ea27 Jeremy Ashkenas most of the examples converted to symbology.
authored
129 wednesday = -> eat_breakfast(); go_to_work(); eat_dinner()
5acc91c Jeremy Ashkenas --
authored
130
4e1e119 Jeremy Ashkenas supporting escaped quotes in strings
authored
131 # Multiline strings with inner quotes.
da6ea27 Jeremy Ashkenas most of the examples converted to symbology.
authored
132 story = "Lorem ipsum dolor \"sit\" amet, consectetuer adipiscing elit,
d1682f5 Jeremy Ashkenas multiline strings
authored
133 sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna
1d35910 Jeremy Ashkenas added the ability to super()
authored
134 aliquam erat volutpat. Ut wisi enim ad."
135
c7fa9c3 Jeremy Ashkenas documentation waypoint
authored
136 # Inheritance and calling super.
b5c9d77 Jeremy Ashkenas updating the Lexer to use classes and some of the older documentation
authored
137 class Animal
2aedbc2 Jeremy Ashkenas Back to naked constructors.
authored
138 (@name) ->
da6ea27 Jeremy Ashkenas most of the examples converted to symbology.
authored
139
b5c9d77 Jeremy Ashkenas updating the Lexer to use classes and some of the older documentation
authored
140 move: (meters) ->
141 alert this.name + " moved " + meters + "m."
142
143 class Snake extends Animal
144 move: ->
145 alert 'Slithering...'
146 super 5
147
148 class Horse extends Animal
149 move: ->
150 alert 'Galloping...'
151 super 45
152
da6ea27 Jeremy Ashkenas most of the examples converted to symbology.
authored
153 sam = new Snake "Sammy the Snake"
154 tom = new Horse "Tommy the Horse"
c7fa9c3 Jeremy Ashkenas documentation waypoint
authored
155
156 sam.move()
157 tom.move()
e3c667d Jeremy Ashkenas number examples
authored
158
159 # Numbers.
da6ea27 Jeremy Ashkenas most of the examples converted to symbology.
authored
160 a_googol = 1e100
161 hex = 0xff0000
162 negative = -1.0
163 infinity = Infinity
164 nan = NaN
9976de7 Jeremy Ashkenas added the 'delete' operator
authored
165
166 # Deleting.
167 delete secret.identity
Something went wrong with that request. Please try again.