{some,term} = [] ++ {some, term}.

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

{some,term} = [] ++ {some, term}.

John Doe
Hi,
is this normal?

{some,term} = [] ++ {some, term}. %% list vanishes

[1,2,3|{some,term}] = [1,2,3] ++ {some, term}. %% improper list

_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions
Reply | Threaded
Open this post in threaded view
|

Re: {some,term} = [] ++ {some, term}.

Brujo Benavides-3
Hi John,


Hope this helps :)

On 24 Apr 2018, at 12:13, John Doe <[hidden email]> wrote:

Hi,
is this normal?

{some,term} = [] ++ {some, term}. %% list vanishes

[1,2,3|{some,term}] = [1,2,3] ++ {some, term}. %% improper list
_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions


_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions
Reply | Threaded
Open this post in threaded view
|

Re: {some,term} = [] ++ {some, term}.

Pierre Fenoll-2
Another funny thing:
1> {A,B} = {sets:from_list([-28]), sets:from_list([4])}.
{{set,1,16,16,8,80,48,
      {[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[]},
      {{[],[],[],[],[],[],[],[],[],[],[],[],[-28],[],[],[]}}},
 {set,1,16,16,8,80,48,
      {[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[]},
      {{[],[],[],[],[],[],[],[],[],[],[],[],[4],[],[],[]}}}}
2> sets:union(A,B) == sets:union(B,A).
false

Thomas Arts (of QuickCheck fame) showed this in 2005 I think!
This is due to the sets underlying representation.
I thought there was a PR to use maps instead but can't find it anymore.

The corresponding PropEr property:
-include_lib("proper/include/proper.hrl").
a_sets_generator() ->
    ?LET(SomeList, list(integer())
        ,sets:from_list(SomeList)
        ).
%% rebar3 as test proper -p prop_sets_union_is_commutative
prop_sets_union_is_commutative() ->
    ?FORALL({SetA,SetB}, {a_sets_generator(),a_sets_generator()}
           ,?WHENFAIL(io:format("\nSetA = ~w\nSetB = ~w\n", [sets:to_list(SetA), sets:to_list(SetB)])
                     ,sets:union(SetA,SetB) =:= sets:union(SetB,SetA)
                     )
           ).



Cheers,
-- 
Pierre Fenoll


On 24 April 2018 at 17:15, Brujo Benavides <[hidden email]> wrote:
Hi John,


Hope this helps :)

On 24 Apr 2018, at 12:13, John Doe <[hidden email]> wrote:

Hi,
is this normal?

{some,term} = [] ++ {some, term}. %% list vanishes

[1,2,3|{some,term}] = [1,2,3] ++ {some, term}. %% improper list
_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions


_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions



_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions
Reply | Threaded
Open this post in threaded view
|

Re: {some,term} = [] ++ {some, term}.

Brujo Benavides-3
Maybe sets could provide a function like…

is_equal(A, B) -> is_subset(A, B) andalso is_subset(B, A).

On 24 Apr 2018, at 13:19, Pierre Fenoll <[hidden email]> wrote:

Another funny thing:
1> {A,B} = {sets:from_list([-28]), sets:from_list([4])}.
{{set,1,16,16,8,80,48,
      {[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[]},
      {{[],[],[],[],[],[],[],[],[],[],[],[],[-28],[],[],[]}}},
 {set,1,16,16,8,80,48,
      {[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[]},
      {{[],[],[],[],[],[],[],[],[],[],[],[],[4],[],[],[]}}}}
2> sets:union(A,B) == sets:union(B,A).
false

Thomas Arts (of QuickCheck fame) showed this in 2005 I think!
This is due to the sets underlying representation.
I thought there was a PR to use maps instead but can't find it anymore.

The corresponding PropEr property:
-include_lib("proper/include/proper.hrl").
a_sets_generator() ->
    ?LET(SomeList, list(integer())
        ,sets:from_list(SomeList)
        ).
%% rebar3 as test proper -p prop_sets_union_is_commutative
prop_sets_union_is_commutative() ->
    ?FORALL({SetA,SetB}, {a_sets_generator(),a_sets_generator()}
           ,?WHENFAIL(io:format("\nSetA = ~w\nSetB = ~w\n", [sets:to_list(SetA), sets:to_list(SetB)])
                     ,sets:union(SetA,SetB) =:= sets:union(SetB,SetA)
                     )
           ).



Cheers,
-- 
Pierre Fenoll


On 24 April 2018 at 17:15, Brujo Benavides <[hidden email]> wrote:
Hi John,


Hope this helps :)

On 24 Apr 2018, at 12:13, John Doe <[hidden email]> wrote:

Hi,
is this normal?

{some,term} = [] ++ {some, term}. %% list vanishes

[1,2,3|{some,term}] = [1,2,3] ++ {some, term}. %% improper list
_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions


_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions




_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions