Thanks for the feedback.
For parsing with DCGs when done correctly they are blindingly fast.
Getting back to my view that Prolog is used to create models of problems and then the problem is applied to the model instead of trying to solve the problem directly with Prolog, difference list when thought of as doing pointer manipulation are extremely powerful but sadly it is hard to find good documentation that points this out with graphics. Writing the documentation is on my to-do list but if @dtonhofer needs more convincing I might be doing them sooner rather than latter.
Once place where I saw note of doing pointer manipulation instead of string copies to make the application faster was with NGINX server. Don’t ask for a reference as I must have read about 50 different pages in their documents over the last week and did not keep track of everything I read.
With regards to the queue that looks like code I saw in
Difference Lists by Frank Pfenning on page L11.2
queue(Is) :- q(Is, B\B).
q([enq(X)|Is], F\[X|B]) :- q(Is, F\B).
q([deq(X)|Is], [X|F]\B) :- q(Is, F\B).
q([], []\[]).
will have to check. Also it might be able to be transformed like I did in this example.