Re: "maplist" for DCG?
Paulo Moura <[email protected]>
| Newsgroups | gmane.comp.ai.prolog.swi |
|---|---|
| Message-ID | <[email protected]> |
Hi Edison, Logtalk provides a meta_non_terminal/1 directive that is handy for these cases: On 23/11/2013, at 16:36, Edison Mera <[email protected]> wrote: > Once ago I have a similar need, and implemented a set of maplist_dcg//N > predicates in one of my libraries, basically is the code Richard wrote for > mapnt, but using the call/(N+1) predicates: > > :- module(maplist_dcg, [maplist_dcg/4, > maplist_dcg/5, > maplist_dcg/6, > maplist_dcg/7, > maplist_dcg/8, > maplist_dcg/9]). I'm under the impression that SWI-Prolog also supports the notation: :- module(maplist_dcg, [ maplist_dcg//2, maplist_dcg//3, ... ]). > :- meta_predicate maplist_dcg(3, ?, ?, ?). :- meta_non_terminal(maplist_dcg(1, ?)). > maplist_dcg(Goal, List) --> > maplist_dcg_(List, Goal). > > :- meta_predicate maplist_dcg_(?, 3, ?, ?). :- meta_non_terminal(maplist_dcg_(?, 1)). > maplist_dcg_([], _) --> []. > maplist_dcg_([E|T], Goal) --> > call(Goal, E), > maplist_dcg_(T, Goal). > > :- meta_predicate maplist_dcg(4, ?, ?, ?, ?). ... The directive is easy to implement and, in the same way as NonTerminal//Arity, it allows to abstract the implicit arguments. Cheers, Paulo ----------------------------------------------------------------- Paulo Moura Logtalk developer Email: <mailto:[email protected]> Web: <http://logtalk.org/> -----------------------------------------------------------------