def _list_to_swipy_ref(item: List, swipy_ref, lit_var_store: Dict[Variable, int]): clist_term = swipy.swipy_new_term_ref() swipy.swipy_put_nil(swipy_ref) args = item.get_arguments() for ind in range(len(args) - 1, -1, -1): _to_swipy_ref(args[ind], clist_term, lit_var_store) swipy.swipy_cons_list(swipy_ref, clist_term, swipy_ref)
def _pair_to_swipy_ref(item: Pair, swipy_ref, lit_var_store: Dict[Variable, int]): head = swipy.swipy_new_term_ref() tail = swipy.swipy_new_term_ref() _to_swipy_ref(item.get_left(), head, lit_var_store) _to_swipy_ref(item.get_right(), tail, lit_var_store) swipy.swipy_cons_list(swipy_ref, head, tail)
def _list_to_swipy(item: List, lit_var_store: Dict[Variable, int]): list_term = swipy.swipy_new_term_ref() if len(item.get_arguments()) == 0: # if empty list swipy.swipy_put_nil(list_term) else: # if non-empty list clist_term = swipy.swipy_new_term_ref() swipy.swipy_put_nil(list_term) args = item.get_arguments() for ind in range(len(args) - 1, -1, -1): _to_swipy_ref(args[ind], clist_term, lit_var_store) swipy.swipy_cons_list(list_term, clist_term, list_term) return list_term