-
Notifications
You must be signed in to change notification settings - Fork 34
fix bug - removePrefix() #150
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Allows for parameterized custom nodes with custom types.
Thanks for catching this. I started refactoring and came up with a more general recursive implementation: function removePrefix(T::DataType)
main_type_str = string(nameof(T)) # Strip leading module names and convert T to a string
param_types = T.parameters # Find parameterized types of T
if isempty(param_types) # If T is not parameterized further
return main_type_str # Stop-condition, return main name
else
# Recursively build a vector of strings for the parameter types
param_type_strs = []
for param_type in param_types
push!(param_type_strs, removePrefix(param_type)) # Recursive call
end
param_type_str = join(param_type_strs, ", ") # Join the constructed vector to a comma-separated string
return "$main_type_str{$param_type_str}" # Construct the parameterized type string
end
end This could be tested for a nested definition, like: module Foo
struct Baz
f::Int64
end
struct Bar{T}
f::T
end
struct Bak{T, K}
f::T
g::K
end
end
baz = Foo.Baz(1)
bar = Foo.Bar(baz)
bak = Foo.Bak(bar, bar)
removePrefix(typeof(baz))
removePrefix(typeof(bar))
removePrefix(typeof(bak)) |
To allow for the change in the removePrefix() function, some tests have been changed by changing `Message` to `ForneyLab.Message`.
Thanks for the suggestion Thijs. I changed the |
Thanks for the implementation, I did not think about how this would affect the |
This reverts commit 392ce28.
The proposed function originally had issues with the following: In order to solve this, the original function with input The latest commits revert the changes to the tests, add new tests and reintroduce the original function as a backup to the new function. |
Allows for parameterized custom nodes with custom types.