4 | | === First sample: an Audio Player, demonstrates general outline === |
| 4 | SORRY, WORK IN PROGRESS |
| 5 | |
| 6 | quick jump: |
| 7 | {{{ |
| 8 | Keywords in Alphabetical Order |
| 9 | |
| 10 | abstract adds all and any as assert base be body bool branch break callable catch char class const continue cue decimal def do dynamic each else end ensure enum event every except expect extend extern fake false finally float for from get has if ignore implements implies import in inherits inlined inout int interface internal invariant is listen lock mixin must namespace new nil nonvirtual not number objc of off old on or out override par partial pass passthrough post print private pro protected public raise ref require return same set shared sig stop struct success test this throw to to? trace true try uint use using var vari virtual where while yield |
| 11 | }}} |
| 12 | |
| 13 | |
| 14 | comments: |
| 15 | {{{ |
| 16 | # a one line comment |
| 17 | /# |
| 18 | |
| 19 | a multi-line comment |
| 20 | |
| 21 | #/ |
| 22 | }}} |
| 23 | {{{ |
| 24 | basic structure: |
| 25 | very top level keywords are the optional "namespace" and "use" |
| 26 | top level keywords are: |
| 27 | interface, class, struct, mixin |
| 28 | inside interface are: |
| 29 | def, pro |
| 30 | inside class are: |
| 31 | def, var, pro, get, set, const, test |
| 32 | inside def there can be: |
| 33 | test, require, ensure, body - or the beginning of code. |
| 34 | |
| 35 | examples: |
| 36 | ... |
| 37 | |
| 38 | |
| 39 | valid keywords inside a method (def): |
| 40 | you can have "trace, assert" wherever you want inside a method |
| 41 | very useful for debugging are |
| 42 | trace and accepts multiple variables |
| 43 | assert accepts a boolean, with one expression per line. |
| 44 | example: |
| 45 | |
| 46 | |
| 47 | |
| 48 | contracts example: |
| 49 | def gap(a as uint, b as uint) as uint |
| 50 | require |
| 51 | 0 <= a <= 1000, 0 <= b <= 1000 |
| 52 | # a >= b # enable this line (or change to ints) to fix the definition |
| 53 | ensure |
| 54 | result <= 1000 |
| 55 | body |
| 56 | res = a - b # is something wrong with this code? (when b > a, uint handles negatives by going to uint's maxvalue) |
| 57 | trace res |
| 58 | |
| 59 | return res |
| 60 | |
| 61 | # without contracts you might get surprising values, not knowing why |
| 62 | }}} |
| 63 | |