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) 2006 Cisco Systems, Inc.  All Rights Reserved.
18% 
19% Contributor(s): 
20% 
21% END LICENSE BLOCK
22
23:- comment(alias, "Syntax Settings").
24:- comment(summary, "Operators, structures, macros, character classes").
25:- comment(categories, ["Built-In Predicates"]).
26
27:- tool(current_macro / 4).
28:- tool(current_struct / 2).
29:- tool(define_macro / 3).
30:- tool(erase_macro / 2).
31:- tool(get_chtab / 2).
32:- tool(set_chtab / 2).
33:- tool(current_op / 3).
34:- tool(op / 3).
35
36:- comment(macro / 3, [
37	summary:"Defines a macro transformation for the functor or type specified by TermClass.",
38	template:["local macro(++TermClass, ++TransPred, ++Options)",  "export macro(++TermClass, ++TransPred, ++Options)"],
39	amode:(macro(++,++,++) is det),
40	index:["no_macro_expansion/1", "macro_expansion"],
41	desc:html("\
42   This declaration is used to define a macro transformation on a class of
43   terms.  Macro transformations are performed when a term is read by one of
44   the predicates read/1,2, read_term/2,3, readvar/3 or read_annotated/2,3 
45   (unless the stream flag or global flag macro_expansion is switched off).
46<P>
47   The TermClass specifies to which terms the transformation will be
48   applied:
49<DL>
50    <DT><STRONG>Name/Arity</STRONG><DD>
51	transform all terms with the specified functor
52    <DT><STRONG>type(Type)</STRONG><DD>
53	transform all terms of the specified type, where Type is one of
54	compound, string, integer, rational, float, breal, goal, atom, meta.
55</DL>
56   The +TransPred argument specifies the predicate that will perform the
57   transformation.  TransPred can be of either arity 2 or 3, and be in the 
58   form:
59<PRE>
60	trans_function(OldTerm, NewTerm [, Module]) :- ... .
61</PRE>
62   or it can be source annotation aware, and be of arity 4 or 5, as follows:
63<PRE>
64	trans_function(OldTerm, NewTerm, OldAnn, NewAnn [, Module]) :- ... .
65</PRE>
66   At transformation time, the system will call TransPred in the module
67   where <CODE>local macro/3</CODE> was invoked. The term to transform is
68   passed as the first argument, the second is a free variable which the
69   transformation should bind to the transformed term. In the case of the
70   source annotation aware version of TransPred, if the term was read in by
71   read_annotated/2,3, the annotated version of the term to transformed is
72   passed in the third argument, and the transformation should bind the
73   fourth argument to the annotated transformed term; otherwise, if no
74   source annotation information is available, the third argument is passed
75   in as a free variable, and the transformation should not bind the fourth
76   argument. In both TransPred cases, the optional last argument is the
77   module where the term was being read in.
78<P>
79   Options is a list which may be empty or contain one of the following
80   type specification atoms:
81<DL>
82    <DT><STRONG>term</STRONG> (default)<DD>
83	Transform the term in all contexts (this is the default, and the
84	transformation is done in the parser, or explicitly via expand_macros/2)
85    <DT><STRONG>clause</STRONG><DD>
86	Transform only if the term is a program clause, i.e. inside
87        compile/1, assert/1 etc, or explicitly via expand_clause/2.
88    <DT><STRONG>goal</STRONG> (deprecated)<DD>
89	Transform only if the term is a goal. This form is deprecated,
90	please use inline/2 to transform goals.
91</DL>
92   and possibly some of the following options:
93<DL>
94    <DT><STRONG>protect_arg</STRONG> (optional)<DD>
95	Disable transformation of subterms. If this option is used, the
96	transformation predicate itself should take care of transforming
97	those subterms that should be transformed (expand_macros/2).
98	This option is only useful for term-macros because only those
99	perform automatic subterm transformation.
100    <DT><STRONG>top_only</STRONG> (deprecated)<DD>
101	Consider only the whole term, not subterms.
102	This option is deprecated, use clause and goal options instead.
103</DL>
104   The visibility of macros is controlled by the module system.
105   Transformations only take place when the macro declaration is
106   visible in the module where the term is read in.
107   The macro visibility is local or exported, depending on the declaration.
108<P>
109   In rare cases it is necessary to suppress macro expansion explicitly.
110   The functor no_macro_expansion/1 can be wrapped around specific
111   instances of a term to prevent it from being transformed.
112   Macro expansion will then remove this wrapper so that the end
113   result is the untransformed term alone.
114<P>
115   Term-transformations (but not clause/goal transformation) automatically
116   transform all subterms of a term in a bottom-up fashion. This means that
117   the transformation predicate will see a term with already transformed
118   subterms.
119<P>
120   The source annotation aware transformation predicate is provided to
121   allow the user to detail how the subterms of the original term is mapped
122   to the transformed term. Without this extra information, the whole of
123   the transformed term is given the source information (source position,
124   source file etc.) of the original source term. This extra information is
125   useful when the subterms are goals, because without the extra
126   information, source tracing of these goals during debugging will not be
127   done.
128"),
129	args:["TermClass" : "Term in the form Atom, Atom/Integer or type(Type).",
130	    "TransPred" : "Term in the form Atom/Integer.",
131	    "Options" : "Possibly empty list of option flags."],
132	exceptions:[4 : "One or more arguments not instantiated.",
133	    5 : "TermClass not of form Atom, Atom/Integer or type(Type).",
134	    5 : "TransPred not of form Atom/Integer.",
135	    5 : "Options not a list or contains invalid flags.",
136	    6 : "Arity of TransPred is not 2 or 3.",
137	    6 : "Illegal flag in Options.",
138	    161 : "Transformation already defined in the current module for TermClass"],
139	eg:"
140% The following example illustrates how a/1 may be
141% transformed into b/2 using the reader:
142
143   [eclipse]: [user].
144
145    trans_a(a(X),b(X,10)).
146
147    :- local macro(a/1,trans_a/2,[]).
148
149   yes.
150   [eclipse]: read(X).
151    a(fred).
152
153   X = b(fred, 10)
154   yes.
155
156
157% Example showing use of protect_arg:
158
159   [eclipse]: [user].
160
161    trb(X, newfunctor(Arg)) :- arg(1, X, Arg).
162    trd(d, newd).
163
164    :- local macro(b/1, trb/2, []),
165	     macro(b_protect/1, trb/2, [protect_arg]),
166	     macro(d/0, trd/2, []).
167
168   yes.
169   [eclipse]: read(X1),read(X2).
170    b(d).
171    b_protect(d).
172
173   X1 = newfunctor(newd)    % d is transformed
174   X2 = newfunctor(d)       % d is not transformed
175   yes.
176
177
178% Example showing use of type macros
179
180    [eclipse 1]: [user].
181
182     tr_int(0, 0).
183     tr_int(N, s(S)) :- N > 0, N1 is N-1, tr_int(N1, S).
184
185     :- local macro(type(integer), tr_int/2, []).
186
187    yes.
188    [eclipse 2]: read(X).
189    3.
190
191    X = s(s(s(0)))
192    yes.
193
194
195% Example showing use of annotation aware macro transformation
196
197    [eclipse 1]: [user].
198    trans_r(r(A,B), New, AnnR, AnnNew) :-
199           New = rr(B,A),
200           (nonvar(AnnR) ->
201               AnnR = annotated_term{term:RAnn},
202               RAnn = r(AnnA,AnnB),
203               NewRAnn = rr(AnnB,AnnA),
204               update_struct(annotated_term, [term:NewRAnn], AnnR, AnnNew)
205           ; 
206               true
207           ).
208
209    :- local macro(r/2, trans_r/4,[]).
210            
211    yes.
212    [eclipse 2]: read(user,R).  
213    r(a,b).
214
215    R = rr(b, a)
216    yes.
217    [eclipse 3]: read_annotated(user,R,AR).      
218    r(a,b).
219
220    R = rr(b, a)
221    AR = annotated_term(rr(annotated_term(b, atom, user, 15, 362, 363), annotated_term(a, atom, user, 15, 360, 361)), compound, user, 15, 358, 360)
222    yes.
223
224% The previous example with non-annotation aware transformation:
225
226    [eclipse 1]: [user].
227    trans_r(r(A,B),rr(B,A)).
228    :- local macro(r/2, trans_r/  2,[]).
229
230    yes.
231    [eclipse 2]: read_annotated(user,R,AR).
232    r(a,b).
233
234    R = rr(b, a)
235    AR = annotated_term(rr(annotated_term(b, atom, user, 3, 61, 63), annotated_term(a, atom, user, 3, 61, 63)), compound, user, 3, 61, 63)
236    % all subterms have the same position information
237
238Error:
239   local macro(X, trx/2, []).              (Error 4).
240   local macro(a/1, tra/2, [c]).           (Error 6).
241",
242	see_also:[portray/3, expand_macros/2, expand_clause/2, current_macro / 4, erase_macro / 2, phrase / 3, inline / 2, read_annotated / 3]]).
243
244
245:- comment(portray / 3, [
246	summary:"Defines a portray transformation for the functor or type specified by TermClass.",
247	template:["local portray(++TermClass, ++TransPred, ++Options)", "export portray(++TermClass, ++TransPred, ++Options)"],
248	amode:(portray(++,++,++) is det),
249	desc:html("\
250   This declaration is used to define a portray transformation on a class of
251   terms.  Portray transformations are performed when a term is written by
252   one of the predicates write/1,2, writeln/1,2, print/1,2, display/1,2,
253   printf/2,3 without the 'T' output option, or write_term/2,3 unless the
254   transform(false) option is used.  Alternatively, portray transformations
255   can be invoked explicitly via portray_term/3.
256<P>
257   The TermClass specifies to which terms the transformation will be
258   applied:
259<DL>
260    <DT><STRONG>Name/Arity</STRONG><DD>
261	transform all terms with the specified functor
262    <DT><STRONG>type(Type)</STRONG><DD>
263	transform all terms of the specified type, where Type is one of
264	compound, string, integer, rational, float, breal, goal, atom, meta.
265</DL>
266   The +TransPred argument specifies the predicate that will perform the
267   transformation.  TransPred must be of arity 2 or 3 and be in the form:
268<PRE>
269	trans_function(OldTerm, NewTerm [, Module]) :- ... .
270</PRE>
271   At transformation time, the system will call TransPred in the module
272   where <CODE>local portray/3</CODE> was invoked.  The term to transform is passed
273   as the first argument, the second is a free variable which the
274   transformation should bind to the transformed term, and the optional
275   third argument is the module where the term is going to be printed.
276<P>
277   Options is a list which may be empty or contain one of the following
278   type specification atoms:
279<DL>
280    <DT><STRONG>term</STRONG> (default)<DD>
281	Transform all terms (this is the default)
282    <DT><STRONG>clause</STRONG><DD>
283	Transform only if the term is printed as a program clause,
284	i.e. by printf/2,3 with the 'C' output option, or write_term/2,3
285	with the as(clause) option.
286    <DT><STRONG>goal</STRONG><DD>
287	Transform only if the term is printed as a goal,
288	i.e. by printf/2,3 with the 'G' output option, or write_term/2,3
289	with the as(goal) option.
290</DL>
291   and possibly the following option:
292<DL>
293    <DT><STRONG>protect_arg</STRONG> (optional)<DD>
294	Disable transformation of subterms. If this option is used, the
295	transformation predicate itself should take care of transforming
296	those subterms that should be transformed (portray_term/3).
297	This option is only useful for term-transformation because only
298	those perform automatic subterm transformation.
299</DL>
300   The visibility of portray declarations is controlled by the module
301   system.  Transformations only take place when the portray
302   declarations is visible in the module where the term is being
303   printed.  The visibility is local or exported, depending on the
304   declaration.
305<P>
306   Portray declarations are being treated as 'write'-macros in
307   current_macro/4 and erase_macro/2.
308<P>
309   Term-transformations (but not clause/goal transformation) automatically
310   transform all subterms of a term in a top-down fashion. This means that
311   the transformation predicate will see a term with untransformed subterms.
312"),
313	args:["TermClass" : "Term in the form Atom, Atom/Integer or type(Type).",
314	    "TransPred" : "Term in the form Atom/Integer.",
315	    "Options" : "Possibly empty list of option flags."],
316	exceptions:[4 : "One or more arguments not instantiated.",
317	    5 : "TermClass not of form Atom, Atom/Integer or type(Type).",
318	    5 : "TransPred not of form Atom/Integer.",
319	    5 : "Options not a list or contains invalid flags.",
320	    6 : "Arity of TransPred is not 2 or 3.",
321	    6 : "Illegal flag in Options.",
322	    161 : "Transformation already defined in the current module for TermClass"],
323	eg:"
324% Example showing use of write macros
325
326    [eclipse 1]: [user].
327
328     :- local portray(s/1, tr_s/2, []).
329     tr_s(0, 0).
330     tr_s(s(S), N) :- tr_s(S, N1), N is N1+1.
331
332    yes.
333    [eclipse 2]: write(s(s(s(0)))).
334    3
335    yes.
336
337
338Error:
339   local portray(X, trx/2, []).              (Error 4).
340   local portray(a/1, tra/2, [c]).           (Error 6).
341",
342	see_also:[portray_term/3, macro/3, printf/2, printf/3, current_macro / 4, erase_macro / 2]]).
343
344
345:- comment(current_macro / 4, [
346	summary:"Succeeds if TermClass is a macro with the transformation predicate
347TransPred defined in module Module and flags Options.
348
349",
350	amode:(current_macro(-,-,-,-) is nondet),
351	desc:html("   This predicate enumerates all visible macros and retrieves their
352   definition.  The arguments TransPred and Options correspond to the
353   arguments of macro/3 or portray/3.  Module is the definition module of
354   TransPred and it can be used for calling the TransPred explicitly (e.g.
355   using :/2).
356
357<P>
358"),
359	args:["TermClass" : "Term in the form Atom/Integer or atom or variable.", "TransPred" : "Term in the form Atom/Integer or variable.", "Options" : "List or a variable.", "Module" : "Atom or variable."],
360	exceptions:[5 : "TermClass not of form Atom/Integer.", 5 : "TransPred not of form Atom/Integer.", 5 : "Options not a list."],
361	eg:"
362[eclipse]: [user].             % define a macro
363 tr_a(a(X), b(X,X)).
364 :- local macro(a/1, tr_a/2, []).
365
366yes.
367[eclipse]: current_macro(F, T, O, M).  % list visible macros
368
369F = (-->) / 2                  % predefined macro
370T = trdcg / 3
371O = [global, clause]
372M = macro     More? (;)
373
374F = (if) / 2                   % predefined macro
375T = tr_if / 2
376O = [global, clause]
377M = coroutine     More? (;)
378
379F = a / 1                      % our user defined macro
380T = tr_a / 2
381O = [local]
382M = eclipse     More? (;)
383
384F = no_macro_expansion / 1     % predefined macro
385T = trprotect / 2
386O = [global, protect_arg]
387M = macro     More? (;)
388
389no (more) solution.
390
391
392
393",
394	see_also:[macro / 3, portray/3, erase_macro / 2]]).
395
396:- comment(current_struct / 2, [
397	summary:"Succeeds if Name is the name of a currently visible structure and Struct is its specification",
398	amode:(current_struct(+,-) is semidet),
399	amode:(current_struct(-,-) is nondet),
400	desc:html("<P>
401	Used to retrieve the definition of a defined structure, or to
402	enumerate all visible structure definitions.
403	</P><P>
404	Visible structures are those which have either been declared locally,
405	exported, or which have been imported or reexported from another module.
406	</P>
407"),
408	args:["Name" : "Variable or atom",
409	    "Struct" : "Variable or structure."],
410	fail_if:"Name is not the name of a visible structure definition",
411	exceptions:[
412		5 : "Name is neither variable nor atom.",
413		5 : "Struct is neither variable nor structure."],
414	eg:"
415    :- local struct(employee(name,age,salary)).
416
417    ?- current_struct(employee, Spec).
418    Spec = employee(name, age, salary)
419    yes.
420
421    ?- current_struct(Name, Spec).
422    Name = employee
423    Spec = employee(name, age, salary)
424    More (0.00s cpu) ? ;
425
426    Name = suspend
427    Spec = suspend(inst, constrained, bound)
428    More (0.00s cpu) ? ;
429
430    No (0.00s cpu)
431
432    ?- current_struct(book, Spec).
433    No (0.00s cpu)
434",
435	see_also:[(local) / 1, (export)/1, struct / 1]]).
436
437:- comment(op / 3, [
438	summary:"Declare operator syntax.",
439	template:["op(+Precedence, +Associativity, ++Name)",
440		"local op(+Precedence, +Associativity, ++Name)",
441		"export op(+Precedence, +Associativity, ++Name)"],
442	amode:(op(+,+,++) is det),
443	desc:html("\
444   Declares Name as an operator of precedence Precedence and associativity
445   Associativity. Operators are purely a syntactic convenience: they allow
446   prefix-, infix- or postfix-syntax as an alternative to the canonical
447   functor-syntax for structures with one or two arguments. If used
448   carefully, they can contribute to making code more readable.
449<P>
450   Precedence is an integer in the range 0 to 1200. An operator with a lower
451   precedence number binds its arguments more strongly than an operator with
452   higher precendence number.
453<P>
454   The different classes of operators are distinguished through the
455   Associativity argument:
456<PRE>
457    Operator class      Associativities
458    ---------------------------------------------------------------
459     prefix             fx, fy (unary) or fxx, fxy (binary)
460     infix              xfx, xfy, yfx
461     postfix            xf, yf
462</PRE>
463   x represents an argument whose precedence must be lower than that of the
464   operator.  y represents an argument whose precedence must be lower or
465   equal to that of the operator.  y should be used if one wants to allow
466   chaining of operators.  The position of the y will determine the
467   grouping within a chain of operators. Examples:
468<PRE>
469    Example declaration        will allow          to stand for
470    ---------------------------------------------------------------
471    :- op(500,xfx,in).         A in B              in(A,B)
472    :- op(500,xfy,in).         A in B in C         in(A,in(B,C))
473    :- op(500,yfx,in).         A in B in C         in(in(A,B),C)
474    :- op(500,fx ,pre).        pre A               pre(A)
475    :- op(500,fy ,pre).        pre pre A           pre(pre(A))
476    :- op(500, xf,post).       A post              post(A)
477    :- op(500, yf,post).       A post post         post(post(A))
478    :- op(500,fxx,bin).        bin A B             bin(A,B)
479    :- op(500,fxy,bin).        bin A bin B C       bin(A,bin(B,C))
480</PRE>
481   Prefix, infix and postfix operators are independent of each other and
482   may coexist.  See the manual chapter on syntax about how ambiguities are
483   resolved in this case.
484<P>
485   Operators can be local or exported, depending on the definition. The
486   default is local, i.e. the following declarations are equivalent:
487<PRE>
488    :- op(500, xfy, before).
489    :- local op(500, xfy, before).
490</PRE>
491   while
492<PRE>
493    :- export op(500, xfy, before).
494</PRE>
495   will export the operator to all modules that import the module containing
496   the declaration.  There are also a number of predefined global operators,
497   see the User Manual appendix for a complete list.
498<P>
499   Name may be a single atom or a list of atoms, in which case each is
500   given the specified precedence and associativity.  A value of [] is
501   interpreted as the empty list.  To declare [] as an operator, use
502   e.g. op(500,fx,[[]]).
503<P>
504   A precedence of 0 has a special meaning.  It erases a local operator
505   definition and/or hides a global operator of the same name and
506   associativity class.
507<P>
508"),
509	args:["Precedence" : "Integer.", "Associativity" : "Atom.", "Name" : "Atom or List of atoms."],
510	exceptions:[4 : "Any of the input arguments is uninstantiated.", 5 : "Precedence is not an integer.", 5 : "Name is not an atom or list of atoms.", 5 : "Associativity is not an atom.", 6 : "Precedence is not in range 0 to 1200.", 6 : "Associativity is not one of xf, xfx, fy, etc."],
511	eg:"
512Success:
513      [eclipse]: module(a).
514      [a]: current_op(X, Y, +).    % there are two global operators
515      X = 500
516      Y = yfx     More? (;)
517      X = 500
518      Y = fx     More? (;)
519      no (more) solution.
520      [a]: display(a+b*c).         % see how it is parsed
521      +(a, *(b, c))
522      yes.
523
524      [a]: op(100, xfy, +).        % define a local infix
525      yes.
526      [a]: display(a+b*c).         % parsed differently now!
527      *(+(a, b), c)
528      yes.
529
530      [a]: op(0, xfy, +).          % just hide the global infix
531      yes.
532      [a]: current_op(X, Y, +).
533      X = 500
534      Y = fx     More? (;)
535      no (more) solution.
536
537Error:
538      op(X, fx, aaa).             (Error 4).
539      op(a, fx, aaa).             (Error 5).
540      op(100, xfx, 1).            (Error 5).
541      op(100, abc, fred).         (Error 6).
542      op(100, xfx, aaa),
543          op(100,xf,aaa).         (Error 43).
544
545
546
547",
548	see_also:[current_op / 3, (local) / 1, (export)/1]]).
549
550:- comment(struct / 1, [
551	summary:"Declare a structure according to Prototype.",
552	template:["local struct(++Prototype)", "export struct(++Prototype)"],
553	amode:(struct(++) is det),
554	index:["with", "of"],
555	desc:html("\
556   ECLiPSe structure notation provides a way to use structures with
557   field names rather than positional arguments.  Note that this is
558   not a new data type, just a new syntax for normal compound terms. 
559   It is intended to make programs more readable and easier to modify,
560   without compromising efficiency (it is implemented by macro
561   expansion). 
562<P>
563   E.g. if a structure is declared by specifying the prototype
564<PRE>
565	book(author, title, year, publisher)
566</PRE>
567    then subsequently book/4-terms can be written as follows:
568<PRE>
569	book{}
570	book{title:'tom sawyer'}
571	book{year:1886, title:'tom sawyer'}
572</PRE>
573    which will be completely equivalent to the usual
574<PRE>
575	book(_, _, _, _)
576	book(_, 'tom sawyer', _, _)
577	book(_, 'tom sawyer', 1886, _)
578</PRE>
579    The advantage is that the order and position of the fields or the
580    arity of the whole structure do not have to be known and can be
581    changed by just changing the initial declaration.
582<P>
583    The argument index of a field in a structure can be obtained using
584    a term of the form
585<PRE>
586	FieldName of StructName
587</PRE>
588    so instead of arg(3,B,Y) one can write
589<PRE>
590	arg(year of book, B, Y)
591</PRE>
592<P>
593    The arity of the structure can be obtained using a term of the
594    following form
595<PRE>
596        property(arity) of StructName
597</PRE>
598    instead of having to explicitly give the arity of the structure.  So, 
599<PRE>
600        property(arity) of book
601</PRE>
602    would be equivalent to the integer 4.  Similarly, a Name/Arity
603    specification can be obtained by writing
604<PRE>
605        property(functor) of StructName
606</PRE>
607    so book/4 can alternatively be written as
608<PRE>
609        property(functor) of book
610</PRE>
611
612<P>
613    Structures can also be declared to contain other structures, e.g.
614<PRE>
615	:- local struct(film(based_on:book,director,year)).
616</PRE>
617    This allows the fields of book to be accessed as if they were
618    fields of film. Note that the declaration of the year-field in
619    the film-structure hides the year-field in the book structure.
620"),
621	args:["Prototype" : "A structure with ground arguments."],
622	exceptions:[4 : "Struct is not ground.", 5 : "Struct is neither variable nor structure."],
623	eg:"
624% A simple structure:
625
626    [eclipse 1]: local struct(person(name,address,age)).
627
628    yes.
629    [eclipse 2]: John = person{age:30, name:john},
630            John = person{age:A},
631            arg(name of person, John, N).
632
633    John = person(john, _146, 30)
634    A = 30
635    N = john
636    yes.
637
638    [eclipse 3]: N is (property(arity) of person) + 1.
639    N = 4
640    yes.
641
642    [eclipse 4]: PersonStructure = (property(functor) of person).
643    PersonStructure = person / 3
644    yes.
645
646% Example for structure inheritance:
647
648    [eclipse 4]: local struct(employee(p:person,salary)).
649
650    yes.
651    [eclipse 5]: Emp = employee{name:john,salary:2000}.
652
653    Emp = employee(person(john, _105, _106), 2000)
654    yes.
655    
656    [eclipse 6]: Emp = employee{name:john, salary:2000},
657            Emp = employee{p:Person, salary:S},
658            arg(name of employee, Emp, N).
659
660    Person = person(john, _169, _170)
661    S = 2000
662    Emp = employee(person(john, _169, _170), 2000)
663    N = john
664    yes.
665
666
667% Subscript syntax can be used with structures:
668
669    [eclipse 7]: Emp = employee{name:john, salary:2000},
670             Cost is 5 * Emp[salary of employee].
671
672     Cost = 10000
673     Emp = employee(person(john, _137, _138), 2000)
674     yes.
675",
676	see_also:[(local) / 1, (export) / 1, current_struct / 2, arg / 3, subscript / 3, update_struct/4]]).
677
678:- comment(current_op / 3, [
679	summary:"Succeeds if Name is a visible operator with precedence Precedence and
680associativity Associativity.
681
682",
683	amode:(current_op(-,-,-) is nondet),
684	desc:html("   Used to check for the existence of a visible operator of precedence
685   Precedence with name Name and associativity Associativity.  Alternative
686   solutions are returned on backtracking.
687
688<P>
689   Precedence is an integer in the range 1 to 1200.
690
691<P>
692   Associativity is one of the atoms
693
694<P>
695<PRE>
696   xfx, xfy, yfx, fx, fy, xf, yf, fxx, fxy.
697</PRE>
698"),
699	args:["Precedence" : "Integer or variable.", "Associativity" : "Atom or variable.", "Name" : "Atom or variable."],
700	exceptions:[5 : "Precedence is not an integer.", 5 : "Associativity is not one of the above atoms.", 5 : "Name is instantiated but not to an atom.", 6 : "Precedence is not in the range 0 to 1200."],
701	eg:"
702Success:
703   current_op(300, fx, *).
704
705   [eclipse]: current_op(P, A, +).
706   P = 500
707   A = fx     More? (;)
708   P = 500
709   A = yfx     More? (;)   % RETURN pressed
710   yes.
711
712Fail:
713   current_op(10, fx, noop).
714
715Error:
716   current_op(prec, fx, +).             (Error 5).
717   current_op(100, fff, +).             (Error 5).
718   current_op(100, fx, bad(op)).        (Error 5).
719   current_op(-1, fx, +).               (Error 6).
720
721
722
723",
724	see_also:[op / 3]]).
725
726:- comment(get_chtab / 2, [
727	summary:"Succeeds if the lexical class of character Char is Class.
728
729",
730	amode:(get_chtab(+,-) is det),
731	desc:html("   Retrieves or checks the lexical class of a given character.
732
733<P>
734   Class is unified with the current lexical character class of Char.
735
736<P>
737   Char must be an integer in the range 0 to 255 (an escaped ASCII code is
738   also acceptable, eg 0'a = 98).
739
740<P>
741   The following table lists the character classes and the corresponding
742   default characters:
743
744<P>
745<PRE>
746 Class          Default member characters
747---------------------------------------------------------
748 upper_case     all upper case letters
749 underline      _
750 lower_case     all lower case letters
751 digit          digits
752 blank_space    space, tab and nonprintable characters
753 end_of_line    newline (NL)
754 atom_quote     '
755 string_quote   \"
756 list_quote
757 chars_quote
758 radix
759 ascii
760 solo           ! ;
761 special        ( [ { ) ] } , |
762 line_comment   %
763 escape         \\
764 first_comment  /
765 second_comment *
766 symbol         # + - . : &lt; = &gt; ? @ ^ ` ~ &amp; $
767 terminator
768</PRE>
769"),
770	args:["Char" : "Integer in the range 0 to 255.", "Class" : "Atom giving class name or variable."],
771	exceptions:[4 : "Char in not instantiated.", 5 : "Char is not an ASCII code.", 6 : "Char is not in the range 0 to 255."],
772	eg:"
773Success:
774   [eclipse]: get_chtab(0'a,X).
775
776   X = lower_case
777   yes.
778   [eclipse]: get_chtab(60,X).
779
780   X = symbol
781   yes.
782   [eclipse]:
783
784Fail:
785   get_chtab(98,symbol).
786   get_chtab(98,blah).
787
788Error
789   get_chtab(X,lower_case).     (Error 4).
790   get_chtab(\"a\",X).            (Error 5).
791   get_chtab(-1,X).             (Error 6).
792
793
794
795",
796	see_also:[set_chtab / 2, read_token / 2, read_token / 3]]).
797
798:- comment(set_chtab / 2, [
799	summary:"Sets the lexical class of character Char to class Class, this provides an
800interface to ECLiPSe 's lexical analyser.
801
802",
803	index:["chtab"],
804	amode:(set_chtab(+,+) is det),
805	desc:html("   Changes the lexical class of a given character.  This is especially
806   useful for implementing compatibility packages.  The possible character
807   classes which a character may have been given are shown below.
808
809<P>
810Note
811   It is not recommended to change the class of the special characters,
812   since in some cases it might make it impossible to correctly parse
813   Prolog terms.
814
815<P>
816   The following table lists the character classes and the default
817   corresponding characters:
818
819<P>
820<PRE>
821 Class          Default member characters
822---------------------------------------------------------
823 upper_case     all upper case letters
824 underline      _
825 lower_case     all lower case letters
826 digit          digits
827 blank_space    space, tab and nonprintable characters
828 end_of_line    newline (NL)
829 atom_quote     '
830 string_quote   \"
831 list_quote
832 chars_quote
833 radix
834 ascii
835 solo           ! ;
836 special        ( [ { ) ] } , |
837 line_comment   %
838 escape         \\
839 first_comment  /
840 second_comment *
841 symbol         # + - . : &lt; = &gt; ? @ ^ ` ~ &amp; $
842 terminator
843</PRE>
844"),
845	args:["Char" : "Integer in range 0 to 255.", "Class" : "Atom indicating the character class."],
846	exceptions:[4 : "Char and/or Class are not instantiated.", 5 : "Char is not an integer in the range 0 to 255.", 6 : "Class is not a valid lexical class."],
847	eg:"
848Success:
849   % The following example illustrates the use
850   % of set_chtab/2 to redefine the class of the
851   % dollar symbol.
852   %
853   [eclipse]: X = $a.
854                 ^ (here?)
855   syntax error: postfix/infix operator expected
856   [eclipse]: set_chtab(0'$, lower_case).
857
858   yes.
859   [eclipse]: X = $a.
860
861   X = $a
862   yes.
863   [eclipse]:
864
865Error:
866   set_chtab(\"a\",symbol).       (Error 5)
867   set_chtab(97,fred).          (Error 6)
868
869
870
871
872",
873	see_also:[(local)/1, get_chtab / 2, read_token / 2, read_token / 3]]).
874
875:- comment(erase_macro / 2, [
876	summary:"Erases the macro definition for TransTerm done in the current module
877
878",
879	amode:(erase_macro(+,++) is det),
880	desc:html("   The macro defined for TransTerm and matching the specified Options
881   is erased.  If there was no matching macro definition, the predicate
882   silently succeeds. See macro/3 and portray/3 for the valid options.
883
884<P>
885"),
886	args:["TransTerm" : "Term in the form Atom/Integer.", "Options" : "Possibly empty list of option flags."],
887	exceptions:[4 : "TransTerm is not instantiated or Options is not fully instantiated.", 5 : "TransTerm not of form Atom/Integer or Options is not a list of atoms.", 6 : "Options contains an element which is not a valid option."],
888	eg:"
889   Success:
890   erase_macro(a/1, [read]).
891   erase_macro(a/1, [write,goal]).
892   Error:
893   erase_macro(X, []).           (Error 4).
894   erase_macro(a, [write]).      (Error 5).
895   erase_macro(a/1, [hello]).    (Error 6).
896
897
898
899",
900	see_also:[current_macro / 4, macro / 3, portray/3, phrase / 3]]).
901