Wiki
Show
Ignore:
Timestamp:
03/20/10 04:42:28 (2 years ago)
Author:
Chuck.Esterbrook
Message:

Improvements to the How-To's.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • cobra/trunk/HowTo/282-PassReferencesToMethods.cobra

    r2127 r2335  
    4747        for cust in customers, print cust 
    4848 
    49         # Yes, there will be lambdas in a future version so 
    50         # the comparison can be inlined in the sort() call. 
     49        # you can localize the comparison code with a closure 
     50        customers.sort(do(a as Customer, b as Customer)) 
     51            return a.name.toLower.compareTo(b.name.toLower) 
     52         
     53        # or a lambda expression 
     54        customers.sort(do(a as Customer, b as Customer)=a.name.toLower.compareTo(b.name.toLower)) 
    5155 
    5256    def orderByName(a as Customer, b as Customer) as int is shared