The advent of code challenge also has more complicated sequences to be read from a text file. I was curious if it was possible to read it directly into well structured nested arrays. Ideally, I would have liked Julia to figure out Union{Vector{Int},Int} from @lmiq automatically, such that it would work for any complicated structure like bellow (full input here):
[[[[[4,3],4],4],[7,[[8,4],9]]],[1,1]]
I omitted to mention that I read the file like this:
d = open("18.txt") do f readlines(f) end
d = eval.(Meta.parse.(d))
I am not sure this is a relevant question, because these adventofcode challenges can be a bit far from real use cases anyways and also because this challenge can also be solved by reading the structures as strings and count brackets, as opposed to running eval.
It doesn’t really matter much since as soon as you have to represent everything as pointers to boxed objects, you’re already hosed in performance anyway. What the problem with the arrays being Any typed?
Wouldn’t union splitting help with subsequent code while indexing into the array, if the type is known to be a small Union instead of Any? Or is that not a factor?
Sadly you will find that when you try to solve the rest of the problem, compile time will absolutely explode due to all the type specializations you run into. The @nospecialize macro might help but I wasn’t able to get reasonable performance with this approach before I changed track.