1 /* Copyright Vladimir Prus 2003. Distributed under the Boost */
2 /* Software License, Version 1.0. (See accompanying */
3 /* file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) */
4
5 #include "../native.h"
6 #include "../object.h"
7
8 /*
9 local result = ;
10 local element ;
11 for element in $(B)
12 {
13 if ! ( $(element) in $(A) )
14 {
15 result += $(element) ;
16 }
17 }
18 return $(result) ;
19 */
set_difference(FRAME * frame,int flags)20 LIST *set_difference( FRAME *frame, int flags )
21 {
22
23 LIST* b = lol_get( frame->args, 0 );
24 LIST* a = lol_get( frame->args, 1 );
25
26 LIST* result = L0;
27 LISTITER iter = list_begin( b ), end = list_end( b );
28 for( ; iter != end; iter = list_next( iter ) )
29 {
30 if (!list_in(a, list_item(iter)))
31 result = list_push_back(result, object_copy(list_item(iter)));
32 }
33 return result;
34 }
35
init_set()36 void init_set()
37 {
38 {
39 const char* args[] = { "B", "*", ":", "A", "*", 0 };
40 declare_native_rule("set", "difference", args, set_difference, 1);
41 }
42
43 }
44