YAP 7.1.0
flags.yap
Go to the documentation of this file.
1%%% -*- Mode: Prolog; -*-
2
3/**
4 * @file library/flags.yap
5 * @author Theofrastos Mantadelis, Bernd Gutmann, Paulo Moura
6 * @date Tue Nov 17 15:18:02 2015
7 *
8 * @brief Flag Manipulation in Prolog
9 *
10 *
11*/
12
13%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
14%
15% Flags was developed at Katholieke Universiteit Leuven
16%
17% Copyright 2010
18% Katholieke Universiteit Leuven
19%
20% Contributions to this file:
21% Author: Theofrastos Mantadelis
22% Sugestions: Bernd Gutmann, Paulo Moura
23% $Date: 2011-02-15 13:33:01 +0100 (Tue, 15 Feb 2011) $
24% $Revision: 15 $
25%
26%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
27%
28% Artistic License 2.0
29%
30% Copyright (c) 2000-2006, The Perl Foundation.
31%
32% Everyone is permitted to copy and distribute verbatim copies of this
33% license document, but changing it is not allowed. Preamble
34%
35% This license establishes the terms under which a given free software
36% Package may be copied, modified, distributed, and/or
37% redistributed. The intent is that the Copyright Holder maintains some
38% artistic control over the development of that Package while still
39% keeping the Package available as open source and free software.
40%
41% You are always permitted to make arrangements wholly outside of this
42% license directly with the Copyright Holder of a given Package. If the
43% terms of this license do not permit the full use that you propose to
44% make of the Package, you should contact the Copyright Holder and seek
45% a different licensing arrangement. Definitions
46%
47% "Copyright Holder" means the individual(s) or organization(s) named in
48% the copyright notice for the entire Package.
49%
50% "Contributor" means any party that has contributed code or other
51% material to the Package, in accordance with the Copyright Holder's
52% procedures.
53%
54% "You" and "your" means any person who would like to copy, distribute,
55% or modify the Package.
56%
57% "Package" means the collection of files distributed by the Copyright
58% Holder, and derivatives of that collection and/or of those files. A
59% given Package may consist of either the Standard Version, or a
60% Modified Version.
61%
62% "Distribute" means providing a copy of the Package or making it
63% accessible to anyone else, or in the case of a company or
64% organization, to others outside of your company or organization.
65%
66% "Distributor Fee" means any fee that you charge for Distributing this
67% Package or providing support for this Package to another party. It
68% does not mean licensing fees.
69%
70% "Standard Version" refers to the Package if it has not been modified,
71% or has been modified only in ways explicitly requested by the
72% Copyright Holder.
73%
74% "Modified Version" means the Package, if it has been changed, and such
75% changes were not explicitly requested by the Copyright Holder.
76%
77% "Original License" means this Artistic License as Distributed with the
78% Standard Version of the Package, in its current version or as it may
79% be modified by The Perl Foundation in the future.
80%
81% "Source" form means the source code, documentation source, and
82% configuration files for the Package.
83%
84% "Compiled" form means the compiled bytecode, object code, binary, or
85% any other form resulting from mechanical transformation or translation
86% of the Source form.
87%
88%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
89%
90% Permission for Use and Modification Without Distribution
91%
92% (1) You are permitted to use the Standard Version and create and use
93% Modified Versions for any purpose without restriction, provided that
94% you do not Distribute the Modified Version.
95%
96% Permissions for Redistribution of the Standard Version
97%
98% (2) You may Distribute verbatim copies of the Source form of the
99% Standard Version of this Package in any medium without restriction,
100% either gratis or for a Distributor Fee, provided that you duplicate
101% all of the original copyright notices and associated disclaimers. At
102% your discretion, such verbatim copies may or may not include a
103% Compiled form of the Package.
104%
105% (3) You may apply any bug fixes, portability changes, and other
106% modifications made available from the Copyright Holder. The resulting
107% Package will still be considered the Standard Version, and as such
108% will be subject to the Original License.
109%
110% Distribution of Modified Versions of the Package as Source
111%
112% (4) You may Distribute your Modified Version as Source (either gratis
113% or for a Distributor Fee, and with or without a Compiled form of the
114% Modified Version) provided that you clearly document how it differs
115% from the Standard Version, including, but not limited to, documenting
116% any non-standard features, executables, or modules, and provided that
117% you do at least ONE of the following:
118%
119% (a) make the Modified Version available to the Copyright Holder of the
120% Standard Version, under the Original License, so that the Copyright
121% Holder may include your modifications in the Standard Version. (b)
122% ensure that installation of your Modified Version does not prevent the
123% user installing or running the Standard Version. In addition, the
124% modified Version must bear a name that is different from the name of
125% the Standard Version. (c) allow anyone who receives a copy of the
126% Modified Version to make the Source form of the Modified Version
127% available to others under (i) the Original License or (ii) a license
128% that permits the licensee to freely copy, modify and redistribute the
129% Modified Version using the same licensing terms that apply to the copy
130% that the licensee received, and requires that the Source form of the
131% Modified Version, and of any works derived from it, be made freely
132% available in that license fees are prohibited but Distributor Fees are
133% allowed.
134%
135% Distribution of Compiled Forms of the Standard Version or
136% Modified Versions without the Source
137%
138% (5) You may Distribute Compiled forms of the Standard Version without
139% the Source, provided that you include complete instructions on how to
140% get the Source of the Standard Version. Such instructions must be
141% valid at the time of your distribution. If these instructions, at any
142% time while you are carrying out such distribution, become invalid, you
143% must provide new instructions on demand or cease further
144% distribution. If you provide valid instructions or cease distribution
145% within thirty days after you become aware that the instructions are
146% invalid, then you do not forfeit any of your rights under this
147% license.
148%
149% (6) You may Distribute a Modified Version in Compiled form without the
150% Source, provided that you comply with Section 4 with respect to the
151% Source of the Modified Version.
152%
153% Aggregating or Linking the Package
154%
155% (7) You may aggregate the Package (either the Standard Version or
156% Modified Version) with other packages and Distribute the resulting
157% aggregation provided that you do not charge a licensing fee for the
158% Package. Distributor Fees are permitted, and licensing fees for other
159% components in the aggregation are permitted. The terms of this license
160% apply to the use and Distribution of the Standard or Modified Versions
161% as included in the aggregation.
162%
163% (8) You are permitted to link Modified and Standard Versions with
164% other works, to embed the Package in a larger work of your own, or to
165% build stand-alone binary or bytecode versions of applications that
166% include the Package, and Distribute the result without restriction,
167% provided the result does not expose a direct interface to the Package.
168%
169% Items That are Not Considered Part of a Modified Version
170%
171% (9) Works (including, but not limited to, modules and scripts) that
172% merely extend or make use of the Package, do not, by themselves, cause
173% the Package to be a Modified Version. In addition, such works are not
174% considered parts of the Package itself, and are not subject to the
175% terms of this license.
176%
177% General Provisions
178%
179% (10) Any use, modification, and distribution of the Standard or
180% Modified Versions is governed by this Artistic License. By using,
181% modifying or distributing the Package, you accept this license. Do not
182% use, modify, or distribute the Package, if you do not accept this
183% license.
184%
185% (11) If your Modified Version has been derived from a Modified Version
186% made by someone other than you, you are nevertheless required to
187% ensure that your Modified Version complies with the requirements of
188% this license.
189%
190% (12) This license does not grant you the right to use any trademark,
191% service mark, tradename, or logo of the Copyright Holder.
192%
193% (13) This license includes the non-exclusive, worldwide,
194% free-of-charge patent license to make, have made, use, offer to sell,
195% sell, import and otherwise transfer the Package with respect to any
196% patent claims licensable by the Copyright Holder that are necessarily
197% infringed by the Package. If you institute patent litigation
198% (including a cross-claim or counterclaim) against any party alleging
199% that the Package constitutes direct or contributory patent
200% infringement, then this Artistic License to you shall terminate on the
201% date that such litigation is filed.
202%
203% (14) Disclaimer of Warranty: THE PACKAGE IS PROVIDED BY THE COPYRIGHT
204% HOLDER AND CONTRIBUTORS "AS IS' AND WITHOUT ANY EXPRESS OR IMPLIED
205% WARRANTIES. THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
206% PARTICULAR PURPOSE, OR NON-INFRINGEMENT ARE DISCLAIMED TO THE EXTENT
207% PERMITTED BY YOUR LOCAL LAW. UNLESS REQUIRED BY LAW, NO COPYRIGHT
208% HOLDER OR CONTRIBUTOR WILL BE LIABLE FOR ANY DIRECT, INDIRECT,
209% INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING IN ANY WAY OUT OF THE USE
210% OF THE PACKAGE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
211%
212%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
213
214
215:- flag_define/2flag_define/5flag_define/7flag_set/2flag_set/3flag_unsafe_set/2flag_get/2flags_reset/0flags_reset/1flags_save/1flags_load/1flag_groups/1flag_group_chk/1flag_help/0flags_print/0defined_flag/7module(flags, [,
216 ,
217 ,
218 ,
219 ,
220 ,
221 ,
222 ,
223 ,
224 ,
225 ,
226 ,
227 ,
228 ,
229 ,
230 ]).
231
232/**
233* @defgroup flags Flag Manipulation in Prolog
234* @ingroup YAPLibrary
235*
236* Routines to manipulate flags: they allow defining, set,
237* resetting.
238* @{
239*/
240
241
242:- append/3memberchk/2member/2use_module(library(lists), [, , ]).
243
244:- style_check(all).
245:- yap_flag(unknown, error).
246
247:- '$defined_flag$'/7'$store_flag_value$'/2dynamic([, ]).
248:- meta_predicate(flag_define(+, +, +, ?, ?, ?, :)).
249:- meta_predicate(flag_define(+, :)).
250:- meta_predicate(validate(+, :, ?, +)).
252
253flag_define(FlagName, InputOptions):-
254 strip_module(InputOptions, Module, UserOptions),
255 Defaults = [flag_group(general), flag_type(nonvar), default_value(true), description(FlagName), access(read_write), handler(true)],
256 append(UserOptions, Defaults, Options),
257 memberchk(flag_group(FlagGroup), Options),
258 memberchk(flag_type(FlagType), Options),
259 memberchk(default_value(DefaultValue), Options),
260 memberchk(description(Description), Options),
261 memberchk(access(Access), Options),
262 memberchk(handler(Handler), Options),
263 flag_define(FlagName, FlagGroup, FlagType, DefaultValue, Description, Access, Module:Handler).
264
265flag_define(FlagName, FlagGroup, FlagType, DefaultValue, Description):-
266 flag_define(FlagName, FlagGroup, FlagType, DefaultValue, Description, read_write, true).
267
268flag_define(FlagName, FlagGroup, FlagType, DefaultValue, Description, Access, MHandler):-
269 strip_module(MHandler, Module, Handler),
270 nonvar(FlagName),
271 nonvar(FlagGroup),
272 nonvar(FlagType),
273 nonvar(Access),
274 nonvar(Handler), nonvar,
275 (\+ atom(FlagName) ->
276 throw(error(type_error(atom, FlagName), message('Flag name needs to be an atom.', flag_define(FlagName, FlagGroup, FlagType, DefaultValue, Description, Access, Module:Handler))))
277 ; \+ atom(FlagGroup) ->
278 throw(error(type_error(atom, FlagGroup), message('Flag group needs to be an atom.', flag_define(FlagName, FlagGroup, FlagType, DefaultValue, Description, Access, Module:Handler))))
279 ; \+ flag_type(FlagType) ->
280 throw(error(domain_error(flag_type, FlagType), message('Unknown flag type.', flag_define(FlagName, FlagGroup, FlagType, DefaultValue, Description, Module:Handler))))
281 ; \+ validate_type(FlagType) ->
282 throw(error(evaluation_error(type_validation), message('Validation of flag type failed, check custom domain.', flag_define(FlagName, FlagGroup, FlagType, DefaultValue, Description, Access, Module:Handler))))
283 ; '$defined_flag$'(FlagName, _FlagGroup, _FlagType, _DefaultValue, _Description, _Access, _Handler) ->
284 throw(error(permission_error(create, flag, FlagName), message('Re-defining a flag is not allowed.', flag_define(FlagName, FlagGroup, FlagType, DefaultValue, Description, Access, Module:Handler))))
285 ; \+ memberchk(Access, [read_write, read_only, hidden, hidden_read_only]),
286 throw(error(domain_error(access, Access), message('Wrong access attribute, available are: read_write, read_only, hidden, hidden_read_only.', flag_define(FlagName, FlagGroup, FlagType, DefaultValue, Description, Access, Module:Handler))))
287 ; \+ callable(Handler) -> % the Handler comes from: strip_module(MHandler, Module, Handler)
288 throw(error(type_error(callable, Handler), message('Flag handler needs to be callable.', flag_define(FlagName, FlagGroup, FlagType, DefaultValue, Description, Access, Module:Handler))))
289 ;
290 validate(FlagType, Module:Handler, DefaultValue, FlagName),
291 assertz('$defined_flag$'(FlagName, FlagGroup, FlagType, DefaultValue, Description, Access, Module:Handler)),
292 assertz('$store_flag_value$'(FlagName, DefaultValue)),
293 (Handler == true ->
294 true
295 ;
296 call(Module:Handler, stored, DefaultValue)
297 )
298 ).
299flag_define(FlagName, FlagGroup, FlagType, DefaultValue, Description, Access, Handler):-
300 throw(error(instantiation_error, message('Flag name, group, type, access and handler need to be instantiated.', flag_define(FlagName, FlagGroup, FlagType, DefaultValue, Description, Access, Handler)))).
301
302flag_groups(FlagGroups):-
303 all(FlagGroup, ('$defined_flag$'(_FlagName, FlagGroup, _FlagType, _DefaultValue, _Description, Access, _Handler), Access \== hidden, Access \== hidden_read_only), FlagGroups).
304
305flag_group_chk(FlagGroup):-
306 nonvar(FlagGroup),
307 '$defined_flag$'(_FlagName, FlagGroup, _FlagType, _DefaultValue, _Description, _Access, _Handler), '$defined_flag$'.
308
309flag_type(Type):-
310 flags_type_definition(Type, _, _).
311
312%% @pred flags_type_definition(TypeName, TypeHandler, TypeValidator).
313flags_type_definition(nonvar, nonvar, true).
314flags_type_definition(atom, atom, true).
315flags_type_definition(atomic, atomic, true).
316flags_type_definition(integer, integer, true).
317flags_type_definition(float, float, true).
318flags_type_definition(number, number, true).
319flags_type_definition(ground, ground, true).
320flags_type_definition(compound, compound, true).
321flags_type_definition(is_list, is_list, true).
322flags_type_definition(callable, callable, true).
323flags_type_definition(in_interval(Type, Interval), in_interval(Type, Interval), in_interval(Type, Interval)).
324flags_type_definition(integer_in_interval(Interval), in_interval(integer, Interval), in_interval(integer, Interval)).
325flags_type_definition(positive_integer, in_interval(integer, (0, (+inf))), true).
326flags_type_definition(non_negative_integer, in_interval(integer, ([0], (+inf))), true).
327flags_type_definition(negative_integer, in_interval(integer, ((-inf), 0)), true).
328flags_type_definition(float_in_interval(Interval), in_interval(float, Interval), in_interval(float, Interval)).
329flags_type_definition(positive_float, in_interval(float, (0.0, (+inf))), true).
330flags_type_definition(non_negative_float, in_interval(float, ([0.0], (+inf))), true).
331flags_type_definition(negative_float, in_interval(float, ((-inf), 0.0)), true).
332flags_type_definition(number_in_interval(Interval), in_interval(number, Interval), in_interval(number, Interval)).
333flags_type_definition(positive_number, in_interval(number, (0.0, (+inf))), true).
334flags_type_definition(non_negative_number, in_interval(number, ([0.0], (+inf))), true).
335flags_type_definition(negative_number, in_interval(number, ((-inf), 0.0)), true).
336flags_type_definition(in_domain(Domain), in_domain(Domain), in_domain(Domain)).
337flags_type_definition(boolean, in_domain([true, false]), true).
338flags_type_definition(switch, in_domain([on, off]), true).
339
340in_domain(Domain):-
341 ground(Domain),
342 is_list(Domain).
343in_domain(Domain, Value):-
344 ground(Value),
345 memberchk(Value, Domain).
346
347in_interval(Type, Interval):-
348 is_list(Interval), is_list,
349 Interval \== [],
350 in_interval_conj(Type, Interval).
351in_interval(Type, Interval):-
352 in_interval_single(Type, Interval).
353
354in_interval_conj(_Type, []).
355in_interval_conj(Type, [Interval|Rest]):-
356 in_interval_single(Type, Interval),
357 in_interval_conj(Type, Rest).
358
359in_interval_single(Type, ([Min], [Max])):-
360 in_interval_single, call(Type, Min),
361 call(Type, Max),
362 Min =< Max.
363
364in_interval_single(Type, ([Min], Max)):-
365 in_interval_single, call(Type, Min),
366 type_or_inf(Type, Max),
367 Min < Max.
368
369in_interval_single(Type, (Min, [Max])):-
370 in_interval_single, type_or_inf(Type, Min),
371 call(Type, Max),
372 Min < Max.
373
374in_interval_single(Type, (Min, Max)):-
375 type_or_inf(Type, Min),
376 type_or_inf(Type, Max),
377 Min < Max,
378 Max - Min > 0.0.
379
380type_or_inf(Type, Value):-
381 nonvar(Type), nonvar(Value),
382 Value == (+inf), .
383type_or_inf(Type, Value):-
384 nonvar(Type), nonvar(Value),
385 Value == (-inf), .
386type_or_inf(Type, Value):- call(Type, Value).
387
388in_interval(Type, [Interval|_Rest], Value):-
389 in_interval(Type, Interval, Value), in_interval.
390in_interval(Type, [_Interval|Rest], Value):-
391 in_interval(Type, Rest, Value).
392
393in_interval(Type, ([Min], [Max]), Value):-
394 in_interval, call(Type, Value),
395 Value >= Min,
396 Value =< Max.
397
398in_interval(Type, ([Min], Max), Value):-
399 in_interval, call(Type, Value),
400 Value >= Min,
401 Value < Max.
402
403in_interval(Type, (Min, [Max]), Value):-
404 in_interval, call(Type, Value),
405 Value > Min,
406 Value =< Max.
407
408in_interval(Type, (Min, Max), Value):-
409 call(Type, Value),
410 Value > Min,
411 Value < Max.
412
413validate_type(Type):-
414 flags_type_definition(Type, _, TypeValidater),
415 call(TypeValidater).
416
417validate(FlagType, Handler, Value, FlagName):-
418 strip_module(Handler, _Module, true),
419 strip_module, flags_type_definition(FlagType, FlagValidator, _),
420 (call(FlagValidator, Value) ->
421 call
422 ;
423 throw(error(validation_error(FlagType, Value), message('Validation of value fails.', validate(FlagType, Value, FlagName))))
424 ).
425validate(FlagType, Handler, Value, FlagName):-
426 flags_type_definition(FlagType, FlagValidator, _),
427 ((call(Handler, validating, Value), (call(FlagValidator, Value); call(Handler, validate, Value))) ->
428 call(Handler, validated, Value)
429 ;
430 throw(error(validation_error(FlagType, Value), message('Validation of value fails.', validate(FlagType, Handler, Value, FlagName))))
431 ).
432
433flag_set(FlagName, FlagValue):-
434 flag_set(FlagName, _OldValue, FlagValue).
435flag_set(FlagName, OldValue, FlagValue):-
436 atom(FlagName),
437 '$defined_flag$'(FlagName, _FlagGroup, FlagType, _DefaultValue, _Description, Access, Module:Handler), '$defined_flag$',
438 (Access \== read_only, Access \== hidden_read_only ->
439 validate(FlagType, Module:Handler, FlagValue, FlagName),
440 retract('$store_flag_value$'(FlagName, OldValue)),
441 assertz('$store_flag_value$'(FlagName, FlagValue)),
442 (Handler == true ->
443 true
444 ;
445 call(Module:Handler, stored, FlagValue)
446 )
447 ;
448 throw(error(permission_error(set, flag, FlagName), message('Setting the flag value is not allowed.',flag_set(FlagName, OldValue, FlagValue))))
449 ).
450flag_set(FlagName, OldValue, FlagValue):-
451 throw(error(existence_error(flag, FlagName), message('The flag is not defined.', flag_set(FlagName, OldValue, FlagValue)))).
452
453flag_unsafe_set(FlagName, FlagValue):-
454 retract('$store_flag_value$'(FlagName, _)),
455 assertz('$store_flag_value$'(FlagName, FlagValue)).
456
457flag_get(FlagName, FlagValue):-
458 \+ '$store_flag_value$'(FlagName, _),
459 throw(error(existence_error(flag, FlagName), message('The flag is not defined.', flag_get(FlagName, FlagValue)))).
460flag_get(FlagName, FlagValue):-
461 '$store_flag_value$'(FlagName, FlagValue).
462
463'$store_flag_value$':-
464 retractall('$store_flag_value$'(_, _)),
465 '$defined_flag$'(FlagName, _FlagGroup, _FlagType, DefaultValue, _Description, _Access, Module:Handler),
466 assertz('$store_flag_value$'(FlagName, DefaultValue)),
467 (Handler == true ->
468 true
469 ;
470 call(Module:Handler, stored, DefaultValue)
471 ),
472 fail.
473flags_reset.
474
475flags_reset(FlagGroup):-
476 '$defined_flag$'(FlagName, FlagGroup, _FlagType, DefaultValue, _Description, _Access, Module:Handler),
477 retractall('$store_flag_value$'(FlagName, _)),
478 assertz('$store_flag_value$'(FlagName, DefaultValue)),
479 (Handler == true ->
480 true
481 ;
482 call(Module:Handler, stored, DefaultValue)
483 ),
484 fail.
485flags_reset(_).
486
487flags_save(FileName):-
488 tell(FileName),
489 catch(('$store_flag_value$'(FlagName, Value),
490 write_canonical('$store_flag_value$'(FlagName, Value)),
491 write('.'), nl),
492 Exception, clean_and_throw(told, Exception)),
493 catch.
494flags_save(_FileName):-
495 flags_save.
496
497flags_load(FileName):-
498 see(FileName),
499 catch((read('$store_flag_value$'(FlagName, Value)),
500 flag_set(FlagName, Value)),
501 Exception, clean_and_throw(seen, Exception)),
502 catch.
503flags_load(_FileName):-
504 flags_load.
505
506clean_and_throw(Action, Exception):-
507 Action,
508 throw(Exception).
509
510throw:-
511 format('This is a short tutorial for the flags library.~nExported predicates:~n'),
512 format(' flag_define/5 : defines a new flag without a handler~n'),
513 format(' flag_define(FlagName, FlagGroup, FlagType, DefaultValue, Description)~n'),
514 format(' flag_define/6 : defines a new flag with a handler~n'),
515 format(' flag_define(FlagName, FlagGroup, FlagType, DefaultValue, Description, Handler)~n'),
516 format(' FlagName : the name of the flag~n'),
517 format(' FlagGroup : the name of the flag group~n'),
518 format(' FlagType : the type of the flag available types are:~n'),
519 format,
520 format(' DefaultValue : the default value for the flag~n'),
521 format(' Description : a flag description~n'),
522 format(' Handler : a handler~n'),
523 format:format,
524 format(' flag_groups/1 : returns all the flag groups in a list~n'),
525 format(' flag_group_chk/1 : checks if a group exists~n'),
526 format(' flag_set/2 : sets the value of a flag~n'),
527 format(' flag_get/2 : gets the value of a flag~n'),
528 format(' flag_store/2 : sets the value of a flag ignoring all tests and handlers~n'),
529 format(' flag_reset/0 : resets all flags to their default value~n'),
530 format(' flag_reset/1 : resets all flags of a group to their default value~n'),
531 format(' flag_help/0 : this screen~n'),
532 format(' flags_print/0 : shows the current flags/values~n').
533format:-
534 flag_type(FlagType),
535 format(' ~w~n', [FlagType]),
536 format.
537format.
538
539format:-
540 format(' Handler important notes:~n'),
541 format(' Conjuction: external_handler(validating, Value):-...~n'),
542 format(' Disjunction: external_handler(validate, Value):-...~n'),
543 format(' After: external_handler(validated, Value):-...~n'),
544 format(' After set: external_handler(stored, Value):-...~n'),
545 format(' this is implemented as (validating,(original;validated))~n'),
546 format(' validating|original|validate|result~n'),
547 format(' true | true | true | true~n'),
548 format(' true | true | fail | true~n'),
549 format(' true | fail | true | true~n'),
550 format(' true | fail | fail | fail~n'),
551 format(' fail | true | true | fail~n'),
552 format(' fail | true | fail | fail~n'),
553 format(' fail | fail | true | fail~n'),
554 format(' fail | fail | fail | fail~n'),
555 format(' Default behaviour is validating->true, validate->fail~n'),
556 format(' To completly replace original set validate->true~n'),
557 format(' To add new values to original set validating->true~n'),
558 format(' To remove values from original set validate->fail~n'),
559 format(' Example definition with a handler:~n'),
560 format(' flag_define(myflag, mygroup, in_interval(integer, [(-5, 5),([15],[25])]), 0, description, my_handler).~n'),
561 format(' my_handler(validate, Value):-Value is 10.~n'),
562 format(' my_handler(validating, Value).~n'),
563 format(' my_handler(validated, Value).~n'),
564 format(' my_handler(stored, Value).~n'),
565 format(' This has defined a flag that accepts integers (-5,5)v[15,25].~n'),
566 format(' The handler adds the value 10 in those.~n').
567
568format:-
569 flag_groups(Groups),
570 forall(member(Group, Groups), flags_print(Group)).
571flags_print(Group):-
572 format(' ~w:~n~w~38+ ~w~19+ ~w~10+ ~w~10+~n', [Group, 'Description', 'Domain', 'Flag', 'Value']),
573 format.
574flags_print(FlagGroup):-
575 '$defined_flag$'(FlagName, FlagGroup, FlagType, _DefaultValue, Description, Access, _Handler),
576 Access \== '$defined_flag$', Access \== '$defined_flag$',
577 flag_get(FlagName, Value),
578 format('~w~38+ ~w~19+ ~w~10+ ~q~10+~n', [Description, FlagType, FlagName, Value]),
579 format.
580flags_print(_).
581
582defined_flag(FlagName, FlagGroup, FlagType, DefaultValue, Description, Access, Handler):-
583 '$defined_flag$'(FlagName, FlagGroup, FlagType, DefaultValue, Description, Access, Handler),
584 Access \== '$defined_flag$', Access \== '$defined_flag$'.
585defined_flag(FlagName, FlagGroup, FlagType, DefaultValue, Description, Access, Handler):-
586 nonvar(FlagName), nonvar(FlagGroup),
587 '$defined_flag$'(FlagName, FlagGroup, FlagType, DefaultValue, Description, Access, Handler).
588
589%% @}
590
callable( ?_Goal_ )
catch( : Goal,+ Exception,+ Action)
format(+ T)
is_list( ?_List_ )
module(+M)
see(+ S)
tell(+ S)
Definition: edio.yap:70
throw(+ Ball)
yap_flag( ?Param, ?Value)
assertz(+ C)
retract(+ C)
retractall(+ G)
format(+ T, :L)
use_module( +Files )
all( T,+ G,- L)
call( 0:P )
forall(: Cond,: Action)
dynamic( + P )
multifile( P )
ground( T)
atom( T)
nonvar( T)
flags_type_definition(TypeName, TypeHandler, TypeValidator)
append(? List1,? List2,? List3)
member(?Element, ?Set) is true when Set is a list, and Element occurs in it
memberchk(+ Element, + Set)