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/17 16:43] tvcutsemat:tutorial:basic [2007/04/17 16:51] tvcutsem
Line 40: Line 40:
 ===== Tables ===== ===== Tables =====
  
-Indexed tables represent what other languages call arrays or listsTables are unidimensional and their indexes range from 1 to the size of the tableAs variables, one can define, assign and refer to a table. Table definition is also made  with the keyword **def** in the following form:+The //table// is AmbientTalk's native compound data type. It is akin to what other languages call //arrays//The main difference is that tables are indexed from ''1'' up to their ''length'', while arrays are indexed from ''0'' up to ''length-1''Like with variables, one can define, assign and refer to a table. Table definitions are also formed with the keyword **def** in the following format:
 <code> <code>
-def t[ <size> ] { <expression> }+def t[ <sizeexpression> ] { <initexpression> }
 </code> </code>
-This means that the <expressionwill be evaluated <sizetimes, i.e., one for each slot of the table. This allows expressions such as initializing a table of ascending numbers as shown below:+This constructs a table, the size of which is determined by ''<sizeexpression>''. The content of each slot is the result of evaluating ''<initexpression>''This means that ''<initexpression>'' is evaluated for each slot in the table! Tables of e.g. ascending numbers are easily formed: 
 <code> <code>
 >def z := 0 >def z := 0
Line 52: Line 53:
 </code> </code>
  
-Although there is no special constructor for definition of multidimensional tables, a table entry can contain another table. This is internally stored as a unidimensional table whose entries are other tables.+Although there is no special constructor for definition of multidimensional tables, a table entry can contain another table. This is internally stored as a one-dimensional table whose entries are other tables.
 <code> <code>
 >def vowels := ["a", "e", "i", "o", "u"] >def vowels := ["a", "e", "i", "o", "u"]
Line 62: Line 63:
 </code> </code>
  
-As shown in the definition of the varible //vowels//evaluating a series of comma-separated data types between square brackets (aka a tabulation) results in table.+As shown in the definition of the variable ''vowels''AmbientTalk provides literal syntax to encode in-line tables. Table assignment and indexation work as usual, but recall that table indices range from ''1'' up to ''table.length''. Some more examples of literal tables:
  
 <code> <code>
at/tutorial/basic.txt · Last modified: 2020/02/09 22:05 by elisag