Newsgroups: comp.lang.prolog
Path: cantaloupe.srv.cs.cmu.edu!rochester!cornellcs!travelers.mail.cornell.edu!news.kei.com!news.mathworks.com!tank.news.pipex.net!pipex!newsfeed.internetmci.com!news.sprintlink.net!nwnews.wa.com!nwfocus.wa.com!mdisea!mothost!schbbs!NewsWatcher!user
From: anewman@epidigm.geg.mot.com (M. Alan Newman)
Subject: DCG's (was: Can you do this?)
Organization: Motorola
Date: Fri, 20 Oct 1995 06:48:45 -0700
Message-ID: <anewman-2010950649240001@137.124.91.130>
References: <1995Oct17.191133.1@vax.sbu.ac.uk> <30864FF8.1A90@vms.uci.kun.nl> <LUDEMANN.95Oct19121524@expernet5.expernet.com>
Sender: news@schbbs.mot.com (SCHBBS News Account)
Nntp-Posting-Host: 137.124.91.130
Lines: 29

In article <LUDEMANN.95Oct19121524@expernet5.expernet.com>,
ludemann@expernet.com wrote:

 [...]
> Incidentally, something similar will flatten a list:
> 
> flatten([]) --> [].
> flatten([X|Y]) --> flatten(X), flatten(Y).
> flatten(X) --> {atomic(X), X \== []}, [X].
> 
> flatten(List, Flattened) :- phrase(flatten(List), Flattened).

What are the reasons for/against using phrase/2 as above (assuming
standard token list expansion), instead of:

flatten(List, Flattened) :- flatten(List, Flattened, []).

In particular, are there any problems intermixing DCG and non-DCG clauses?
For example, having a predicate whose three clause (heads) are:

foo(A, B) :- ...
foo --> ...
foo(A, B) :- ...

and, similarly, invoking this predicate by either goal:
  foo(A, B)   or    phrase(foo, A, B)
-- 
M. Alan Newman (anewman@epidigm.geg.mot.com)  Speaking for myself.
Motorola, GSTG, Diversified Technology Division
