@result{}echo foo
@result{}echo bar, baz
@end example
+
+Note that for some forms of @var{expression}, it may be faster to use
+@code{m4_map_args}.
@end defmac
@anchor{m4_foreach_w}
in any way other than removing the element currently contained in
@var{variable}. This macro is faster than the corresponding
@code{m4_foreach([@var{variable}],
-m4_indir([m4_dquote]m4_set_listc([@var{set}])), [@var{action}])}.
+m4_indir([m4_dquote]m4_set_listc([@var{set}])), [@var{action}])},
+although @code{m4_set_map} might be faster still.
@example
m4_set_add_all([a]m4_for([i], [1], [5], [], [,i]))
argument of the set element. Behavior is unspecified if @var{action}
recursively lists the contents of @var{set} (although listing other sets
is acceptable), or if it modifies the set in any way other than removing
-the element passed as an argument. This macro is faster than the
-corresponding
-@code{m4_map_args([@var{action}]m4_set_listc([@var{set}]))}.
+the element passed as an argument. This macro is faster than either
+corresponding counterpart of
+@code{m4_map_args([@var{action}]m4_set_listc([@var{set}]))} or
+@code{m4_set_foreach([@var{set}], [var],
+[@var{action}(m4_defn([var]))])}.
@end defmac
@defmac m4_set_remove (@var{set}, @var{value}, @ovar{if-present}, @
# arguments, such as for m4_join, or wrapped inside quotes for use in
# m4_foreach. Order of the output is not guaranteed.
#
-# Short-circuit the idempotence relation. Use _m4_defn for speed.
+# Short-circuit the idempotence relation.
m4_define([m4_set_difference],
-[m4_if([$1], [$2], [],
- [m4_set_foreach([$1], [_m4_element],
- [m4_set_contains([$2], _m4_defn([_m4_element]), [],
- [,_m4_defn([_m4_element])])])])])
+[m4_if([$1], [$2], [], [m4_set_map_sep([$1], [_$0([$2],], [)])])])
+
+m4_define([_m4_set_difference],
+[m4_set_contains([$1], [$2], [], [,[$2]])])
# m4_set_dump(SET, [SEP])
# -----------------------
# m4_foreach. Order of the output is not guaranteed.
#
# Iterate over the smaller set, and short-circuit the idempotence
-# relation. Use _m4_defn for speed.
+# relation.
m4_define([m4_set_intersection],
[m4_if([$1], [$2], [m4_set_listc([$1])],
m4_eval(m4_set_size([$2]) < m4_set_size([$1])), [1], [$0([$2], [$1])],
- [m4_set_foreach([$1], [_m4_element],
- [m4_set_contains([$2], _m4_defn([_m4_element]),
- [,_m4_defn([_m4_element])])])])])
+ [m4_set_map_sep([$1], [_$0([$2],], [)])])])
+
+m4_define([_m4_set_intersection],
+[m4_set_contains([$1], [$2], [,[$2]])])
# m4_set_list(SET)
# m4_set_listc(SET)
# not guaranteed.
#
# We can rely on the fact that m4_set_listc prunes SET1, so we don't
-# need to check _m4_set([$1],element) for 0. Use _m4_defn for speed.
-# Short-circuit the idempotence relation.
+# need to check _m4_set([$1],element) for 0. Short-circuit the
+# idempotence relation.
m4_define([m4_set_union],
-[m4_set_listc([$1])m4_if([$1], [$2], [], [m4_set_foreach([$2], [_m4_element],
- [m4_ifdef([_m4_set([$1],]_m4_defn([_m4_element])[)], [],
- [,_m4_defn([_m4_element])])])])])
+[m4_set_listc([$1])m4_if([$1], [$2], [],
+ [m4_set_map_sep([$2], [_$0([$1],], [)])])])
+
+m4_define([_m4_set_union],
+[m4_ifdef([_m4_set([$1],$2)], [], [,[$2]])])
## ------------------- ##