I didn't declare q to be a local variable. That can cause problems for a user; fixed code:
L(p,f, s, t) := block([b, i : 0, q],
b : solve(p,s),
b : xreduce('append, (map(lambda([s,k], makelist(s,k)), b, multiplicities))),
f : f / coeff(ratexpand(p), s, length(b)),
for bk in b do (
q : exp(rhs(bk) * t),
f : q * (integrate(f / q, t) + concat('c, i : i + 1))),
f)$
--Barton