Janus not recognizing object as Deque

This is the python file helper.py:

from collections import deque

#------DEQUE STUFF------
def create_empty():
    return deque()

def append_left(deq, a):
    deq = deque(deq)
    return deq

and here is the prolog file:

:- module(deque, [

:- use_module(library(janus)).

:- table create_empty/1,  append_left/3.

lib :- py_add_lib_dir("C:/Users/vatis/OneDrive/Documents/Noise/backend").

create_empty(D) :-
    py_call(helper:create_empty(), D).

append_left(D, A, ND) :-
    py_call(helper:append_left(D, A), ND).

So I tried running append_left, but I get this error:

?- create_empty(D), append_left(D, 1, D1).
ERROR: Python 'AttributeError':
ERROR:   'list' object has no attribute 'appendLeft'
ERROR: Python stack:
ERROR:   File "c:\users\vatis\onedrive\documents\noise\backend\helper.py", line 15, in append_left
ERROR:     def append_left(deq, a):
ERROR:         ^^^^^^^^^^^^^^
ERROR:   [14] janus:py_call(helper:append_left([],1),_1770)
ERROR:   [11] toplevel_call(user:user: ...) at c:/program files/swipl/boot/toplevel.pl:1317
ERROR: Note: some frames are missing due to last-call optimization.
ERROR: Re-run your program in debug mode (:- debug.) to get more detail.

Python thinks the object is a list, but in the second line of the function I have deq = deque(deq) which should turn the list into a python deque.

It might be possible that Janus did not refresh or something because the previous version of the file did not have that line. I do not know how to refresh Janus to update if there is a way though.

Any ideas? Thanks in advance.

Janus converts Python objects that seem to have a reasonable representation in Prolog to a Prolog data structure. A deque is probably defined as a iterable object and (thus) converted into a list. If you want to have the Python object, use py_call/3 with the option py_object(true). I also doubt you want the :- table directive. This is meaningful when your Prolog code deals with some global Python object. You can either create the object and assertz/1 the reference or you table the predicate that creates it and Prolog ensure the object is created only once lazily.

Overall, the general idea is to define Python functions that are capable of consuming terms created by Prolog and produce a Python result that can be consumed immediately by Prolog. Wrapping a Python deque as a Prolog library seems far too low level. Of course, it depends on the overall goal you have. What are you trying to write? Why do you want both Prolog and Python and what role should each of these play in the application?

The core idea of Janus was to bring Python’s vast collection of interfaces to just about anything to Prolog. Thus, “I want to program in Prolog, but I need to talk to e.g., midi and Prolog has no library for midi”. So, we define what we need from midi, take a Python midi library, write some Python code around it to make it a bit more Prolog friendly and finally wrap that in some Prolog predicates.

My idea here is that the functions will return lists. That is what I want. But, I am using python to allow me to append an item to the left of the list, and so on. Problem is, those functions are only reserved for the deque type. So in the append_left function in python, I take the inputted list from python, turn it into a deque so I can apply the function that I want (like appending an element to the left end), and return the deq which will get converted back into a list in prolog. Unfortunately, it seems like the deq = deque(deq) has no meaning?

Ah I fixed the error. Turned out I had a typo in the function name.