-
Notifications
You must be signed in to change notification settings - Fork 235
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
Improve "key not found" error messages for string/symbol keys #3409
Conversation
Oh that's awesome! |
Several comments:
|
well, my PR is going to take a while to come, because there are problems with my approach, as you have pointed out:
Though I have a more or less working implementation of my ideas (which is currently tested in Macaulay2Web), I'm not going to rush to submit a PR. |
Sounds good. When you do make the PR, I would appreciate it if it was broken up into multiple commits each with a specific objective. |
97412f0
to
a35e97f
Compare
We don't know how to represent arbitrary objects as strings at this low level, but this takes care of two very common cases.
a35e97f
to
125d3ed
Compare
Okay I actually thought about this and I think I know how to call a robust printing method from interpreter. Can I push here or should I make a new PR? |
I'll push this for now, but feel free to revert of course. Here's the proposed output: i1 : h#123
currentString:1:2:(3):[4]: error: key not found in hash table: 123 (of class ZZ)
i1 : h#(id_(ZZ^2))
currentString:1:2:(3):[4]: error: key not found in hash table:
| 1 0 | (of class Matrix)
| 0 1 |
i1 : h#blah
currentString:1:2:(3):[4]: error: key not found in hash table: blah (of class Symbol)
i1 : h#"blah\"foo"
currentString:1:2:(3):[4]: error: key not found in hash table:
"blah\"foo" (of class String) (Whether it goes on a new line or not depends on length/depth/height) Paul can edit the I can't think of an example that breaks the time limit, but if you can think of one let me know. |
Oh this actually works beautifully even in the event of slow printing or errors in printing: i1 : h = new HashTable from {};
i2 : T = new Type of List
o2 = T
o2 : Type
i3 : t = new T from {"test", "me"};
i4 : elapsedTime h#t -- should instantly print "{test, me} (of class T)"
stdio:4:13:(3): error: key not found in hash table: {test, me} (of class T)
-- 0.000618107 seconds elapsed
i5 : net T := t -> error "can't print me"
o5 = FunctionClosure[stdio:5:9-5:36]
o5 : FunctionClosure
i6 : elapsedTime h#t -- should instantly print "new T from {"test","me"} (of class T)"
stdio:6:13:(3): error: key not found in hash table:
new T from {"test","me"} (of class T)
-- 0.000275408 seconds elapsed
i7 : net T := t -> horizontalJoin("1", (sleep 1; toString(#t)), "3")
o7 = FunctionClosure[stdio:7:9-7:63]
o7 : FunctionClosure
i8 : elapsedTime h#t -- should print after 1s "124 (of class T)"
stdio:8:13:(3): error: key not found in hash table: 123 (of class T)
-- 1.0007 seconds elapsed
i9 : net T := t -> horizontalJoin("1", (sleep 5; toString(#t)), "3")
o9 = FunctionClosure[stdio:9:9-9:63]
o9 : FunctionClosure
i10 : elapsedTime h#t -- should print after 3s "new T from {"test","me"} (of class T)"
stdio:10:13:(3): error: key not found in hash table:
new T from {"test","me"} (of class T)
-- 3.00068 seconds elapsed |
Looks good to me! |
Do you think the extra lines of the output should be commentized or not? We're not very consistent: i1 : A + B
stdio:1:3:(3): error: no method for binary operator + applied to objects:
-- A (of class Symbol)
-- + B (of class Symbol)
i2 : sum(A, B)
stdio:2:1:(3): error: no method found for applying sum to:
argument 1 : A (of class Symbol)
argument 2 : B (of class Symbol) |
I'm leaning towards not commenting them so that they can be syntax highlighted. |
e.g. A+B (where A and B are undefined symbols)
For consistency, I decided it's simpler to always print the missing key in a new line, and also to remove the comments from missing operator method errors. (e.g. |
yes this looks similar to my changes, except I have a mode-dependent behaviour (similar to Print, AfterPrint, etc), and also it applies to all error messages, obviously. will review more carefully now. |
by now the only failure would be something like:
which admittedly is pretty rare. |
This was the motivation for the name Regarding the error in |
in principle there are two different places where to make code mode-dependent:
I had indeed done the latter for [my analogue of] Relatedly, I also experimented with a new type of |
Say we wanted to use xterm-256color in terminal output, then doing it at the interpreter would make a lot more sense, both for speed of character setting and because that's where printing really happens. But in principle I agree with you that if it can be in top-level there's no reason to force it in the interpreter. |
We don't know how to represent arbitrary objects as strings at this low level, but this takes care of two very common cases.
Before
After