1 | % (c) 2019-2022 Lehrstuhl fuer Softwaretechnik und Programmiersprachen, | |
2 | % Heinrich Heine Universitaet Duesseldorf | |
3 | % This software is licenced under EPL 1.0 (http://www.eclipse.org/org/documents/epl-v10.html) | |
4 | ||
5 | :- module(kernel_lists,[ not_element_of_list_wf/3 | |
6 | %, element_of_list_wf/4 % code not used | |
7 | ]). | |
8 | ||
9 | :- use_module(module_information,[module_info/2]). | |
10 | :- module_info(group,kernel). | |
11 | :- module_info(description,'This module provides operations for lists of B objects.'). | |
12 | % with possible repetitions, as, e.g., for set_extensions | |
13 | ||
14 | :- use_module(kernel_objects,[not_equal_object_wf/3]). | |
15 | :- use_module(error_manager). | |
16 | ||
17 | not_element_of_list_wf(Element,List,WF) :- not_el_wf(List,Element,WF). | |
18 | ||
19 | :- block not_el_wf(-,?,?). | |
20 | not_el_wf([],_,_WF) :- !. | |
21 | not_el_wf([H|T],X,WF) :- !, | |
22 | not_equal_object_wf(H,X,WF), | |
23 | not_el_wf(T,X,WF). | |
24 | not_el_wf(Other,X,WF) :- | |
25 | add_internal_error('Not a list: ',not_el_wf(Other,X,WF)),fail. | |
26 | ||
27 | % Questions: does it make sense to call clpfd_interface:clpfd_not_inlist ? | |
28 | ||
29 | ||
30 | ||
31 | % test code below with: i1=1 & j1:0..6 & mid1:0..7 & mid2 : {mid1/2, mid1} | |
32 | % code not used at the moment, so commented out | |
33 | ||
34 | /* | |
35 | :- use_module(kernel_mappings,[kernel_call/4,kernel_call_predicate_check_element_of_wf/4]). | |
36 | :- use_module(clpfd_lists,[try_in_fd_value_list_check/4]). | |
37 | :- use_module(preferences,[get_preference/2]). | |
38 | ||
39 | element_of_list_wf(ElementVal,TypeOfElement,List,WF) :- | |
40 | % temporary solution: use code from interpreter to evaluate set_extension: | |
41 | kernel_call(b_interpreter:convert_list_of_expressions_into_set_wf(List,ValueSet,set(TypeOfElement),WF), | |
42 | List,WF, set_extension(List)), % do we need real AST Expression ? List contains values | |
43 | % temporary solution: use check_element_of_wf; to do: use custom version just for lists | |
44 | kernel_call_predicate_check_element_of_wf(ElementVal,ValueSet,WF,unknown), | |
45 | %print_term_summary(prop(ExValue,ElementVal,WF)),nl, | |
46 | % TO DO: avoid calling check_element_of version when CLPFD complete check possible | |
47 | (get_preference(use_clpfd_solver,false) -> true | |
48 | ; get_fd_type_from_b_type(TypeOfElement,FDType), | |
49 | try_in_fd_value_list_check(List,ElementVal,FDType,WF) | |
50 | % TO DO: provide cleaner API for this | |
51 | ), | |
52 | tools_printing:print_term_summary(finished_element_of_list_wf(ElementVal,List)),nl. | |
53 | ||
54 | get_fd_type_from_b_type(integer,T) :- !, T=integer. | |
55 | get_fd_type_from_b_type(global(G),T) :- !, T=global(G). | |
56 | get_fd_type_from_b_type(_,_). % otherwise type could be couple_left,... | |
57 | ||
58 | */ |