1+ """
2+ struct Composition{F<:Function}
3+
4+ Store the all the information of a composition learned by an ICN.
5+ """
16struct Composition{F<: Function }
27 code:: Dict{Symbol,String}
38 f:: F
49 symbols:: Vector{Vector{Symbol}}
510end
611
12+ """
13+ Composition(f::F, symbols) where {F<:Function}
14+
15+ Construct a `Composition`.
16+ """
717function Composition (f:: F , symbols) where {F<: Function }
818 code = Dict {Symbol,String} ()
919 return Composition {F} (code, f, symbols)
1020end
1121
22+ """
23+ code(c::Composition, lang=:maths; name="composition")
24+
25+ Access the code of a composition `c` in a given language `lang`. The name of the generated method is optional.
26+ """
1227function code (c:: Composition , lang= :maths ; name= " composition" )
1328 return get! (c. code, lang, generate (c, name, Val (lang)))
1429end
30+
31+ """
32+ composition(c::Composition)
33+
34+ Access the actual method of an ICN composition `c`.
35+ """
1536composition (c:: Composition ) = c. f
37+
38+ """
39+ symbols(c::Composition)
40+
41+ Output the composition as a layered collection of `Symbol`s.
42+ """
1643symbols (c:: Composition ) = c. symbols
1744
1845"""
@@ -25,6 +52,11 @@ function compose(icn::ICN, weigths::BitVector=BitVector())
2552 return Composition (composition, symbols)
2653end
2754
55+ """
56+ generate(c::Composition, name, lang)
57+
58+ Generates the code of `c` in a specific language `lang`.
59+ """
2860function generate (c:: Composition , name, :: Val{:maths} )
2961 aux = map (s -> reduce_symbols (s, " , " , length (s) > 1 ), symbols (c))
3062 def = reduce_symbols (aux, " ∘ " , false )
@@ -62,6 +94,11 @@ function generate(c::Composition, name, ::Val{:Julia})
6294 return documentation * format_text (output, BlueStyle (); pipe_to_function_call= false )
6395end
6496
97+ """
98+ composition_to_file!(c::Composition, path, name, language=:Julia)
99+
100+ Write the composition code in a given `language` into a file at `path`.
101+ """
65102function composition_to_file! (c:: Composition , path, name, language= :Julia )
66103 output = code (c, language; name)
67104 write (path, output)
0 commit comments