Who knows maybe one day I get that too. Now I am starting to actually understand templates and how to use them. Once you get the "grammar" all you need is to find the function which does what you want.
My previous result was messy so I edited it:
Code:
{:'list_sort(list_difference(list_union(field('#shelf'), field('tags'), ','), list_union(list_union(field('#genre'), field('#length'), ','), field('#character'), ','),','),0,',')'}
Returns me a nice alphabetical list of all tags, shelves which aren't categorized into separate lists. And I can easily edit it for new categories etc.