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 revision
Previous revision
Next revisionBoth sides next revision
at:tutorial:basic [2007/04/17 16:40] tvcutsemat:tutorial:basic [2007/04/17 16:51] tvcutsem
Line 10: Line 10:
 As usual, one can define, assign and refer to a variable. Variable definitions are made with the keyword **def**. Note that AmbientTalk is a dynamically typed language, so variables do not have a type but can contain any value. As usual, one can define, assign and refer to a variable. Variable definitions are made with the keyword **def**. Note that AmbientTalk is a dynamically typed language, so variables do not have a type but can contain any value.
  
-In the examples we use the interactive AmbientTalk shell (iat) where the input and output prompt are represented by > and <code>>></code> respectively. +In the examples we use the interactive AmbientTalk shell (iat) where the input and output prompt are represented by > and %%>>%% respectively. 
  
 <code> <code>
Line 35: Line 35:
  
 <note> <note>
-When using the '':='' assignment operator, beware of the following syntactic annoyance: the expression ''a := 1'' denotes an assignment to the variable "a", while ''a:= 1'' is misunderstood by the parser as "a: = 1", which is the invocation of a keyworded message named ''a:''. Keyworded message sends will be explained later on in this chapter. Hence, as a general rule, don't forget to always put a space between the variable name and the '':='' operator.+When using the '':='' assignment operator, beware of the following syntactic annoyance: the expression ''a := 1'' denotes an assignment to the variable ''a'', while ''a:= 1'' is misunderstood by the parser as ''a: = 1'', which is the invocation of a keyworded message named ''a:''. Keyworded message sends will be explained later on in this chapter. Hence, as a general rule, don't forget to always put a space between the variable name and the '':='' operator.
 </note> </note>
  
 ===== 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