-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path05-regions3.frank
More file actions
42 lines (34 loc) · 1.17 KB
/
05-regions3.frank
File metadata and controls
42 lines (34 loc) · 1.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# 04-regions2.frank covered how ownership is enfored with regions.
# This example covers some built-in functions for regions.
r1 = Region()
r1.data1 = {}
r1.data2 = {}
# The `is_closed()` function can be used to check if a region
# is open. Region 1 is currently considered open since it has
# an incoming reference from the local region.
res = is_closed(r1)
# Region 2 is created to be the new owner of Region 1.
r2 = Region()
r2.child = r1
# The `close()` function can be used to set all incoming local
# references to None.
close(r1)
# We can also check the status with `is_closed`.
res = is_closed(r2.child)
# A subregion can be merged into its parent region, with the
# `merge()` function. The bridge object of the subregion loses
# the `[RegionObject]` prototype, since it is no longer the bridge
# object of a region.
merge(r2.child, r2)
# Regions can also be dissolved, thereby moving all contained
# objects back into the local region.
#
# This function differs syntactically from the paper which
# uses `merge(r2)`.
dissolve(r2)
# This can be used to reconstruct regions. This example uses
# a for loop:
r1 = Region()
for key, value in r2.child:
r1[key] = value
r2.child = r1