pharo
pharo copied to clipboard
Get the variable names of objects
This comes from a question on the Discord. I thought it was a nice exercise for me :)
The context, if I'm correct, is that you are playing on the playground and call complex methods that call complex methods, etc. At some point, you want to know the name of temporary variable that hold some objects.
The proposed method Context>>variableNamesOf: just do that
|a b|
a := 'hello'.
b := 'world'.
(thisContext variableNamesOf: a) >>> #(#a).
b := a.
(thisContext variableNamesOf: a) >>> #(#a #b).
Pay attention you have too much fun :)
Hello, I did not understand the do it context is needed. Is it only for the tests?
Context >> searchDoIt
Failing tests not related:
- [CI] Failing test: ProperMethodCategorizationTest>>testNoUncategorizedMethods #11669
- [CI] two failing test in SpCommandTest #11702
If you don't declare the temps variables you get an empty array

I don't know if that is expected or not. But one normally doesn't declare the names of the temp variable in the Playground
Yes, these Variables in the playground are not temps, but WorkspaceVariables, what the compiler does is to add a special "RequestorScope" to the scope hierarchy that has the defintions.
This means that if #variableNamesOf: would ask the scope (and make sure the parent scope is asked, too), we could could find those variables (reading works with #readInContext:, too).
Hi all, what do we do with this?
I will reroll when I have the time.