User Tools

Site Tools


at:tutorial:basic

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revisionBoth sides next revision
at:tutorial:basic [2007/04/06 08:39] – * elisagat:tutorial:basic [2007/04/06 08:58] – add elisag
Line 275: Line 275:
 ==== Tables ==== ==== Tables ====
    
-TODO!+ 
 +We have already introduce how to define tables. Let us now focus on how to manipulate them with the native methods provided by the table object. 
 +<code> 
 +>def vowels := ["a", "e", "i", "o", "u"
 +>>["a", "e", "i", "o", "u"
 +>vowels.length 
 +>>5 
 +>vowels.at(1) 
 +>>"a" 
 +>vowels.atPut(1, "z"
 +>>"z" 
 +>vowels 
 +>>["z", "e", "i", "o", "u"
 +>vowels.isEmpty() 
 +>>false 
 +>[1,2,3].filter: {|e| e != 2 } 
 +>>[1, 3] 
 +>[1,2,3].map: { |i| i + 1 } 
 +>>[2, 3, 4] 
 +>vowels.select(2,5).implode() 
 +>>"eio" 
 +</code> 
 + 
 +Tables also support some useful iterator methods such as: 
 +<code> 
 +>def sum:= 0;  
 +>>0 
 +>[1,2,3].each: { |i| sum := sum + i } 
 +>>nil 
 +>sum 
 +>>6 
 +>def sumNnum (@args) { 
 +  args.inject: 0 into: { |total, next| total + next} 
 +
 +>><closure:sumNnum> 
 +>sumNnum(1,2,3) 
 +>>6 
 +</code>
  
 ==== Booleans ==== ==== Booleans ====
at/tutorial/basic.txt · Last modified: 2020/02/09 22:05 by elisag