(bind-func dict_update:[!v,List{Pair{String*,!v}*}*,String*,[!v,!v]*]*
"set (or update) value for key in dict according to update_fn (returns the old value)"
(lambda (dict key update_fn)
(if (null? dict)
(convert null)
(if (equal (first (car dict)) key)
(let ((oldval (second (car dict)))
(newval (update_fn oldval)))
;; if update_fn returns null, do nothing. otherwise
;; update the value for key
(tset! (car dict) 1 newval)
oldval)
(if (null? (cdr dict))
(begin (append_destructive dict (list (Pair key (update_fn (convert null)))))
(convert null))
(dict_update (cdr dict) key update_fn))))))