Replies: 10 comments 8 replies
-
Thank you for starting this discussion! Scryer Prolog is an ideal system for working with DCGs, and I agree that having a few often needed non-terminals seems very useful! One general question I have, if we consider for example ?- phrase(integer(I), Cs). Is this simply an instantiation error? I suppose so. And what about: ?- phrase(integer(12), Cs). Should this yield |
Beta Was this translation helpful? Give feedback.
-
What does generous mean in the context? I never heard it before. And what would be the opposite? |
Beta Was this translation helpful? Give feedback.
-
This describes a sequence. Not whatever. And note the space. Whatever is |
Beta Was this translation helpful? Give feedback.
-
Match? A match is when a (repeat: a, that is any) substitution θ results in something identical. We have never such matches in the presence of general variables, we have only substitutions that are most general unifiers. As long as one side is variable free, there is no difference and it makes sense to talk about matching, but in the general case as here, it is not. If we would only talk about a given list of chars, matching is OK. But not if that list contains variables as well. |
Beta Was this translation helpful? Give feedback.
-
In regular expressions lingo, "non-greedy" is sometimes referred to as "lazy". |
Beta Was this translation helpful? Give feedback.
-
|
Beta Was this translation helpful? Give feedback.
-
In what sense is this generous? It is not even fair. |
Beta Was this translation helpful? Give feedback.
-
Instead of |
Beta Was this translation helpful? Give feedback.
-
Or with better typed variables:
|
Beta Was this translation helpful? Give feedback.
-
Regarding For the other nonterminals, we would also benefit from more usage experience and a careful consideration of conventions. For example,
It would maybe be helpful to consider a more concrete proposal for the actual implementations, and also a careful description of what the arguments are. For example, a recent DCG draft uses grammar-rule-body for what in the current description is referred to as a "DCG". I think at the moment, a good conservative addition to |
Beta Was this translation helpful? Give feedback.
-
Right now we have DCGs, which are very useful for lots of applications. However, I end up repeating some basic nonterminals quite often through different projects. Maybe it is time to build a DCGs Util library with some common nonterminals. The question is: what nonterminals should be in that library? I will propose some nonterminals, but feel free to discuss more (or less) nonterminals.
library(dcgs)
provides:seq//1
- Describes a sequence. It is generous (meaning that shorter matches have higher priority)seqq//1
- Describes a sequence of sequences. Also generous.... //0
- Describes a sequence but discards the unificationSome additions I propose:
generous//2
- Takes a DCG and tries to apply it generously. The shorter matches have higher priority.greedy//2
- Takes a DCG and tries to apply it greedily. The longer matches have higher priority.exactly//3
- Takes a DCG and tries to apply it exactly N times.at_least//3
- Takes a DCG and tries to apply it at least N times.blanks//0
- Describes whitespaces and tabs, zero or moredigit//1
- Describes a digitinteger//1
- Decribes an integer numberfloat//1
- Describes a float numbernumber//1
- Describes a number (integer and floats)string//1
- Describes a string. The difference between string and seq is that string checks explicitly that the members of the list are char atoms.string_without//2
- Describes a string without some specific charseol//0
- Describes the end of a lineWhat more nonterminals should be present? Some nonterminal in the list is not right?
Beta Was this translation helpful? Give feedback.
All reactions