( @(user) ) Login/Signup Logout
The Dao Programming Language
for Scripting and Computing

Home Documentation Download Blog Forum Projects Demo
Label: ♦english ♦feature request

[594] methods in "reflect" to list all routines and classes of a namespace. And more.

Comment
Hello again,

I tried all routines and found none to list me all classes and routines of a namespace, thus I concluded that there is none yet, right?
It could be as simple (?) as allowing the "constant" and "variable" methods to accept namespaces as parameters, I could then use it like:
reflect.constant(reflect.namespace())
Which I would expect to give me a list of classes and routines defined in the given namespace. (That is the current namespace in the above example.)

Also, there is a complete lack of reflection support in any of the lately added features. Amongst the possible candidates I am thinking of are: (from most to leas important to me)
  1. list all decorators attached to a routine,
  2. handling of interfaces. Essentially listing their routines and attributes, probably using reflect.constant and reflect.variable,
  3. list of meta-fields of an object,
  4. list all interfaces a class is bound to,
  5. list all typedefs, also decide if reflect.type should return the alias or the effective type,
  6. list all values an enum can take and
  7. list all allowed types a disjoint union may have (vs the one it actually holds, as reported by reflect.type),
  8. what about templates? Didn't try them.
Please note that for me, only the first one is a feature I'd actually need, while the others are just what I came up when thinking about what would be needed to programming a Dao IDE in Dao.

Finally, using a method called "constant" to get a list of routines feels awkward to me. I can understand the implementation-side reason for it, but any sane user would think it just returns the actual constants defined in the class. The documentation "Return the constant fields of object, ..." doesn't alleviate that either :-) My proposal would be to have "constant" really only return constants, adding a new method called "routines" which returns routines only. And yet another one "metafields" returning only the meta-fields, etc. :)
And while I'm at the names, I'd add an "s" to the name of all the reflection routines that can return more than one value, i.e. that return a list. For example, it should be "constant s ", "param s ", etc.

That's all from me for today, it's more than enough :-)
Comments
I have been considering to remove "reflect", and redesign some essential reflection functions as part of "std" (which also need some redesigning). Your suggestions seem very helpful for this.
Great! A powerful reflection library (depending on the size, I would probably keep it in "reflect" in order not to grow "std" too much) is very important for language-supporting libraries. I'm prototyping a unit-testing library and really felt the need for it :-)

Edit: funny thing, I just saw this commented-out line in DaoQtCore.dao
#stdio.println( reflect.constant( reflect.namespace() ).keys() );
Seems that what I asked for was supported some time ago :-)
I don't report this as a bug, because you want to redesign the whole reflection thing anyway, but the string version of reflect.isa doesn't seem to work:
(dao) io.println(reflect.isa(Exception.Error("Hi"),"Exception.Error"))
0
(dao) io.println(reflect.isa(Exception.Error("Hi"), reflect.type(Exception.Error("Ho"))))
1
(dao) io.println(reflect.isa(Exception.Error.Value("Hi"), "Exception.Error"))
0
(dao) io.println(reflect.isa(Exception.Error.Value("Hi"), reflect.type(Exception.Error("Ho"))))
1
The output should actually always be 1.
Right, they were supported before, but were then broken due to some changes in the implementation of namespace and class.
"Exception.Error" is not supported in type name, if you use
io.println(reflect.isa(Exception.Error("Hi"),"Exception::Error"))
it will work. This will be fixed.
Seems it is the same error I did as in my bugreport, thanks for pointing this out :)

Change picture:

Choose file:
Visitor Map This site is powered by Dao
Copyright (C) 2009-2013, daovm.net.
Webmaster: admin at daovm dot net