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

Volker Wysk <[email protected]>
Newsgroups gmane.comp.lang.mercury.general
Message-ID <[email protected]>
Am Montag, dem 17.10.2022 um 21:56 +0530 schrieb Razetime:
> 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?

No.

> b) Otherwise, how can I frame my predicate to match a string correctly?

You already have it in your question. That predicate l will work, the way it
is.

Cheers, Volker

_______________________________________________
users mailing list
[email protected]
https://lists.mercurylang.org/listinfo/users
signature.asc (application/pgp-signature, 833 B)
-----BEGIN PGP SIGNATURE-----

iQIzBAABCgAdFiEE6QXGh82Ov3+2nrxp+K4ydFOsHoUFAmNNhNIACgkQ+K4ydFOs
HoWGjRAAhHQ9qSyHoDdHb5M9fa1TnxooKGIcQIyqAc/tckP8xXUp1qSy+iC+iasf
qrtdEs1euIj//89GUltOXY/+acssgw5xxFWoLUwTzn3pZgmEuEHda87WUkMJlXjR
zUSmLJrP3RFEJ63uTqb3FM/p9uRAKSlekA5e+maRUTj2AjIJOkYEFKPpb5YBR52q
5h9ifHf1LLmZEty04imy8iEiz5Aq4F+mlkMOKCpo833BGStdmTURFFfu5OIzymq8
0bfoyOT/0+LJLefSgwNLpfowD/Y1WxoAJ7r22BTA5I8dQtWCaHSgHgIErS0rjWwY
Fabv9nVjSlA1OfWdlkRfMOppZKXznG2jmN5A9qn5YoCjFORaLHmObi+dCWrGD4UC
v85eKePDsjf9NqJHfBPVA0gP/mR0SGFO3AtI08dCdbCOaIYVtb6dZKRpcdCTtwjp
1oiTKQOv7Cmxkgg52DMGyxYQuxPRyf/bicNvfb/xn+lIvj+of/ZjQ79pB/9pAMtx
gTdKGWcMDcMCfQwZZXjA96VWFWw++yD62XhjEpeaVSUZzc1Wm/It7UOvStZ3s79i
iEnTLQjQ6Gmf1D68a1Fbe/Y0PjODGEUC6BbicO2TGH3p+S1QhhWJ4prSG0whW0ru
xxYA1Q8TRyjyWlhOBwFKI9V64qJBFonQrKq+GopBo4qiGEQ/Zwc=
=datg
-----END PGP SIGNATURE-----
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.