-
-
Notifications
You must be signed in to change notification settings - Fork 59
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
Use context-stripped names in str(Expression) #1315
base: master
Are you sure you want to change the base?
Conversation
@@ -765,8 +765,12 @@ def get_elements(self) -> Sequence[BaseElement]: | |||
def get_head(self): | |||
return self._head | |||
|
|||
def get_head_name(self): | |||
return self._head.name if isinstance(self._head, Symbol) else "" | |||
def get_head_name(self, short=False) -> str: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is OK
@@ -317,7 +317,7 @@ def __repr__(self) -> str: | |||
|
|||
def __str__(self) -> str: | |||
return "%s[%s]" % ( | |||
str(self.head), | |||
self.get_head_name(short=True), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This could be a problem if there are symbols with the same name in different contexts, which is something that you would want to detect in debugging.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
repr
still shows the long names.
Personally in my debugging, I don't recall needing this yet. And in WMA I am seeing short names used in errors and tracing.
We could add a user-defined setting, but this is more complicated.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is because WMA uses FullForm
to show expressions "without formatting". For example,
In[1]:= F[s`p,t]//FullForm
Out[1]//FullForm= F[s`p, t]
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is useful and related, but different.
This is a useful Mathics3 user function. But in addition, there is always the need for lower-level displays of elements. These functions get called and appear in error messages as well as in that TraceEvaluation.
What I've been noticing is that WMA does not fill out context paths when reporting error messages and we do. I can't find a good example of this but I am sure you've seen experienced these.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, because WMA uses "FullForm". We use just str()
or repr()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok - then this can wait until after we have boxing under control and get superseded.
Maybe #1316 could be useful. Instead of |
If you can find evidence of WMA doing something like this in its trace routines like |
Let`s see if this helps. This is what happends in WMA, if I interrupt the evaluation with Ctrl+C:
In any case, it is not a great debugger either... |
Notice that in the example "Show" shows the FullForm of the current expression, and "Trace" shows the variables without the context. |
In neither case am I seeing Thanks for the information. I am sure in the future we will be able to provide this and much more. But now is probably not the time to add this. I was looking for small non-controversial user-facing issues. |
In the str(Expression), show
Head
as a context-stripped name, e.g.Plus
instead ofSystem`Plus
. We see these long names inTraceEvaluation
and in error messages. With this change we now will see:instead of:
which is what I think is desired most of the time. In the rare occasions where one wants the full context path,
repr()
shows that.Also, in the future I think we will have better debugging features that can fill out this information on demand.