Wiki

Changes between Version 4 and Version 5 of AllOfCobraInOnePage

Show
Ignore:
Timestamp:
01/06/14 12:13:28 (11 years ago)
Author:
kobi7
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • AllOfCobraInOnePage

    v4 v5  
    11== All of cobra in one page == 
    2 The purpose is to get a quick glance by looking at the sample code, and have a link to the thorough documentation. 
     2The purpose of this page is to see usage by looking at sample code, and have a link to the thorough documentation. 
    33 
    4 === First sample: an Audio Player, demonstrates general outline === 
     4SORRY, WORK IN PROGRESS 
     5 
     6quick jump: 
     7{{{ 
     8Keywords in Alphabetical Order 
     9 
     10abstract 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 
     14comments: 
     15{{{ 
     16# a one line comment 
     17/# 
     18 
     19a multi-line comment 
     20 
     21 #/ 
     22}}} 
     23{{{ 
     24basic structure: 
     25very top level keywords are the optional "namespace" and "use" 
     26top level keywords are: 
     27interface, 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 
     35examples: 
     36... 
     37 
     38 
     39valid keywords inside a method (def): 
     40you can have "trace, assert" wherever you want inside a method 
     41very useful for debugging are  
     42trace and accepts multiple variables 
     43assert accepts a boolean, with one expression per line. 
     44example: 
     45 
     46 
     47 
     48contracts example: 
     49def 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