Re: term_expansion/2 with DCG clauses
Paulo Moura <[email protected]>
| Newsgroups | gmane.comp.ai.prolog.swi |
|---|---|
| Message-ID | <[email protected]> |
On 14/08/2013, at 10:24, Jan Wielemaker <[email protected]> wrote: > On 08/14/2013 04:28 AM, Richard A. O'Keefe wrote: >> >> On 14/08/2013, at 3:44 AM, Jan Wielemaker wrote: >>> This seems a logical way to access DCG expansion. The only price is that >>> you cannot created rules for -->/2 (nor for []/0 and ./2). Do these >>> systems have an agreed way to creates DCGs from expansion rules? I guess >>> Richard will know the rationale for not doing DCG after user expansion. >> >> If I recall correctly, DCG expansion was done *before* user expansion. >> With there being no goal_expansion in those days, this was important if >> you wanted users to be able to plug their own goal_expansion code in and >> have it apply to the result of DCG expansion. >> Further, DCG expansion was available as library code, so if you wanted it, >> you could very easily call it yourself. > > So not doing DCG expansion if user expansion is involved seems out of > date. I think the interesting question here is where and how the user can intervene if a call to term_expansion/2 produces a grammar rule (or a list of grammar rules). > The idea to chain `translation packages' is also implemented in > Ciao and ECLiPSe (and Logtalk?), although the way the packages are > specified there is much more fine-grained. In the case of Logtalk, the user can define his/her own chaining. The fundamental difference is that the user explicitly states (using a directive in a source file or a compiler option in the predicate that compiles and loads a source file) which object contains the expansion rules to be used. In this object the user can define if and how the chaining works. > If you want DCG translation and do further term expansion on the result, > you can call dcg_translate_rule/2. Would be nice if this had the same > name in all systems supporting DCGs ... That was one of my goals when I served as the editor of the ISO WG17 DCGs standardization proposal, backed by a reference implementation (and a set of unit tests). You know what happened. > As I understand it, some people > assume you can call expand_term/2 to achieve DCG translation. There are > two issues with that: it might do a lot more and it is probably a bad > idea to call expand_term/2 from term_expansion/2. It surely easily gets > you into a loop. > > I see no reason to change anything right now. I agree. It will be a long time until any sort of de facto standard expansion mechanisms emerges. Cheers, Paulo ----------------------------------------------------------------- Paulo Moura Logtalk developer Email: <mailto:[email protected]> Web: <http://logtalk.org/> -----------------------------------------------------------------