Consider the following function for clearing a List:
func ClearList(l)
unlet a:l[:]
endfunc
let l = [1, 2, 3, 4]
call ClearList(l)
echo "List = ->" .. string(l) .. "<-"
After calling the ClearList() function, all the elements in the List
are cleared.
A similar function for clearing a Dict:
func ClearDict(d)
for k in keys(a:d)
unlet a:d[k]
endfor
endfunc
let d = {'a' : 10, 'b' : 20}
call ClearDict(d)
echo "Dict = ->" .. string(d) .. "<-"
In this function, we have to iterate through all the keys and unlet each
item. The Dict cannot be cleared by simply using unlet or by assigning
the argument to an empty dictionary.
Regards,
Yegappan