Note - do ensure to read the linked articles in this reply as they hold much of the fine detail of the answers you seek.
Quote:^if(\$$1)^$1= {^value(\$$1)^},
^endIf^
Using do() or ^do()^call, the first parameter given is the name of the
macro. The second and subsequent parameters form the
first and subsequent data inputs passed the specified macro.
Within the macro, the inputs are referred to as $1, $@, etc. Wherever a $N is inserted the literal value of the input (i.e. the do() input value), thus above the
$1 is inserting an attribute name passed to the macro. But, we need the overall result to be an attribute
reference (i.e. a $-prefixed name). In a macro a $ already has a special meaning, so to insert an actual dollar-sign character we 'escape' it with a back-slash (the
red code above). So is input one is "SomeName" the macro code
\$$1 returns the string "$SomeName". White space matters in this context; if the macro code were
\$ $1 the string returned becomes "$ SomeName" - which isn't, of course, a valid attribute reference!
Quote:$MyExportSet=$KeyAttributes.replace("citeinessay|citetype|nickname","");
$KeyAttributes is a Set. We are using the
Set.replace() to create set that excludes the 3 attribute names before passing the result to $MyExportSet. The replace string is a
regular expression - description of the fine workings of these is a subject on its own; if you're new to regex, I'd read up the general subject via Google.
We need $MyExportSet as if we try to do the next step by nesting code (inserting the right side of the above where $MyExportSet is in the code below) it doesn't work. There are limits to how deeply TB will drill down into code in terms of evaluating things. There's no hard as fast limit - before you ask, you just need to experiment. Plus, when designing this sort of code, it's useful to have interim attribute values so you can check the result of each step is what you assumed it to be.
Quote:$MyExportString=eval($MyExportSet.format('','eval(do("export-list","','"))+','')
);
This is a hack to get around the fact that action and export code lack a loop function, e.g. for(x, x < y; x=x+1) sort of thing. We need to turn every item in $MyExportSet into a discrete string. OK,
Set.format(), in its 4-argument syntax, lets us supply list-prefix/item-prefix/item-suffix/list-suffix for each item in the set. In fact, we only need list prefix/suffix but there's another road-block that I address with a macro. Each Set item's output needs to use the current list item value
more than once. So, in the format() code's argument #2 and #3 we wrap the item name in an eval(do()) call, split between [2] and [3] like so: [eval(do(] and [))]. For Set item "SomeAttribute" we pass in
eval(do("export-list","SomeName"))+…representing
#2[Set item value]#3, and receiving back:
eval(^if($SomeName)^SomeName= {^value($SomeName)^},
^endIf^)+Great, we've now tricked format() into inserting each set item value not once, but
three times, into the per-item output.
The outer wrapper takes the string+string+string+ output from format() and turns it into a single string.
Footnote. Why use ^code^ in the macro and not action code and evaluate before export. Well, it seems that's pushing eval() and macros further than they're currently (v5.9.3) designed to go - ergo the outstanding problem with TB no letting me get line returns where I want them in $ExportString. AS you may guess I explored a lot of blind alleys in getting to the above code (as the edges of action code aren't documented - aTbRef is effectively what we know, or believe, is true).
Sorry for the long post. This stuff isn't simple (in execution) so please don't shoot the messenger if it's hard to follow! As said previously, try breaking the task into steps and check at each one that progress thus far is what you expect.