Skip to content

Commit 597e7fb

Browse files
author
duchier
committed
adds to Mapping the following exports: clone, exchange, toRecord
git-svn-id: https://gforge.info.ucl.ac.be/svn/mozart@15976 ada56829-ad1f-0410-b00f-83cda6628aec
1 parent 1c3795f commit 597e7fb

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

Mapping.oz

+22
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ export
55
Items toList:Items
66
Keys arity:Keys
77
Entries toListInd:Entries
8+
Clone Exchange ToRecord
89
prepare
910
fun {Get M Key} M.Key end
1011
proc {Put M Key Value} M.Key := Value end
@@ -68,4 +69,25 @@ prepare
6869
(Lo#A.Lo)|{ArrayToListX A Lo+1 Hi}
6970
end
7071
end
72+
DictClone = Dictionary.clone
73+
ArrayClone = Array.clone
74+
fun {Clone M}
75+
if {IsDictionary M} then {DictClone M}
76+
elseif {IsRecord M} then M
77+
else {ArrayClone M} end
78+
end
79+
DictExchange = Dictionary.exchange
80+
ArrayExchange = Array.exchange
81+
proc {Exchange M Key Old New}
82+
if {IsDictionary M} then {DictExchange M Key Old New}
83+
elseif {IsRecord M} then M.Key=Old=New
84+
else {ArrayExchange M Key Old New} end
85+
end
86+
DictToRecord = Dictionary.toRecord
87+
ArrayToRecord = Array.toRecord
88+
fun {ToRecord Label M}
89+
if {IsDictionary M} then {DictToRecord Label M}
90+
elseif {IsRecord M} then {Adjoin M Label}
91+
else {ArrayToRecord Label M} end
92+
end
7193
end

mapping.html

+8
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,14 @@ <H2>Exports</H2>
8585
<DT><CODE>{Mapping.entries +M ?L}</CODE>
8686
<DT><CODE>{Mapping.toListInd +M ?L}</CODE>
8787
<DD>returns a list of the entries <CODE>Key#Value</CODE> in the mapping
88+
<DT><CODE>{Mapping.clone +M1 ?M2}</CODE>
89+
<DD>returns a clone <CODE>M2</CODE> of the mapping <CODE>M1</CODE>
90+
<DT><CODE>{Mapping.exchange +M +Key ?Old +New}</CODE>
91+
<DD>atomically exchanges the value for <CODE>Key</CODE> in mapping <CODE>M</CODE>:
92+
sets it to <CODE>New</CODE> while returning <CODE>Old</CODE>
93+
<DT><CODE>{Mapping.toRecord +Label +M ?R}</CODE>
94+
<DD>returns a record <CODE>R</CODE> with label <CODE>Label</CODE> representing
95+
the entries in mapping <CODE>M</CODE>
8896
</DL>
8997

9098
<HR>

0 commit comments

Comments
 (0)