Help with a 'siblings' query

I’m trying to find lessons in my schema which belong to the same series and which are of higher rank than the given lesson. But the below query is returning all lessons of higher rank, regardless of which series they belong to. I’m somewhat lost as to why this is the case.

Below, :lesson/series is a ref & :lesson/rank is an integer.

(defn higher-siblings [l-idf]
  "Return id and rank of higher siblings."
  (d/q '[:find ?sibling ?rank
         :in $ l
         :where
         [?l :lesson/rank ?r]
         [?l :lesson/series ?s]
         [?sibling :lesson/series ?s]
         [?sibling :lesson/rank ?rank]
         [(> ?rank ?r)]]
    (d/db conn) l-idf))

My problem: the query seems to be binding ?sibling regardless of the ?s of ?l.

Intuitively that suggests an ‘and’ is missing, but can’t quite reconcile that with the fact that since these are logic variables, I thought ‘and’ should be implied in some sense.

Is this anything to do with the fact that I have multiple where clauses referencing the same ‘a’ value?

Just for interest, I also have a composite tuple to make rank+series unique, so another form, which gives the same result, is:

      '[:find ?sibling ?rank
        :in $ l
        :where
        [?l :lesson/rank+series ?tup]
        [(untuple ?tup) [?r ?s]]
        [?sibling :lesson/series ?s]
        [?sibling :lesson/rank ?rank]
        [(> ?rank ?r)]]

Solved: By incrementally breaking down the query into smaller and smaller pieces and testing it each time, until the error simply stared me in the face, I discovered there’s a missing ? on the variable in the :in clause in the listing above. I was using the variable name l in surrounding code, where it’s not a logic variable, from where the typo must have slipped in.

As such, the input variable was not being bound to anything, and the query was returning a superset of the results I thought I was querying for.

(Side note: could an unbound :in variable not throw a warning maybe? Note I’m currently still on client-pro 0.9.41, in case that’s been added since.)