Julia 0.7 supports method propertynames(x, private=false)
The latest documentation for that method reads
‘‘propertynames(x) may return only “public” property names that are part of the documented interface of x. If you want it to also return “private” fieldnames intended for internal use, pass true for the optional second argument. REPL tab completion on x. shows only the private=false properties.’’
Does Julia 0.7 let you define a property/field as readonly when you define a
or is the overloaded method
propertyname responsible for enforcing
How does the REPL know when a property is private?
Also, how are methods
setproperty expected to deal with private properties?
This has no influence on running code, it is purely for documentation and things like tab completion.
OK, I take it that the property related methods will have to enforce
private=true if desired.
But how does “tab completion” (i.e. the REPL) know that a property is supposed to be private?
It only looks at the
propertynames(x, private=false). It’s up to
x to return the appropriate thing. Right now, the default definition for a struct will return all its fields.
Can create private properties by defining:
function getpublicproperties(x::MyType, field::Symbol)
if field == :a
error("Not a public property")
function getallproperties(x::MyType, field::Symbol)
function Base.getproperty(x::MyType, field::Symbol; public = true)
then you get:
julia> x = MyType(1, 2)
ERROR: Not a public property
 error(::String) at ./error.jl:33
 getpublicproperties at ./REPL:5 [inlined]
 #getproperty#4 at ./REPL:3 [inlined]
 getproperty(::MyType, ::Symbol) at ./REPL:2
julia> getproperty(x, :b, public = false)
I am sure you can do some macro-magic to define these things nicely.