Hello there,
A simple semantic question, and a way to call an inner constructor
Assuming I have a simple structure defined as follows
struct Test
b::Int;
m::Int;
n::Int;
end
But such that we have b = m+n+1. One can built an inner constructor to check that the construction is fine
struct Test
b::Int;
m::Int;
n::Int;
Test(b::Int,m::Int,n::Int) = begin
@assert b == m+n+1 "b should be m+n+1"
return new(b,m,n)
end
end
And the structure can be called by
Test(8,0,7)
And raises an error with Test(8,0,4).
In some cases, I would like to be able to partially defined the structure, i.e call a Test(8,0,) that returns a Test(8,0,7) or Test(8,,7) that returns a Test(8,0,7). Kind of throw-away input argument.
However, I cannot figure out how to call such a function. I was thinking to define function as
Q(b::Int,m::Int,_) = Q(b,m,b-m-1);
Q(b::Int,_,n::Int) = Q(b,b-n-1,n);
But if definition is possible, I can’t instanciate them with
Test(8,0,_)
ERROR: syntax: all-underscore identifier used as rvalue
I understand the error, and
- I know that I can handle the construction using keyword
- Can also define Test(8,0,nothing) that can be handled by multiple dispatch, but I was wondering if such an easy syntax as Q(8,0,) or Q(8,,7) can be used ?
Any advice ?
Thanks