[m-users.] Using string literals as character lists in a DCG

Razetime <[email protected]>
Newsgroups gmane.comp.lang.mercury.general
Message-ID <CAMtxHUseW++0wFaO1pameDY73NRRnG=o5XVhdzVNn5YVnqEd9g@mail.gmail.com>
I am trying to include a string as a sequence of characters in a DCG.

This is my predicate l, which should take a string X and match the
list of characters represented by X in a DCG:

:- pred l(string::in,cl::in,cl::out) is semidet.
l(X,Y,Z):-string.to_char_list(X,X0),append(X0,Z,Y).

:- pred seq(list(T),list(T),list(T)).
:- mode seq(out,in,out) is multi.
seq([])     --> [].
seq([E|Es]) --> [E], seq(Es).

I wish to use it in a dcg like so:
thing --> l("thing").

such that the dcg matches ['t','h','i','n','g'].

My questions are:
a) Is there a flag like :- set_prolog_flag(double_quotes, chars) that
allows one to use strings easily in DCGs?
b) Otherwise, how can I frame my predicate to match a string correctly?
_______________________________________________
users mailing list
[email protected]
https://lists.mercurylang.org/listinfo/users
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.