[m-users.] Using string literals as character lists in a DCG
Razetime
rraghu.11502 at gmail.com
Tue Oct 18 03:26:20 AEDT 2022
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?
More information about the users
mailing list