at:tutorial:basic
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revisionNext revisionBoth sides next revision | ||
at:tutorial:basic [2007/04/06 11:38] – * elisag | at:tutorial:basic [2007/04/17 16:43] – tvcutsem | ||
---|---|---|---|
Line 4: | Line 4: | ||
====== Functional and Imperative Programming ====== | ====== Functional and Imperative Programming ====== | ||
- | This part of the tutorial | + | This part of the tutorial |
===== Variables ===== | ===== Variables ===== | ||
- | 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, they just contain | + | 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 |
- | In the examples we use the interactive AmbientTalk shell (iat) where the input and output prompt are represented by > and >> | + | In the examples we use the interactive AmbientTalk shell (iat) where the input and output prompt are represented by > and %%>>%% respectively. |
< | < | ||
Line 19: | Line 19: | ||
</ | </ | ||
- | Variable definitions can be combined with assignments as shown above. As in Pico, assignments uses the ": | + | Variable definitions can include an initialization expression that immediately initializes the variable. Variable assignment is performed by means of the well-known |
- | An assignment consists of one or more expressions, | ||
< | < | ||
>[x, y] := [ y, x ] | >[x, y] := [ y, x ] | ||
>> | >> | ||
</ | </ | ||
+ | |||
+ | As we will explain later, the '' | ||
The variable name is used to refer a variable. The variable is evaluated when referenced. | The variable name is used to refer a variable. The variable is evaluated when referenced. | ||
Line 32: | Line 33: | ||
>>7 | >>7 | ||
</ | </ | ||
+ | |||
+ | < | ||
+ | When using the '': | ||
+ | </ | ||
===== Tables ===== | ===== Tables ===== | ||
Line 66: | Line 71: | ||
==== Table Splicing ==== | ==== Table Splicing ==== | ||
- | TODO! | + | AmbientTalk provides the operator @ to splice tables into surrounding table expressions. |
+ | < | ||
+ | > | ||
+ | >>[1, 2, 3, 4] | ||
+ | >[1, @[2,[3]], [4], @[5], @[], 6] | ||
+ | >>[1, 2, [3], [4], 5, 6] | ||
+ | </ | ||
+ | |||
+ | The splicing operator can be also used for matching table elements as shown below. | ||
+ | < | ||
+ | >def [first, @rest] := [1,2,3,4] | ||
+ | >>[1, 2, 3, 4] | ||
+ | >rest | ||
+ | >>[2, 3, 4] | ||
+ | </ | ||
===== Functions ===== | ===== Functions ===== | ||
Line 197: | Line 216: | ||
>def square := { |x| x * x } | >def square := { |x| x * x } | ||
>>< | >>< | ||
- | >square(1,2) | + | >square(3) |
- | >>3 | + | >>9 |
</ | </ | ||
at/tutorial/basic.txt · Last modified: 2020/02/09 22:05 by elisag