-
Notifications
You must be signed in to change notification settings - Fork 31
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
Properties #18
Comments
I was going to ask for the same. I want some user to be able to set Can't promise anything unfortunately but I'll try to have a look and see if I can make a PR. |
Just to be a little bit more precise, one can currently do @with_kw type P
a=1
b=2
c=a+3b
end but a user will be able to overwrite the @with_kw type P
a=1
b=2
@nokw c=a+3b
end |
Tnx for your interest. With Julia 0.7 this could be done via properties. So, maybe it should be a 0.7 only feature? |
I'm not sure I understand, could you elaborate? |
I see that this could be used to hide the field |
Yes, you'd need to mark a "field" with |
This would be an ok syntax: @with_kw struct A
a
b <= sin(a) + 5
end i.e. the Also, properties would be read-only (also for mutable types) as it gets too complicated otherwise. |
Although, even with properties, it might be nice to have fields which are calculated for performance reasons: @with_kw struct A
a
@set b = really_expensive_function(a) + 5
end |
AFAIU we want two features:
Correct? |
Case 1. would be doable by having @with_kw struct A {F<:Function}
a
b
c::F = (a::A)->(a.a+2a.b)
end
d = A(1,2) and then |
But how would you know when one wants to store a function in a field vs when it should be used as a property-function? I think it would still need to be marked somehow, no? |
That depends on how convenient the syntax should be, the code above works right now as it is. @with_kw struct A {F<:Function}
a
b
c::F = a+2b
end The information that |
But if I have, say a ODE problem which defaults to exponential growth:
Now, |
It would be cool to have fields which are always calculated:
would translate into something like
(i.e. there would be no constructor which allows setting
c
)The text was updated successfully, but these errors were encountered: