Skip to content
Discussion options

You must be logged in to vote

Frequent use of append/3 in the same program or predicate may indicate that a portion of the code could benefit from DCGs.

For example, consider the task: "Does the list "hello there" contain the subsequence "eee"? Easy to express with DCGs:

?- phrase((...,"e",...,"e",...,"e",...), "hello there").
   true
;  false.

With append/3, it is also possible, though significantly more tedious and prone to errors. (Try it!)

Multiple uses of append/3 in a row can also lead to significantly increased asymptotic complexity compared to using DCGs. As an example, consider describing a longer text as a list of characters or tokens from multiple parts with DCGs, and contrast it to various different ways …

Replies: 3 comments 12 replies

Comment options

You must be logged in to vote
1 reply
@jjtolton
Comment options

Answer selected by jjtolton
Comment options

You must be logged in to vote
3 replies
@jjtolton
Comment options

@jjtolton
Comment options

@jjtolton
Comment options

Comment options

You must be logged in to vote
8 replies
@haijinSk
Comment options

@haijinSk
Comment options

@jjtolton
Comment options

@UWN
Comment options

@haijinSk
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
4 participants