  if f=='sort_by':
   need(isinstance(x,list) and isinstance(v[1],N))
   if not x:return []
   ks=[ev(v[1],z) for z in x];need(all(typ(z) in ('number','string') and typ(z)==typ(ks[0]) for z in ks));return [z for _,z in sorted(zip(ks,x),key=lambda t:t[0])]
  if f in ('sum','avg','max','min','sort'):
   need(isinstance(x,list))
   if f in ('sum','avg'):need(all(typ(z)=='number' for z in x))
   elif x:need(typ(x[0]) in ('number','string') and all(typ(z)==typ(x[0]) for z in x))
   if f=='sum':return sum(x)
   if f=='avg':return sum(x)/len(x) if x else None
   if f=='sort':return sorted(x) if x else []
   return (max(x) if f=='max' else min(x)) if x else None