View Single Post
Old 03-12-2023, 07:44 AM   #527
chaley
Grand Sorcerer
chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.
 
Posts: 12,495
Karma: 8065348
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
Quote:
Originally Posted by ownedbycats View Post
I managed to figure this, perhaps a bit clumsily -- also changed some of the reference names to be a bit clearer

Code:
program:
...
	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.
FWIW: this is a simplified version of what you wrote:
Code:
program:
...
	if !new_colls then 
		existing_colls = $#kobocoll;
		new_colls = $#booktype
	else
		existing_colls = list_difference($#kobocoll, $#booktype, ',')
	fi;
	merged_colls = list_union(new_colls, existing_colls, ',');
chaley is offline   Reply With Quote