Try to using core.logic to solve this problem:  https://www.v2ex.com/t/128273