You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+13-1Lines changed: 13 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -18,11 +18,23 @@ Pkg.add("AcuteML")
18
18
```julia
19
19
using AcuteML
20
20
```
21
+
21
22
# Documentation
22
23
Click on the badge: [](https://aminya.github.io/AcuteML.jl/dev)
23
24
24
25
See [Type Definition](https://aminya.github.io/AcuteML.jl/dev/#Main-macro-and-I/O-1) for a comprehensive introduction to syntax. You can use `@aml` macro to define a Julia type, and then the package automatically creates a xml or html associated with the defined type.
25
26
27
+
# Readme Content
28
+
-[Installation and Usage](#installation-and-usage)
Copy file name to clipboardExpand all lines: docs/src/customConstructors.md
+114-2Lines changed: 114 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,5 +1,117 @@
1
-
# Custom Constructors - AcuteML Backend
2
-
## Making a Type and constructor from scratch
1
+
# Custom Constructors
2
+
3
+
## Adding Custom code to the structures
4
+
5
+
AcuteML introduces three `@creator`, `@extractor`, and `@updater` macros to be used inside `@aml` definition. The location of the macros specifies their location in the function. For example, putting `@creator` at the begining, adds the code to begining of creator function.
6
+
7
+
8
+
- Put `@creator` inside `@aml` to add a custom code to the creator function (DOM creation when the struct is instanciated).
9
+
10
+
This macro only affects creation (not extraction/updating), but can be used in combination with other macros.
11
+
12
+
- Put `@extractor` inside `@aml` to add a custom code to the extractor function (DOM parsing when a html/xml text is used for instanciation of a struct).
13
+
14
+
This macro only affects creation (not creation/updating), but can be used in combination with other macros.
15
+
16
+
Be careful that setting struct fields using `@extractor` only changes the struct field and not the xml code.
17
+
18
+
- Put `@updater` inside `@aml` to add a custom code to the updater function (DOM updating after instanciation of a struct).
19
+
20
+
This macro only affects updating (not creation/extraction), but can be used in combination with other macros.
21
+
22
+
In the following example `IQ` and `average` are calculated automatically. Also, in the following example `log` is filled automatically (which doesn't have an associated xml element).
23
+
24
+
```julia
25
+
using AcuteML
26
+
# Definition
27
+
@amlmutable struct Student "student"
28
+
29
+
# add custom code to the begining of creator function
30
+
# the following automatically fills IQ based on the name
31
+
@creatorbegin
32
+
ifoccursin("smart", name)
33
+
name =replace(name, "-smart"=>"") # remove smart from name
34
+
IQ ="smart"
35
+
elseifoccursin("genius", name)
36
+
name =replace(name, "-genius"=>"") # remove smart from name
37
+
IQ ="genius"
38
+
else
39
+
error("Give a smart student.")
40
+
end
41
+
end
42
+
43
+
name::String, "~"
44
+
GPA::Float64, "~"
45
+
IQ::UN{String}=nothing, att"~"# default to nothing, but filled automatically by first @cretor macro
46
+
# add custom code to the end of extractor function
47
+
48
+
log::UN{String}=nothing, "~"
49
+
50
+
@extractorbegin
51
+
if GPA >4.0
52
+
log ="A genius with a GPA of $GPA is found"# setting fields using @extractor only changes the field and not the xml code
53
+
end
54
+
end
55
+
end
56
+
57
+
@amlmutable struct MathClass "math-class"
58
+
@creatorbegin
59
+
GPAsum =0.0
60
+
for student in students
61
+
GPAsum = GPAsum + student.GPA
62
+
end
63
+
average = GPAsum /length(students) # fill average field
0 commit comments