Open jpfairbanks opened 8 years ago
I did some investigations, it looks like we can go through the methods of LightGraphs using something like
fun = filter(x-> x!=:CombinatorialAdjacency
&& string(x)[end]!= '!'
&& (string(x)[1] == 'Δ' || !isupper(string(x)[1]))
&& isa(eval(x),Function)
, names(LightGraphs))
m=methods(fun[1])
defs = m.defs
defs = defs.next
Though I fear that without a layer of abstraction in LightGraphs (JuliaGraphs/LightGraphs.jl#227 again), so that we could use inheritance instead of composition, this will look like an ugly and unstable hack
The Go programming language does not have any inheritance and uses composition for everything. After working in Go for a while, I find composition better than inheritance. I think that using macros we can support it now and the language support will get better in the future. Between the two of us, we have spent more time thinking about how to do it with metaprogramming than it would have taken to just change the code. :smiley:
promotion.jl just contains a table of functions that should convert their arguments to a common number type before application. We could use a similar table to avoid metaprogramming. https://github.com/JuliaLang/julia/blob/master/base/promotion.jl#L172
You could even write the table with sed.
but promote
operates alway between two objects, how would you use it to automatically cast a single object from one type to another?
PS see also https://groups.google.com/forum/#!topic/julia-users/No5oe0RB5lI
In #1 we discussed the need for the Network type to behave as a Graph when calling LightGraphs functions. In this way we are extending the behavior of the type Graph by embedding it into another type. One way to do this is with some metaprogramming that takes every function in a list and creates a new function that first converts the first argument to a SimpleGraph.
The goal is to generate for each function in some list
f(g::SimpleGraph, args...)->f(convert(SimpleGraph, network), args...)