Is there a way to modify the parser, or define options, to align the indentation of a sequence of Queries on a Dataset?
Given:
ds = <|"a" -> 1, "b" -> <|"c" -> 2|>, "d" -> <|"e" -> 3, "f" -> <|"g" -> 4|>|>|> // Dataset;
A sequence of queries is indented like this:
ds[
{"b" -> {"c" -> foo}}][
{"d" -> {"e" -> bar}}][
{"d" -> {"f" -> {"g" -> baz}}}][
{"d" -> {{"f" -> quz}}}]
There are 2 problems with this format in practice with realistic workflows where queries are often lengthy and need to be modified repeatedly:
The lines are staggered - it would be desirable to have them left-aligned, as applications with many lines continues to accumulate that slope, making spot-checking of depth more difficult than it should be.
The open bracket "[" of each query appears on the line above it, making it more difficult than necessary to highlight a query (eg, to delete it). It would be more modular to confine each on its own line, but doing so results in a syntax error:
Syntax::sntxb: Expression cannot begin with "[{d->{e->bar}}][{d->{f->{g->baz}}}]".
Interestingly, writing out Query solves the 2nd problem but not the first:
ds //
Query[{"b" -> {"c" -> foo}}] /*
Query[ {"d" -> {"e" -> bar}}] /*
Query[ {"d" -> {"f" -> {"g" -> baz}}}] /*
Query[ {"d" -> {{"f" -> quz}}}]
Note, chaining queries using RightComposition reverses the indentation compared to \, which also works.
Codecell style. – Kuba Nov 23 '16 at 18:49InitializationCell->Trueoption but this can be switched on notebook or stylesheet level if you need it. As to examples, select bracket and Alt+8 – Kuba Nov 23 '16 at 18:53/., don't have a quick solution for you, sorry. – Kuba Nov 23 '16 at 19:18