-
Notifications
You must be signed in to change notification settings - Fork 126
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
Add predicates for using library(debug) with DCGs #1128
base: master
Are you sure you want to change the base?
Conversation
I couldn't find any way to make natural(A,N) --> digit(D), ${A1 is A * 10 + D}, natural(A1,N). I think it's excluded by the grammar? |
It is definitely a good idea to extend these constructs to grammars, thank you a lot for working on this! One thing I noticed: With the current definition, the nonterminal *(_) --> ... . Please consider using One small detail: Please consider using brackets for the |
Use in stead of Also note that
|
This definition only makes sense in the absence of semicontext. |
I've removed Should I report I've used Is there any way to define a |
I see that SWI's |
I may have misunderstood
are you saying that some other DCG compiler may interpret I was specifically wondering whether it's okay for me to use a lambda there, or if I should define a predicate like |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please note that \ renames variables. So what is the purpose of it in this context?
I need to get $-G_2 --> call(\Xs0^Xs^
catch(phrase(G_2, Xs0, Xs), Ex, (
portray_clause(exception:Ex:G_2=(Xs0, Xs)), throw(Ex)
))). without a lambda: $-G_2 --> call(catch_exception_body(G_2)).
% can't think of a better name for this:
catch_exception_body(G_2, Xs0, Xs) :-
catch(phrase(G_2, Xs0, Xs), Ex, (
portray_clause(exception:Ex:G_2=(Xs0, Xs)), throw(Ex)
)). Is there some other trick to getting those variables? Or are you suggesting that |
You are renaming the variables in
Either declare However, there is a further problem here. DCGs and regular predicates share the same name space. So whenever we add a new non-terminal
Note that this code does not repeat anything unnecessarily. There is just one place that is responsible for printing. So for debugging DCGs the best is to use another operator, say |
Users would choose between
(In the expansion that is equivalent to
|
2a7a1b7
to
bb624cc
Compare
cf96173
to
bb420e9
Compare
a769b09
to
0666b56
Compare
If someone will find this ticket and is interested in tracing DCGs, I usually just add |
Enables easy tracing of DCGs: