@@ -217,13 +217,13 @@ statement a value belongs to:
217217 "hello",
218218 "world"
219219 print "hello"
220- print "I am inside if"
220+ print "I am inside if"
221221
222222 if func 1,2,3,
223223 "hello",
224224 "world"
225225 print "hello"
226- print "I am inside if"
226+ print "I am inside if"
227227
228228
229229## Table Literals
@@ -294,7 +294,7 @@ doubled.
294294
295295The items included in the new table can be restricted with a ` when ` clause:
296296
297- iter = ipairs items
297+ iter = ipairs items
298298 slice = [item for i, item in iter when i > 1 and i < 3]
299299
300300Because it is common to iterate over the values of a numerically indexed table,
@@ -510,15 +510,15 @@ instances, so modifications to it in one instance will show up in another:
510510 a\give_item "pants"
511511 b\give_item "shirt"
512512
513- -- will print both pants and shirt
513+ -- will print both pants and shirt
514514 print item for item in *a.clothes
515515
516516The proper way to avoid this problem is to create the mutable state of the
517517object in the constructor:
518518
519519 class Person
520- new: =>
521- @clothes = {}
520+ new: =>
521+ @clothes = {}
522522
523523### Inheritance
524524
@@ -565,21 +565,26 @@ will not be assigned locally.
565565This is especially useful when declaring what will be externally visible in a
566566module:
567567
568- -- my_module.moon
569- module "my_module", package.seeall
568+ -- my_module.moon
569+ module "my_module", package.seeall
570570 export print_result
571571
572- length = (x, y) -> math.sqrt x*x + y*y
572+ length = (x, y) -> math.sqrt x*x + y*y
573+
574+ print_result = (x, y) ->
575+ print "Length is ", length x, y
576+
577+ -- main.moon
578+ require "my_module"
573579
574- print_result = (x, y) ->
575- print "Length is ", length x, y
580+ my_module.print_result 4, 5 -- prints the result
576581
577- -- main.moon
578- require "my_module"
582+ print my_module.length 6, 7 -- errors, `length` not visible
579583
580- my_module.print_result 4, 5 -- prints the result
584+ Assignment can be combined with the export keyword to assign to global
585+ variables directly:
581586
582- print my_module.length 6, 7 -- errors, `length` not visible
587+ export some_number, message_str = 100, "hello world"
583588
584589### Export All & Export Proper
585590
@@ -675,11 +680,11 @@ with no argument list provided.
675680 func!
676681
677682 -- this will not work:
678- -- the function has to no reference to my_object
683+ -- the function has to no reference to my_object
679684 run_callback my_object.write
680685
681686 -- function stub syntax
682- -- lets us bundle the object into a new function
687+ -- lets us bundle the object into a new function
683688 run_callback my_object\write
684689
685690## The Using Clause; Controlling Destructive Assignment
0 commit comments