Skip to content

Commit 1100d9f

Browse files
authored
Merge pull request #27 from aminya/mutability
Mutability
2 parents 8b732ef + 92e3413 commit 1100d9f

7 files changed

Lines changed: 422 additions & 79 deletions

File tree

README.md

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -34,21 +34,21 @@ Use `@aml` macro to define a Julia type, and then the package automatically crea
3434
### Document Defnition
3535
* Use `xd""` or `hd""` to define a XML or HTML document:
3636
```julia
37-
@aml struct Doc xd""
37+
@aml mutable struct Doc xd""
3838
# add fields (elements) here
3939
end
4040
```
4141

4242
### Nodes (Elements) Defnition
4343
* Specify the html/xml struct name as a string after the struct name after a space
4444
```julia
45-
@aml struct Person "person"
45+
@aml mutable struct Person "person"
4646
# add fields (elements) here
4747
end
4848
```
4949
* If the html/xml name is the same as struct name, you can use `"~"` instead
5050
```julia
51-
@aml struct person "~"
51+
@aml mutable struct person "~"
5252
# add fields (elements) here
5353
end
5454
```
@@ -98,7 +98,7 @@ GPA::Float64, "~", GPAcheck
9898

9999
* To define any restrictions for multiple values of a struct, define a function that gets all the variables and checks a criteria and returns Bool, and put its name after a `,` after the struct name:
100100
```julia
101-
@aml struct Person "person", courseCheck
101+
@aml mutable struct Person "person", courseCheck
102102
# ...
103103
end
104104
```
@@ -129,22 +129,23 @@ using AcuteML
129129
# Types definition
130130

131131
# Person Type
132-
@aml struct Person "person", courseCheck
133-
age::UInt, "~"
132+
@aml mutable struct Person "person", courseCheck
133+
age::UInt64, "~"
134134
field, "study-field"
135135
GPA::Float64 = 4.5, "~", GPAcheck
136136
courses::Vector{String}, "taken-courses"
137137
id::Int64, a"~"
138138
end
139139

140-
@aml struct University "university"
140+
@aml mutable struct University "university"
141141
name, a"university-name"
142142
people::Vector{Person}, "person"
143143
end
144144

145-
@aml struct Doc xd""
145+
@aml mutable struct Doc xd""
146146
university::University, "~"
147147
end
148+
148149
```
149150

150151
```julia
@@ -173,6 +174,8 @@ end
173174
P1 = Person(age=24, field="Mechanical Engineering", courses=["Artificial Intelligence", "Robotics"], id = 1)
174175
P2 = Person(age=18, field="Computer Engineering", GPA=4, courses=["Julia"], id = 2)
175176

177+
P2.GPA=4.2 # mutability support
178+
176179
U = University(name="Julia University", people=[P1, P2])
177180

178181
D = Doc(university = U)
@@ -207,7 +210,7 @@ julia> print(U.aml)
207210
<person id="2">
208211
<age>18</age>
209212
<study-field>Computer Engineering</study-field>
210-
<GPA>4</GPA>
213+
<GPA>4.2</GPA>
211214
<taken-courses>Julia</taken-courses>
212215
</person>
213216
</university>
@@ -225,12 +228,11 @@ julia> print(D.aml)
225228
<person id="2">
226229
<age>18</age>
227230
<study-field>Computer Engineering</study-field>
228-
<GPA>4</GPA>
231+
<GPA>4.2</GPA>
229232
<taken-courses>Julia</taken-courses>
230233
</person>
231234
</university>
232235
```
233-
234236
-------------------------------------------------------
235237

236238
# Example - Extractor

docs/src/index.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,21 +31,21 @@ Use `@aml` macro to define a Julia type, and then the package automatically crea
3131
### Document Defnition
3232
* Use `xd""` or `hd""` to define a XML or HTML document:
3333
```julia
34-
@aml struct Doc xd""
34+
@aml mutable struct Doc xd""
3535
# add fields (elements) here
3636
end
3737
```
3838

3939
### Nodes (Elements) Defnition
4040
* Specify the html/xml struct name as a string after the struct name after a space
4141
```julia
42-
@aml struct Person "person"
42+
@aml mutable struct Person "person"
4343
# add fields (elements) here
4444
end
4545
```
4646
* If the html/xml name is the same as struct name, you can use `"~"` instead
4747
```julia
48-
@aml struct person "~"
48+
@aml mutable struct person "~"
4949
# add fields (elements) here
5050
end
5151
```
@@ -95,7 +95,7 @@ GPA::Float64, "~", GPAcheck
9595

9696
* To define any restrictions for multiple values of a struct, define a function that gets all the variables and checks a criteria and returns Bool, and put its name after a `,` after the struct name:
9797
```julia
98-
@aml struct Person "person", courseCheck
98+
@aml mutable struct Person "person", courseCheck
9999
# ...
100100
end
101101
```

examples/constructor.jl

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,21 @@
11
using AcuteML
22

33
# Type Definition
4-
@aml struct Person "person", courseCheck
5-
age::UInt, "~"
4+
5+
@aml mutable struct Person "person", courseCheck
6+
age::UInt64, "~"
67
field, "study-field"
78
GPA::Float64 = 4.5, "~", GPAcheck
89
courses::Vector{String}, "taken-courses"
910
id::Int64, a"~"
1011
end
1112

12-
@aml struct University "university"
13+
@aml mutable struct University "university"
1314
name, a"university-name"
1415
people::Vector{Person}, "person"
1516
end
1617

17-
@aml struct Doc xd""
18+
@aml mutable struct Doc xd""
1819
university::University, "~"
1920
end
2021

@@ -38,18 +39,25 @@ end
3839
# Constructor
3940

4041
P1 = Person(age=24, field="Mechanical Engineering", courses=["Artificial Intelligence", "Robotics"], id = 1)
41-
P2 = Person(age=18, field="Computer Engineering", GPA=4, courses=["Julia"], id = 2)
4242

43-
U = University(name="Julia University", people=[P1, P2])
43+
P2 = Person(age=18, field="Computer Engineering", GPA=4, courses=["Julia"], id = 2)
4444

45-
D = Doc(university = U)
45+
P2.GPA=4.2 # mutability support
4646

47-
# An example that doesn't meet the critertia function for GPA because GPA is more than 4.5
47+
# Two examples that doesn't meet the critertia function for GPA because GPA is more than 4.5
4848
#=
4949
P3 = Person(age=99, field="Macro Wizard", GPA=10, courses=["Julia Magic"], id = 3)
50-
#GPA doesn't meet criteria function
50+
# GPA doesn't meet criteria function
51+
52+
P1.GPA=5.0
53+
# GPA doesn't meet criteria function
5154
=#
5255

56+
U = University(name="Julia University", people=[P1, P2])
57+
58+
D = Doc(university = U)
59+
60+
5361
print(P1.aml)
5462
#=
5563
<person id="1">
@@ -66,7 +74,7 @@ print(P2.aml)
6674
<person id="2">
6775
<age>18</age>
6876
<study-field>Computer Engineering</study-field>
69-
<GPA>4</GPA>
77+
<GPA>4.2</GPA>
7078
<taken-courses>Julia</taken-courses>
7179
</person>
7280
=#
@@ -84,7 +92,7 @@ print(U.aml)
8492
<person id="2">
8593
<age>18</age>
8694
<study-field>Computer Engineering</study-field>
87-
<GPA>4</GPA>
95+
<GPA>4.2</GPA>
8896
<taken-courses>Julia</taken-courses>
8997
</person>
9098
</university>
@@ -104,7 +112,7 @@ print(D.aml)
104112
<person id="2">
105113
<age>18</age>
106114
<study-field>Computer Engineering</study-field>
107-
<GPA>4</GPA>
115+
<GPA>4.2</GPA>
108116
<taken-courses>Julia</taken-courses>
109117
</person>
110118
</university>

examples/extractor.jl

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,24 @@
11
using AcuteML
22

33
# Type Definition
4-
@aml struct Person "person", courseCheck
5-
age::UInt, "~"
4+
@aml mutable struct Person "person", courseCheck
5+
age::UInt64, "~"
66
field, "study-field"
77
GPA::Float64 = 4.5, "~", GPAcheck
88
courses::Vector{String}, "taken-courses"
99
id::Int64, a"~"
1010
end
1111

12-
@aml struct University "university"
12+
@aml mutable struct University "university"
1313
name, a"university-name"
1414
people::Vector{Person}, "person"
1515
end
1616

17-
@aml struct Doc xd""
17+
@aml mutable struct Doc xd""
1818
university::University, "~"
1919
end
2020

21+
2122
# Value Checking Functions
2223
GPAcheck(x) = x <= 4.5 && x >= 0
2324

0 commit comments

Comments
 (0)