Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Confusing step in DCG left-recursion solution #9

Open
jeremy-w opened this issue Sep 29, 2018 · 4 comments
Open

Confusing step in DCG left-recursion solution #9

jeremy-w opened this issue Sep 29, 2018 · 4 comments

Comments

@jeremy-w
Copy link

We can do this by introducing two additional arguments that let us limit the number of rule applications to the given list's length: (https://www.metalevel.at/prolog/dcg)

As a reader, it’s not clear to me why there are two arguments, or what’s up with the sharing between LS1 in the left/right descents.

I suspect there is one or two intermediate steps to arrive at that solution, that you are able to leap straight past thanks to running across the problem many times before. For a newcomer, though, it leaves a mystery.

If you could elaborate on how this works within the chapter, that would be very helpful!

@triska
Copy link
Owner

triska commented Sep 29, 2018

Thank you for this highly appropriate suggestion! The basis for this step is found in the important concept of list differences.

This was so far only briefly mentioned, and I have now added several new paragraphs about it, please have a look:

https://www.metalevel.at/prolog/dcg#leftrecursion

What do you think, does it help?

@jeremy-w
Copy link
Author

Yes, it does. I had to read and think on it a bit, but I could follow along. I think this specific example was especially helpful:

We can interpret the difference of these lists as describing the list of elements that are consumed by the first recursive invocation of tree_nodes//3 in this example.

Explaining it to myself, I see the two args as, arg 1 “you have this much list to work with”, arg 2 “and you left this much unused”. Then the flow from the first recursive call to the second makes sense as parceling out the overall list.

I appreciated the further words on list differences vs difference lists. The clarifications throughout the book on what constitutes modern Prolog vs legacy Prolog have been a big help in understanding what Prolog can do today.

@triska
Copy link
Owner

triska commented Oct 1, 2018

Explaining it to myself, I see the two args as, arg 1 “you have this much list to work with”, arg 2 “and you left this much unused”

Yes, this is applicable in this case, since it assumes the list is given when the rule is invoked and this is indeed the main point of the example. However, this wording would not completely do justice to the versatility of the actual relation, which also works if the list is not specified in any way. In that case, it yields the number of tokens that are needed for this rule to apply. I am always striving for formulations that encompass all possible usage modes, and so I have worded this in such a way that both cases are subsumed, even though one direction is emphasized much more strongly.

Thank you very much for your kind feedback and for this suggestion!

triska added a commit that referenced this issue Oct 7, 2018
This addresses #9, raised by Jeremy W. Sherman (@jeremy-w). Many thanks!
@triska
Copy link
Owner

triska commented May 13, 2019

I have created a small video to explain list differences in more detail, please have a look:

https://www.metalevel.at/prolog/videos/list_differences

It's work in progress... however, I hope you find it useful!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants