Re: [m-users.] Problem with DCG producing false negative

Volker Wysk <[email protected]>
Newsgroups gmane.comp.lang.mercury.general
Message-ID <[email protected]>
Hi

I don't fully understand what you're doing here. But you should try to make
the DCG rules det or semidet. Then you can let the compiler spot your
errors, when it doesn't agree with the determinism category which you have
declared.

Hope that helps,
Volker


Am Montag, dem 17.10.2022 um 00:14 +0530 schrieb Razetime:
> I have created the following predicate tls to match lines that satisfy
> the conditions given in Advent of Code Day 7:
> https://adventofcode.com/2016/day/7 (Spoilers)
> 
> For some reason during testing ,the DCG fails when given
> L="fslvgbiibdkhchajyb[zpbhqrokrbfuqrowop]gqqzoqvfsdfcjcdurrs[xhqfcfytbbekivnvod]jxjwuxivnyhppvfhaol[evfnrmrjnnhychtpv]emiyjcjsnojxexs",
> tls(X,Y,to_char_list(L),[])
> and I am not sure why it is giving that result. What is done wrong here?
> 
> :- pred tls(list(cl)::out,list(cl)::out,cl::in,cl::out) is nondet.
> tls([X],[])        --> {alp(X)},seq(X).
> tls([X0|X],[Y0|Y]) --> {alp(X0),alp(Y0),\+abba(Y0)},
> 
> seq(X0),['['],seq(Y0),[']'],tls(X,Y),{any_true(abba,[X0|X])}.
> 
> :- pred seq(list(T),list(T),list(T)).
> :- mode seq(out,in,out) is multi.
> seq([])     --> [].
> seq([E|Es]) --> [E], seq(Es).
> 
> :- pred alp(cl::in) is semidet.
> alp(L):-all_true(is_alpha,L).
> 
> :- pred abba(cl::in) is semidet.
> abba([A,B,B,A|L]):-A\=B.
> abba([_,A,B,C|L]):-abba([A,B,C|L]).
> _______________________________________________
> users mailing list
> [email protected]
> https://lists.mercurylang.org/listinfo/users

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

iQIzBAABCgAdFiEE6QXGh82Ov3+2nrxp+K4ydFOsHoUFAmNNF7IACgkQ+K4ydFOs
HoUlfxAAqKMbiABL1JSmYu8H60eIVY+GK0itljU9rNfAB/wY5l/T0to9l7UFjA62
bWAOVr3XLbV6i/POH+4l7ithd0RdS9fSpwR9unfsy6fjNws20zaYAkABvE30pPNU
6iBJsuYaZANcLbmPb2PqAGdcffuJn8+gMh9FiTrYOhNcajV2G+hxRtHvAuWuq84H
2A35vACU74bbsGig9aiSbibPhlKpssfC0bEZ73kwcWv7Hx5TrULSoiUqRoJS9DCk
TqjTth93zCflmvjf8Dc1D9Vmd29bC6yuc0qhIDmbzmnm5rJOSsIYgTU0ExTS5Umy
SuZSfxjmDJbERthdN85wjSBqRg3i7xNEyPA3g8EFkw2oyd2mCVb/JxE+d0CHC207
DSxok4Wk+vvvAyDgwJkuWev1gJgvdg1rEhBcm/PAH+OIFMxw0q56b/gFxpK7wodV
RPOMx79XBDI7JzZ46sk801BtUTC2xPlZmEl3tXv++yrjl3TiDETXPSYPjWtXPW0U
sWwql4vST9hcuwJBvjgd99AL2mRgNN8RwxVOE2ekQCZCXz8u2TJro4Ni8tP+J5Xx
q5gAewUICdSb4QFENvDJchrCCK7uGzDziAZnkpXDtzatAPoptsBWhhXNDfhC6R6V
nbOxksxITdXpi0CL6eG6tYTdJKAqUHarQloU+E6v8ajqrGW6X7o=
=bg1D
-----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.