I managed to figure this, perhaps a bit clumsily -- also changed some of the reference names to be a bit clearer
Code:
program:
genre = $#subjects;
new_colls = strcat(
## if $$#purchasecost == '0.00' then 'Freebies,' fi,
if 'Omnibus' in $#admintags then 'Omnibuses,' fi,
if 'overdrive' in approximate_formats() && !$purchasesource then 'Loans,' fi,
if $#booktype=='Fanfiction' then list_re($tags, ',', '^Fanfiction.(.*)$', 'Fanfiction: \1,') fi,
if 'public domain' inlist $#admintags then 'Public Domain,' fi,
if '^Cozy Mystery$' inlist genre then 'Cozy Mysteries,' fi,
if '^Horses$' inlist genre then 'Horses,' fi,
if 'Folktales & Mythology' inlist genre then 'Folktales & Mythology,' fi,
if '^Science Fiction$' inlist genre then 'Science Fiction,' fi,
if '^(Fantasy|Paranormal)$' inlist genre then 'Fantasy & Paranormal,' fi,
);
if new_colls == '' then existing_colls = $#kobocoll fi;
if new_colls then existing_colls = list_difference($#kobocoll, $#booktype, ',') fi;
if new_colls == '' then new_colls = strcat($#booktype, ',') fi;
merged_colls = list_union(new_colls, existing_colls, ',');
explanation:
new_colls generates a set of new collections with the strcat
existing_colls is taken from the existing #kobocoll value. If new_colls exists, it removes booktype from the list
If new_colls doesn't exist, it sets it to #booktype
merged_colls combines new_colls and existing_colls.