1% BEGIN LICENSE BLOCK
2% Version: CMPL 1.1
3%
4% The contents of this file are subject to the Cisco-style Mozilla Public
5% License Version 1.1 (the "License"); you may not use this file except
6% in compliance with the License.  You may obtain a copy of the License
7% at www.eclipse-clp.org/license.
8%
9% Software distributed under the License is distributed on an "AS IS"
10% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied.  See
11% the License for the specific language governing rights and limitations
12% under the License.
13%
14% The Original Code is  The ECLiPSe Constraint Logic Programming System.
15% The Initial Developer of the Original Code is  Cisco Systems, Inc.
16% Portions created by the Initial Developer are
17% Copyright (C) 1996 - 2006 Cisco Systems, Inc.  All Rights Reserved.
18%
19% Contributor(s):
20%
21% END LICENSE BLOCK
22%
23% @(#)umsmacros.tex	1.9 96/01/08
24%
25% umsmacros.tex
26%
27
28\chapter{{\eclipse} Macros}
29%HEVEA\cutdef[1]{section}
30\label{chapmacros}
31
32%----------------------------------------------------------------------
33\section{Introduction}
34%----------------------------------------------------------------------
35\index{source transformation}
36\index{macro expansion}
37{\eclipse} provides a general mechanism to perform macro expansion
38of Prolog terms.
39Macro expansion can be performed in 3 situations:
40\begin{quote}
41\begin{description}
42
43\item[read macros]\index{read macros}\index{macros!read}
44  are expanded just after a Prolog term has been read by the
45  {\eclipse} parser. Note that the parser is not only used during
46  compilation but by all
47  \biptxtref{term-reading}{read/1}{../bips/kernel/ioterm/read-1.html}
48  predicates.
49
50\item[compiler macros]\index{compiler macros}\index{macros!compiler}
51  are expanded only during compilation and only when a term occurs
52  in a certain context (clause or goal).
53
54\item[write macros]\index{write macros}\index{macros!write}
55  are expanded just before a Prolog term is printed by one of the
56  output predicates
57
58\end{description}
59\end{quote}
60
61In addition to transforming a term, macros can also be
62\emph{source annotation aware}, and provide source annotation information for
63the transformed term if
64supplied with source annotation information for the orginal term.  Source
65annotation information is about the source and position of a term, and is
66provided by the predicate
67 \bipref{read_annotated/3}{../bips/kernel/ioterm/read_annotated-3.html}.
68
69Macros are attached to classes of terms specified by their functors
70or by their type.
71Macros obey the module system's visibility rules.
72They may be either
73\biptxtref{local}{local/1}{../bips/kernel/modules/local-1.html}
74or
75\biptxtref{exported}{export/1}{../bips/kernel/modules/export-1.html}.
76The macro expansion is performed by a user-defined Prolog predicate.
77
78
79%----------------------------------------------------------------------
80\section{Using the macros}
81\label{usingmacros}
82%----------------------------------------------------------------------
83
84The following declarations and built-ins control macro expansion:
85\begin{quote}
86\begin{description}
87
88\item[local macro(+\pattern{TermClass}, +\pattern{TransPred},
89  +\pattern{Options})]
90  defines a macro for the given \about{TermClass}. The transformation itself
91  will
92  be performed by the predicate \about{TransPred}.
93
94\item[export macro(+\pattern{TermClass}, +\pattern{TransPred},
95      +\pattern{Options})]
96  as above, except that the macro is available to other modules.
97
98\item[erase_macro(+\pattern{TermClass}, +\pattern{Options})]
99  erases the macro that is  currently defined for \about{TermClass}. Note that
100  this can only be done in the module where the definition was made.
101
102\item[current_macro(?\pattern{TermClass}, ?\pattern{TransPred},
103       ?\pattern{Options}, ?\pattern{Module})]
104  can be used to get information about currently defined visible macros.
105
106\end{description}
107\end{quote}
108
109Macros are selectively applied only to terms of the specified class.
110\about{TermClass} can take two forms:
111\begin{quote}
112\begin{description}
113
114\item[\pattern{Name}/\pattern{Arity}]
115  transform all terms with the specified functor
116
117\item[type(\pattern{Type})]\index{type macros}\index{macros!type}
118  transform all terms of the specified type, where \about{Type}
119  is one of the following: \notation{compound}, \notation{string},
120  \notation{integer},
121  \notation{rational}, \notation{float}, \notation{breal}, \notation{atom},
122  \notation{goal}.\footnote{%
123    \notation{type(goal)} stands for suspensions.}
124
125\end{description}
126\end{quote}
127The \notation{+\pattern{TransPred}} argument specifies the predicate that will
128perform the
129transformation. It has to be either of arity 2 or 3 and should have the form:
130\begin{quote}
131\notation{\pattern{trans_function}(\pattern{OldTerm},~\pattern{NewTerm}%
132~[,~\pattern{Module}])~:-~...~.}
133\end{quote}
134or it can be source annotation aware, and be of arity 4 or 5, as follows:
135\begin{quote}
136\notation{\pattern{trans_function}(\pattern{OldTerm},~\pattern{NewTerm},%
137~\pattern{OldAnn},~\pattern{NewAnn}~[,~\pattern{Module}])~:-~...~.}
138\end{quote}
139At transformation time, the system will call \about{TransPred} in the module
140where \bipref{macro/3}{../bips/kernel/syntax/macro-3.html} was invoked.
141The term to transform is passed as the first argument, the second is a free
142variable which the transformation predicate should bind to the transformed
143term. In the case of the source annotation aware version of \about{TransPred},
144if
145the term was read in by \predspec{read_annotated/2,3}, the annotated version of
146the
147term to transformed is passed in the third argument, and the transformation
148should bind the fourth argument to the annotated transformed term;
149otherwise, if no source annotation information is available, the third
150argument is passed in as a free variable, and the transformation should not
151bind the fourth argument. In both \pattern{TransPred} cases, the optional last
152argument is the module where the term was being read in. See
153section~\ref{annotated} for more details on annotated terms.
154
155\about{Options} is a list which may be empty (in this case the macro defaults
156to a local read term macro) or contain specifications from
157the following categories:
158\begin{itemize}
159
160\item mode:
161  \begin{quote}
162  \begin{description}
163
164  \item[read:]\index{macros!read}
165    This is a read macro and shall be applied after reading a term (default).
166
167  \item[write:]\index{macros!write}
168    This is a write macro and shall be applied before printing a term.
169  \end{description}
170  \end{quote}
171
172\item type:
173  \begin{quote}
174  \begin{description}
175
176  \item[term:]\index{macros!term}
177    Transform all terms (default).
178
179  \item[clause:]\index{macros!clause}
180    Transform only if the term is a program clause, i.e., inside
181    \bipref{compile/1}{../bips/kernel/compiler/compile-1.html},
182    etc.\footnote{%
183      Note that clause transformation is {\em not} performed with
184      \bipref{assert/1}{../bips/kernel/dynamic/assert-1.html},
185      \bipref{retract/1}{../bips/kernel/dynamic/retract-1.html} and
186      \bipref{clause/1}{../bips/kernel/dynamic/clause-1.html}. This is a change
187      from previous versions of \eclipse.}
188    Write macros are applied using the \notation{C} option in the
189    \bipref{printf/2}{../bips/kernel/ioterm/printf-2.html} predicate.
190
191  \item[goal:]\index{macros!goal}
192    Goal-read-macros are transformed only if the term is a subgoal in the body
193    of a program clause.
194    Goal-write macros are applied using the \notation{G} option in the
195    \bipref{printf/2}{../bips/kernel/ioterm/printf-2.html} predicate.
196  \end{description}
197  \end{quote}
198
199\item additional specification:
200  \begin{quote}
201  \begin{description}
202
203  \item[protect_arg:]\index{macros!protect_arg}
204    Disable transformation of subterms (optional).
205
206  \item[top_only:]\index{macros!top_only}
207    Consider only the whole term, not subterms (optional).
208  \end{description}
209  \end{quote}
210\end{itemize}
211The following shorthands exist:
212\begin{quote}
213\begin{description}
214
215\item[local/export portray(+\pattern{TermClass},
216      +\pattern{TransPred}, +\pattern{Options}):]
217    \bipref{portray/3}{../bips/kernel/syntax/portray-3.html}
218    is like
219    \bipref{macro/3}{../bips/kernel/syntax/macro-3.html},
220    but the write-option is implied.
221
222\item[inline(+\pattern{PredSpec}, +\pattern{TransPred}):]
223    \bipref{inline/2}{../bips/kernel/compiler/inline-2.html}
224    is the same as a goal-read-macro. The visibility is inherited
225    from the transformed predicate.
226
227\end{description}
228\end{quote}
229
230Here is an example of a conditional read macro:
231\begin{quote}
232\begin{verbatim}
233[eclipse 1]: [user].
234 trans_a(a(X,Y), b(Y)) :-    % transform a/2 into b/1,
235        number(X),           % but only under these
236        X > 0.               % conditions
237
238:- local macro(a/2, trans_a/2, []).
239  user       compiled traceable 204 bytes in 0.00 seconds
240
241yes.
242[eclipse 2]: read(X).
243        a(1, hello).
244
245X = b(hello)                 % transformed
246yes.
247[eclipse 3]: read(X).
248        a(-1, bye).
249
250X = a(-1, bye)               % not transformed
251yes.
252\end{verbatim}
253\end{quote}
254If the transformation function fails, the term is not transformed. Thus,
255\notation{a(1, zzz)} is transformed into \notation{b(zzz)} but
256\notation{a(-1, zzz)}
257is not transformed.
258The arguments are transformed bottom-up. It is possible to protect the
259subterms of a transformed term by specifying the flag \notation{protect_arg}.
260
261A term can be protected against transformation by quoting it with
262the ``protecting functor'' (by default it is
263\predspecidx{no_macro_expansion/1}):\index{macro!no_macro_expansion}
264\begin{quote}
265\begin{verbatim}
266[eclipse 4]: read(X).
267        a(1, no_macro_expansion(a(1, zzz))).
268X = b(a(1, zzz)).
269\end{verbatim}
270\end{quote}
271Note that the protecting functor is itself defined as a macro:
272\begin{quote}
273\begin{verbatim}
274trprotect(no_macro_expansion(X), X).
275:- export macro(no_macro_expansion/1, trprotect/2, [protect_arg]).
276\end{verbatim}
277\end{quote}
278
279A local macro is only visible in the module where it has been defined.
280When it is defined as exported, then it is copied to all
281other modules that contain a
282\bipref{use_module/1}{../bips/kernel/modules/use_module-1.html} or
283\bipref{import/1}{../bips/kernel/modules/import-1.html}
284for this module.
285The transformation function should also be exported in this case.
286There are a few global macros predefined by the system, e.g., for
287% the following stops latex2html from turning --> into ->
288{\tt -}{\tt ->/2} (grammar rules, see below) or \predspec{with/2} and
289\predspec{of/2}
290(structure syntax, see section \ref{chapstruct}).
291These predefined macros can be hidden by local macro definitions.
292
293The global flag \notationidx{macro_expansion} can be used to disable
294macro expansion globally, e.g., for debugging purposes.
295Use \notation{set_flag(macro_expansion, off)} to do so.
296
297The next example shows the use of a type macro. Suppose we want to represent
298integers as \predspec{s/1} terms:
299\begin{quote}
300\begin{verbatim}
301[eclipse 1]: [user].
302 tr_int(0, 0).
303 tr_int(N, s(S)) :- N > 0, N1 is N-1, tr_int(N1, S).
304 :- local macro(type(integer), tr_int/2, []).
305
306yes.
307[eclipse 2]: read(X).
308        3.
309
310X = s(s(s(0)))
311yes.
312\end{verbatim}
313\end{quote}
314When we want to convert the \predspec{s/1} terms back to normal integers so that
315they
316are printed in the familiar form, we can use a write macro.
317Note that we first erase the read macro for integers, otherwise we would get
318unexpected effects since all integers occurring in the definition of
319\predspec{tr_s/2} would turn into \predspec{s/1} structures:
320\begin{quote}
321\begin{verbatim}
322[eclipse 3]: erase_macro(type(integer)).
323
324yes.
325[eclipse 4]: [user].
326 tr_s(0, 0).
327 tr_s(s(S), N) :- tr_s(S, N1), N is N1+1.
328 :- local macro(s/1, tr_s/2, [write]).
329
330yes.
331[eclipse 2]: write(s(s(s(0)))).
3323
333yes.
334\end{verbatim}
335\end{quote}
336
337\subsection{Source annotation aware macro transformations}
338\label{annotated}
339When the macro transformation predicate has 4 or 5 arguments, it is termed
340source annotation aware, and the extra
341arguments are used to specify how source information from the
342original term should be mapped to the transformed term.
343
344An annotated term provides the source information about a term. It
345is structurally similar to the original term and
346contains all information about the term, plus additional type information,
347variable names, and source position annotations for all subterms.
348
349The structure of the descriptive terms is as follows:
350
351\vfill %<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
352
353\begin{quote}
354\begin{verbatim}
355:- export struct(annotated_term(
356                                term,     % var, atomic or compound
357                                type,     % term type (see below)
358                                file,     % source file name (atom)
359                                line,     % source line (integer)
360                                from, to  % source position (integers)
361                 ...
362                )).
363\end{verbatim}
364\end{quote}
365
366The type-field describes the type of the original term and provide type
367information similar to those used in
368\bipref{type_of/2}{../bips/kernel/typetest/type_of-2.html}, except that they
369convey additional information about variables and \notation{end_of_file}.
370
371In the case of atomic terms and variables, the term-field simply contains the
372plain original term. For compound terms, the term-field contains a structure
373whose functor is the functor of the plain term, but whose arguments are
374annotated versions of the plain term arguments.
375
376For example, the annotated term representing the source term
377\notation{foo(bar, X, _, 3)} is:
378
379\begin{quote}
380\begin{verbatim}
381annotated_term(foo(
382                   annotated_term(bar, atom, ...),
383                   annotated_term(X, var('X'), ...),
384                   annotated_term(_, anonymous, ...),
385                   annotated_term(3, integer, ...)
386                  ),
387               compound,
388               ...
389              )
390\end{verbatim}
391\end{quote}
392
393The file/line/from/to-fields of an annotated term describe the
394"source position" of the term, as follows:
395
396\begin{description}
397\item[file]
398    The canonical file name of the source file (an atom), or the
399    empty atom \notation{'}\notation{'} if the source is not a file or is not
400    known.
401
402\item[line]
403    The line number in the source stream (positive integer).
404
405\item[from, to]
406    The exact term position as integer offsets in the source stream,
407    starting at \about{from} and ending at $\mbox{\about{to}}-1$.
408\end{description}
409
410The extra arguments for the transformation predicate are a pair of
411annotated terms for the original and transformed term. The predicate will
412be supplied with the annotated term for the original term if available,
413and the predicate is responsible for specifying the annotated term for the
414transformed term---the structure of the transformed annotated term must
415match the annotated term structure expected for the transformed term. If
416no annotated information is available, the original annotated term will be
417a variable, and the predicate must not bind the transformed annotated term.
418
419For an example, here is a source annotation aware version of the previous
420\predspec{trans_a/2} example:
421
422\begin{verbatim}
423[eclipse 1]: [user].
424...
425
426 trans_a(a(X,Y), b(Y), AnnA, AnnTrans) :-
427        number(X),
428        X > 0,
429        ( var(AnnA) ->
430              true      % no source information, leave AnnTrans as var
431        ;
432              AnnA = annotated_term{term:a(_AnnX, AnnY),
433                                    file:File, line:Line,
434                                    from:From,to:To},
435              AnnTrans = annotated_term{term:b(AnnY),
436                                    type: compound,
437                                    file:File, line:Line,
438                                    from:From,to:To}
439         ).
440
441:- local macro(a/2, trans_a/4, []).
442
443Yes (0.23s cpu)
444[eclipse 2]: read_annotated(user, X, Y).
445 a(3,bar(X)).
446
447X = b(bar(X))
448Y = annotated_term(b(annotated_term(bar(annotated_term(X, var('X'), user, 18,
449654, 655)), compound, user, 18, 650, 654)), compound, user, 18, 646, 648)
450
451\end{verbatim}
452
453In the example, the main functor of the transformed predicate, \predspec{b/1},
454inherits the annotation information for the original term's principal
455functor, \predspec{a/2}. The argument Y in the transformed term takes the
456annotation information from the corresponding argument in the original
457term.
458
459
460
461The source annotation aware transformation predicate facility is provided to
462allow the user to access the details of how the subterms of the original term
463are mapped to the transformed term. Without this extra information, the whole of
464the transformed term is given the source information (source position, source
465file etc.) of the original source term. This extra information is useful when
466the subterms are goals, because without the extra information, source tracing of
467these goals during debugging will not be done.
468
469
470%----------------------------------------------------------------------
471\section{Definite Clause Grammars --- DCGs}
472\label{dcg}
473%----------------------------------------------------------------------
474\index{DCG}
475\index{definite clause grammar}
476\index{grammar rules}
477\index{\notation{-}\notation{->/2}}
478Grammar rules are described in many standard Prolog texts (\cite{clocksin81}).
479In {\eclipse} they are provided by a predefined global\footnote{%
480  So that the user can redefine it with a local one.}
481macro for
482% the following stops latex2html from turning --> into ->
483{\tt -}{\tt ->/2}.
484When the parser reads a clause whose main functor is
485% the following stops latex2html from turning --> into ->
486 {\tt -}{\tt ->/2}, it transforms
487it according to the standard rules.
488The syntax for DCGs is as follows:
489\begin{quote}
490\begin{verbatim}
491grammar_rule --> grammar_head, ['-->'], grammar_body.
492
493grammar_head --> non_terminal.
494grammar_head --> non_terminal, [','], terminal.
495
496grammar_body --> grammar_body, [','], grammar_body.
497grammar_body --> grammar_body, [';'], grammar_body.
498grammar_body --> grammar_body, ['->'], grammar_body.
499grammar_body --> grammar_body, ['|'], grammar_body.
500grammar_body --> iteration_spec, ['do'], grammar_body.
501grammar_body --> ['-?->'], grammar_body.
502grammar_body --> grammar_body_item.
503
504grammar_body_item --> ['!'].
505grammar_body_item --> ['{'], Prolog_goals, ['}'].
506grammar_body_item --> non_terminal.
507grammar_body_item --> terminal.
508\end{verbatim}
509\end{quote}
510The non-terminals are syntactically identical to prolog goals (atom, compound
511term or variable), the terminals are lists of prolog terms (typically
512characters or tokens). Every
513term is transformed, unless it is enclosed in curly brackets. The control
514constructs like conjunction \predspec{,/2},
515disjunction (\predspec{;/2} or \predspec{|/2}),
516the cut (\predspec{!/0}), the condition (\predspec{\notation{->}/1}) and
517do-loops need not be enclosed in curly brackets.
518
519The grammar can be accessed with the built-in
520\bipref{phrase/3}{../bips/kernel/control/phrase-3.html}.
521The first argument of \bipref{phrase/3}{../bips/kernel/control/phrase-3.html} is
522the name of the
523grammar to be used, the
524second argument is a list containing the input to be parsed. If the
525parsing is successful the built-in will succeed.
526For instance, with the grammar
527\begin{quote}
528\begin{verbatim}
529a --> [] | [z], a.
530\end{verbatim}
531\end{quote}
532\notation{phrase(a, X, [])} will give on backtracking
533\begin{quote}
534\begin{verbatim}
535X = [z] ; X = [z, z] ; X = [z, z, z] ; ....
536\end{verbatim}
537\end{quote}
538
539\subsection{Simple DCG example}
540
541The following example illustrates a simple grammar declared using the DCGs.
542
543\begin{quote}
544\begin{verbatim}
545sentence --> imperative, noun_phrase(Number), verb_phrase(Number).
546
547imperative, [you] --> [].
548imperative --> [].
549
550noun_phrase(Number) --> determiner, noun(Number).
551noun_phrase(Number) --> pronoun(Number).
552
553verb_phrase(Number) --> verb(Number).
554verb_phrase(Number) --> verb(Number), noun_phrase(_).
555
556determiner --> [the].
557
558noun(singular) --> [man].
559noun(singular) --> [apple].
560noun(plural) --> [men].
561noun(plural) --> [apples].
562
563verb(singular) --> [eats].
564verb(singular) --> [sings].
565verb(plural) --> [eat].
566verb(plural) --> [sing].
567
568pronoun(plural) --> [you].
569\end{verbatim}
570\end{quote}
571The above grammar may be applied by
572using \bipref{phrase/3}{../bips/kernel/control/phrase-3.html}. If the predicate
573succeeds then the input has been parsed successfully.
574\begin{quote}
575\begin{verbatim}
576[eclipse 1]: phrase(sentence, [the,man,eats,the,apple], []).
577
578yes.
579[eclipse 2]: phrase(sentence, [the,men,eat], []).
580
581yes.
582[eclipse 3]: phrase(sentence, [the,men,eats], []).
583
584no.
585[eclipse 4]: phrase(sentence, [eat,the,apples], []).
586
587yes.
588[eclipse 5]: phrase(sentence, [you,eat,the,man], []).
589
590yes.
591\end{verbatim}
592\end{quote}
593The predicate \bipref{phrase/3}{../bips/kernel/control/phrase-3.html} may be
594used to return the point at which
595parsing of input fails---if the returned list is empty then the
596input has been successfully parsed.
597
598\begin{quote}
599\begin{verbatim}
600[eclipse 1]: phrase(sentence, [the,man,eats,something,nasty],X).
601
602X = [something, nasty]     More? (;)
603
604no (more) solution.
605[eclipse 2]: phrase(sentence, [eat,the,apples],X).
606
607X = [the, apples]     More? (;)
608
609X = []     More? (;)
610
611no (more) solution.
612[eclipse 3]: phrase(sentence, [hello,there],X).
613
614no (more) solution.
615\end{verbatim}
616\end{quote}
617
618\subsection{Mapping to Prolog clauses}
619A grammar rule is translated to a Prolog clause by adding two arguments
620which represent the input before and after the nonterminal which is
621represented by the rule.
622The effect of the transformation can be observed, e.g., by calling
623\bipref{expand_clause/2}{../bips/kernel/compiler/expand_clause-2.html}:
624\begin{quote}
625\begin{verbatim}
626[eclipse 1]: expand_clause(p(X) --> q(X), Expanded).
627
628X = X
629Expanded = p(X, _250, _243) :- q(X, _250, _243)
630Yes (0.00s cpu)
631[eclipse 2]: expand_clause(p(X) --> [a], Expanded).
632
633X = X
634Expanded = p(X, _251, _244) :- 'C'(_251, a, _244)
635Yes (0.00s cpu)
636\end{verbatim}
637\end{quote}
638
639\subsection{Parsing other data structures}
640
641DCGs are in principle not limited to the parsing of lists.
642The predicate \bipref{'C'/3}{../bips/kernel/termmanip/C-3.html} is responsible
643for reading resp.\ generating
644the input tokens. The default definition is
645\begin{quote}
646\begin{verbatim}
647'C'([Token|Rest], Token, Rest).
648\end{verbatim}
649\end{quote}
650The first argument represents the parsing input before consuming
651\about{Token} and \about{Rest} is the input after consuming \about{Token}.
652
653By redefining \predspec{'C'/3}, it is possible to apply a DCG to
654input sources other than a list, e.g., to parse directly from an I/O stream:
655\begin{quote}
656\begin{verbatim}
657:- local 'C'/3.
658'C'(Stream-Pos0, Token, Stream-Pos1) :-
659        seek(Stream, Pos0),
660        read_string(Stream, " ", _, TokenString),
661        atom_string(Token, TokenString),
662        at(Stream, Pos1).
663
664 sentence --> noun, [is], adjective.
665 noun --> [prolog] ; [lisp].
666 adjective --> [boring] ; [great].
667\end{verbatim}
668\end{quote}
669This can then be applied to a string as follows:
670\begin{quote}
671\begin{verbatim}
672[eclipse 1]: String = "prolog is great", open(String, string, S),
673             phrase(sentence, S-0, S-End).
674...
675End = 15
676yes.
677\end{verbatim}
678\end{quote}
679Here is another redefinition of \predspec{'C'/3}, using a similar idea, which
680allows  direct parsing of {\eclipse} strings as sequences of characters:
681\begin{quote}
682\begin{verbatim}
683:- local 'C'/3.
684'C'(String-Pos0, Char, String-Pos1) :-
685        Pos0 =< string_length(String),
686        string_code(String, Pos0, Char),
687        Pos1 is Pos0+1.
688
689anagram --> [].
690anagram --> [_].
691anagram --> [C], anagram, [C].
692\end{verbatim}
693\end{quote}
694This can then be applied to a string as follows:
695\begin{quote}
696\begin{verbatim}
697[eclipse 1]: phrase(anagram, "abba"-1, "abba"-5).
698yes.
699[eclipse 2]: phrase(anagram, "abca"-1, "abca"-5).
700no (more) solution.
701\end{verbatim}
702\end{quote}
703Unlike the default definition, these redefinitions of \predspec{'C'/3} are not
704bi-directional.
705Consequently, the grammar rules using them can only be used for parsing,
706not for generating sentences.
707
708Note that every grammar rule uses that definition of \predspec{'C'/3} which is
709visible in
710the module where the grammar rule itself is defined.
711
712%HEVEA\cutend
713