Very basic dcg prolog syntax

后端 未结 2 1319
广开言路
广开言路 2021-01-19 11:21

I am trying to understand prolog and definite clause grammar but I am having a very hard time understanding both of them.

I am really trying to understand how to use

2条回答
  •  清歌不尽
    2021-01-19 12:14

    it's not easy to translate do/4 to DCG in meaningful way. I've removed arguments that 'copy' the hidden arguments of the DCG.

    do(Sum) -->
        [1],  %check if H is 1
        {  % braces allow 'normal' Prolog code (but we have no access to 'hidden' arguments)
        Additional is H+5,
        Sum is Additional+Additional
        }.
    

    edit sorry I forgot H in Additional is H+5,, should read Additional is 1+5,...

提交回复
热议问题