# Deterministically parsing with library(dcg/high\_order)

**URL:** <https://swi-prolog.discourse.group/t/deterministically-parsing-with-library-dcg-high-order/5292>\
**Category:** Predicate\
**Tags:** dcg\
**Created:** [April 18, 2022, 8:51am UTC](https://swi-prolog.discourse.group/t/deterministically-parsing-with-library-dcg-high-order/5292 "2022-04-18T08:51:52Z")\
**Posts on this page:** 1\
**Showing post:** 13

<div class="post-metadata">

**Author:** ![Boris](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/boris/32/7486_2.png) [@Boris](https://swi-prolog.discourse.group/u/Boris)\
**Post date:** [April 18, 2022, 10:13am UTC](https://swi-prolog.discourse.group/t/deterministically-parsing-with-library-dcg-high-order/5292/13 "2022-04-18T10:13:03Z")

</div>

Thank you for your answer. Let me ask it differently: given that there are several predicates in dcg/basics that follow the same pattern (whites//0, digits//1 etc) is there a point in providing a meta-predicate _specifically for deterministic parsing_? And would it rather belong to dcg/basics since its motivation is

> We need a comprehensive set of generally useful DCG primitives.

In my slowly growing personal collection of “generally useful code” I have exactly det\_sequence//2,3,5 with the naive implementation I showed above. It is useful like once a high noon.

I dug it out, apparently I only have it for 2 and 3 arguments, it looks like this:

```prolog
$ cat detparse.pl
:- module(detparse, [det_sequence//2,
                     det_sequence//3]).
:- meta_predicate det_sequence(3, -, ?, ?).
:- meta_predicate det_sequence(3, //, -, ?, ?).

det_sequence(Goal, [X|Xs]) -->
    call(Goal, X),
    !,
    det_sequence(Goal, Xs).
det_sequence(_, []) --> [].

det_sequence(Goal, Sep, [X|Xs]) -->
    call(Goal, X),
    det_sequence_1(Goal, Sep, Xs).

det_sequence_1(Goal, Sep, [X|Xs]) -->
    Sep,
    call(Goal, X),
    !,
    det_sequence_1(Goal, Sep, Xs).
det_sequence_1(_, _, []) --> [].

```

I am not sure about the names nor about the implementation.

---

_[View the full topic](https://swi-prolog.discourse.group/t/deterministically-parsing-with-library-dcg-high-order/5292)._
