-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
Mapping of Dicts: How to interpret error message? #18713
Comments
Here is a short syntax that works: map(kv -> kv[1]=>kv[2]^2, d) I would think that we should also accept tuples, though. |
The Looking through the source, calling Based on my understanding, The error is admittedly rather cryptic in your particular scenario, since it's not obvious that Does that sort of make sense? (To anyone reading: Please let me know if anything I've said is false or misleading!) |
Spot on. Worth cross-referencing #17968, which hopefully made the error message clearer, but not clear enough. (The old message would have been |
@timholy I think the error is perfectly clear coming from |
The fact that you missed it might mean it's not clear enough. The tricky part is coming up with something better. Maybe show examples of valid syntax? E.g., Example valid syntaxes:
map(kv[1]=>abs(kv[2]), dict) # creates another Dict, of key=>abs(value)
[kv[2] for kv in dict] # creates an array of values
[(kv[1], kv[2]) for kv in dict] # creates an array of (key,value) tuples or something like that. |
To be honest, I actually think the existing error message is fine if the line break before the bit about |
Thanks for the explanation, @ararslan. I did not know about the difference between
Yes, I originally had the code
I had no clue about the role of Also, I think the part about "if calling map, consider a comprehension instead" is not very helpful (even if it mentions
works perfectly fine - without using a comprehension. So this part of the message does not help to understand what the real problem is actually. Is it possible to mention the element type? I would suggest the following: To construct an Associative, similar() requires an element type of Pair, but got element type Tuple{Int64,Int64}.... If I would have read "requires Pair, but got Tuple{Int,Int}", I think I would have been able to fix the error immediately after finding out about the difference between |
Printing the element type is definitely a good idea everywhere it doesn't match expectations. Printing function names differently from standard text would also be nice, but it requires a more general strategy to fix it everywhere. |
-> Später als Typ machen? Dazu dann DBMParam -> DBM. + Fehler gefixt, der mit Julia 0.5 auftrat (siehe JuliaLang/julia#18713)
Error messager is easier now:
|
I have the following code snippet, that works in Julia 0.4:
In Julia 0.5.0, this gives me the following error message, which I don't understand:
Why did this cease to work? How can I understand the error message?
The following works in 0.4 and 0.5 and prints two times "
Pair{Int64,Int64}
":If I can still iterate over the the dictionary and get key-value pairs, so why can't I map them?
The text was updated successfully, but these errors were encountered: