3 ms·
That wikipedia definition, IMO, is weird. I would limit reflection to modifying values, metadata and properties, not to modifying functions. Limiting it to tha
by Someone 12y ago
That wikipedia definition, IMO, is weird. I would limit reflection to modifying values, metadata and properties, not to modifying functions.
Limiting it to that is what allows strongly-typed somewhat ahead of time compiled languages such as Java and C# to have reflection.
And yes, C# has support for creating new functions at runtime, but that is not reflection, not in my book, and not in Microsofts's (if it was, they would have put it in the reflection namespace)
Modifying code is a step up. For example, in lisp, it is fairly easy to grab a function, walk its tree for use of integers, and replace every '3' by '4' and every usage of the '+' function by '-'
And the wikipedia examples are amazingly bad, indeed. eval, as in the php example, has nothing to do with reflection. Neither does Objective-C's performSelector. You want to show respondsToSelector; that's what does the introspection part.
- lispm 12y agoIn Lisp it is relatively easy to change a function. A typical thing is 'advising', where some code is added to a function. This had been done to ordinary functions decades ago and Common Lisp added it as a standard to its object system. > Modifying code is a step up. For example, in lisp, it is fairly easy to grab a function, walk its tree for use of integers, and replace every '3' by '4' and every usage of the '+' function by '-' Actually it is not easy. Actually walking Lisp code is relatively complex. The code walker needs to understand built-in Lisp constructs, macros and more.