Wiki

Changes between Version 4 and Version 5 of Variables

Show
Ignore:
Timestamp:
01/14/14 11:25:10 (11 years ago)
Author:
hopscc
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • Variables

    v4 v5  
    3434 
    3535{{{ 
     36#!cobra 
    3637s = "name:" # s is a String since thats what it is assigned from 
    3738greet = 'hello ' + 'Mike.' # also a String since the assignment is a (String) expression 
     
    5051Local variables of Reference types should generally be assigned to, to create and type them. 
    5152{{{ 
     53#!cobra 
    5254     s as String  # generates a compiler error    
    5355     # needs to be 
     
    7173 
    7274{{{ 
     75#!cobra 
    7376space = 32_u8 
    7477ispace as int32 = space 
     
    97100 
    98101{{{ 
     102#!cobra 
    99103class VarEG 
    100104    var count = 0  # type inferred from initial value (int32) 
     
    139143 
    140144{{{ 
     145#!cobra 
    141146    # Initializer/Ctor 
    142147    cue init( age as int, name as String) 
     
    153158}}} 
    154159 
    155 In the initializer, instance variable _name is now initialised, [[BR]] 
    156 _definition is nil but thats allowed since its declared nilable. 
     160By the end of the initializer, instance variable _name is fully initialised, [[BR]] 
     161_definition (VarEg._definition) is nil but thats allowed since its declared nilable. 
    157162 
    158163  
     
    169174 
    170175{{{ 
    171  
     176#!cobra 
    172177    # call to create VarEg instance 
    173178    t = VarEG( 157, 'hops') 
     
    194199 
    195200{{{ 
    196  
     201#!cobra 
    197202    t = VarEG( 492, 'hops') 
    198203    oldDefn = t.defn    # local var oldDefn <-  'No defn' 
     
    214219 
    215220{{{ 
     221#!cobra 
    216222    # Note that nItems is incremented in the initializer so it has a count of the  
    217223    # number of instances made