2.6 Conclusion
3.1.6 Assignment Lists
The assignments made by a command are a list of name expressions and value expressions, where each name expression is paired with the value expression it is assigned. An assignment list can be empty, the result of adding a name-value expression pair to an assignment list or the combination of two assignment lists.
Definition 3.9 Assignment lists
There is a set Alist and constructor functions nil, cons and combine satisfying:
nil2Alist
x
2Ene
2Eal
2Alistcons((
x;e
);al
)2Alistal
2Alistbl
2Alist3.1 Expressions ofL 52
(
x;e
)al
will be written for cons((x;e
);al
)and(x;e
)nil will be abbreviated(x;e
).albl
will be written for combine(al;bl
).Function combine? is a recogniser for assignment lists constructed by combination.
combine?:Alist!boolean
combine?(
al
) def= 9(
bl;cl
:Alist):al
=blcl
2 The combination of assignments lists is by the use of the syntactic construct combine. This allows the order of assignments to be preserved. When a sequence of assignment lists is combined, the order in which assignments to a name are made can be determined from the syntax of the assignment lists.
The structure of an assignment list, in the set Alist, is strictly a tree. The assignment lists occurring in processor commands would not be formed using the combine constructor and can be described by the subset of the assignment lists which excludes this constructor. This subset contains the simple assignment lists, corresponding to the usual list structures. The prefix of an assignment list, up to the first combination of lists, is a simple list and an assignment list is made up of the combination of a finite set of simple lists.
Definition 3.10 Simple lists
An assignment list
al
is simple, simple?(al
), if no sub-list ofal
is constructed by combine.simple?:Alist!boolean
simple?(
al
) def=8(
bl
:Alist):blal
):combine?(bl
)Slist is the set of all simple lists, Slistdef
= f
al
:Alistjsimple?(al
)g.Function initial constructs a simple list from the prefix of an assignment list.
initial:Alist!Slist
initial(nil) def = nil initial((
v;x
)al
) def = (v;x
)initial(al
) initial(albl
) def = nil 2 Function initial allows an arbitrary assignment list to be considered as a set of simple lists. This allows the assignments made by an individual list to be examined separately from the remainder of an assignment list.Example 3.10 With assignment lists
al;bl
2 Alist and name-value pairs,a;b
2 (En E), the set of assignment lists, Alist, includesa
(al
bl
)andab
((b
al
)bl
). Neither of these would occur in an command nor would they be formed to describe a sequence of instructions. The result of applying the function initial to the first list is the simple lista
nil and to the second3.1 Expressions ofL 53
Finding Assignments in Lists
An assignment list associates name expressions with the value expressions which they are as- signed. Name expression
x
is associated in states
with a valuev
by an assignment listal
if there is a pair(x
0;e
0 )2(EnE)inal
such thatx
sx
0 andv
se
0. The value associated with a name
x
in a states
byal
is found by traversing the assignment list. If the assignment list is constructed from the addition of a pair(x
1
;e
1)to an assignment list
bl
thenx
1is compared (in state
s
withx
) before searchingbl
. If the assignment list is constructed from the combination of two assignment lists(blcl
)then the listcl
is searched before the listbl
(the choice is arbitrary).Definition 3.11 Membership and find
For an assignment list
al
and states
, the namex
2s En is a member ins
ofal
iff there is a name expression inal
which is equivalent ins
tox
.2 :(EnStateAlist)!boolean
x
2s nil def =falsex
2s(x
1;e
1 )al
def =(x
sx
1 )_(x
2sal
)x
2s(albl
) def =x
2sal
_x
2sbl
Function find searches an assignment list for the value expression assigned to a name expression.
find:(EnAlist)!State!E
find(
x;
nil)(s
) def =x
find(x;
(x
1;e
1 )al
)(s
) def =e
1 ifx
sx
1find(
x;al
) otherwisefind(
x;
(albl
))(s
) def=
find(
x;bl
)(s
) ifx
2sbl
find(
x;al
)(s
) otherwise2 Given a name expression
x
, assignment listal
and states
, the result of find(x;al
)(s
)is the value expression associated with namex
inal
, ifx
is a member ins
ofal
. Ifx
is not a member inx
ofal
, the result is the name expressionx
.Example 3.11 Let
x
1;x
2;x
3 be name expressions,e
1;e
2;e
3;e
4 be expressions,s
a state,al
the assignment list(x
1
;e
2 )(x
2
;e
2)and
bl
the assignment list(x
2;e
3)(
x
3;e
4). Assume that
x
1;x
2 andx
3 are distinct ins
:x
16s
x
2,x
26s
x
3 and
x
16s
x
3. The expressions associated withx
1;x
2andx
3inal
arefind(
x
1;al
)(s
)=e
1;
find (x
2;al
)(s
)=e
2;
find (x
3;al
)(s
)=x
3 The values associated withx
1;x
2andx
3inal
bl
are find(x
1;al
bl
)(s
)=e
1;
find (x
2;al
bl
)(s
)=e
3;
find (x
3;al
bl
)(s
)=e
43.1 Expressions ofL 54