O shell está interpretando $? como o status de saída do comando anterior.
Para evitar a interpretação da shell:
Use aspas em torno de $? :
(Head-Level-Mother-Daughters ?h1 ?l1 ?m1 "$?" ?m "$?")
Ou
(Head-Level-Mother-Daughters ?h1 ?l1 ?m1 '$?' ?m '$?')
Ou escape $ com \ :
(Head-Level-Mother-Daughters ?h1 ?l1 ?m1 $? ?m $?)