generalize applyToTerms and move it from Term to ArgSpec

(This fixes a bug in example/aircraft-wandering.dblog where the old
implementation of applyToTerms failed to cast a TupleSetSpec to a Term.
The model still doesn't run though -- all particles have zero weight.)