The Standard Rules supports
To remove (existing entry - K) from (L - list of values of kind K), if present
and
To remove (N - list of Ks) from (L - list of values of kind K), if present
but today I needed something else so I made a little utility phrase for
To remove (D - description of values of kind K) from (L - list of K), if present:
tested only with 6M62
Include (-
! based on 6M62 LIST_OF_TY_RemoveValue
[ LIST_OF_TY_RemoveValuesByDesc list desc forgive i j no_items odsize f delendum mf ;
if ((list==0) || (BlkValueWeakKind(list) ~= LIST_OF_TY)) rfalse;
if ((desc==0) || (~~desc ofclass Routine)) rfalse;
no_items = BlkValueRead(list, LIST_LENGTH_F); odsize = no_items; mf = false;
BlkValueWrite(list, LIST_LENGTH_F, no_items); ! Forces the list to be mutable
for (i=0: i<no_items: i++) {
delendum = BlkValueRead(list, i+LIST_ITEM_BASE);
f = desc(delendum);
if (f) {
mf = true;
if (KOVIsBlockValue(BlkValueRead(list, LIST_ITEM_KOV_F)))
BlkValueFree(delendum);
for (j=i+1: j<no_items: j++)
BlkValueWrite(list, j-1+LIST_ITEM_BASE,
BlkValueRead(list, j+LIST_ITEM_BASE));
no_items--; i--;
BlkValueWrite(list, LIST_LENGTH_F, no_items);
}
}
if (odsize ~= no_items) rfalse;
if (forgive) rfalse;
if (~~mf) {
print "*** Couldn't remove values because none matching description were present in the list ";
LIST_OF_TY_Say(list, true);
print " ***^";
RunTimeProblem(RTP_LISTRANGEERROR);
}
];
-).
To remove (D - description of values of kind K) from (L - list of K), if present:
(- LIST_OF_TY_RemoveValuesByDesc({-lvalue-by-reference:L}, {D}, {phrase options}); -).