[erlang-questions] Which built-in function makes [H|T] ?

Richard Carlsson carlsson.richard@REDACTED
Thu Nov 16 10:27:31 CET 2017


If you want to think in terms of constructors, where you first get an
initial value and then "populate" it, then the constructor for lists is
written [] (the empty list), and for a tuple you can call
erlang:make_tuple(Arity, InitialValue) or use
erlang:list_to_tuple(Elements). The function maps:new() simply returns #{},
so why it exists at all is a bit of a mystery. Maybe there were plans to
add a maps:new(Options) which could allow you to set special flags, like in
array:new(Options).

        /Richard

2017-11-16 3:19 GMT+01:00 Zhongzheng Liu <liuzhongzheng2012@REDACTED>:

> As far as I know, there is no constructor function for list or tuple.
>
> We have maps:new(), why not lists:new() or tuple:new() ?
>
>                              Liu Zhongzheng
>
>
> 2017-11-14 18:15 GMT+08:00 Cons T Åhs <cons@REDACTED>:
> >
> > On 14 Nov 2017, at 09:50, Richard Carlsson <carlsson.richard@REDACTED>
> > wrote:
> >
> > Most operators have a corresponding function in the 'erlang' module. For
> > example, A + B can be written erlang:'+'(A,B). However, the cons operator
> > [|] does not, as far as I know.
> >
> >
> > I’ve always considered this a gross oversight for several reasons.  One
> is
> > that you have to write your own local fun when you want to pass it as
> higher
> > order functional argument, another is that should one generate Erlang
> code
> > directly one has to take care of this and generate special syntax.  Then
> > there is the personal obvious reason :-)
> >
> > Cons
> >
> >
> >
> >
> >
> >         /Richard
> >
> > 2017-11-14 8:56 GMT+01:00 Zhongzheng Liu <liuzhongzheng2012@REDACTED>:
> >>
> >> Hi mail-list:
> >>
> >> Which built-in function work as   fun(H, T) -> [H|T] end ?
> >>
> >> i.e how to fill the following expression without user defined function ?
> >>
> >> [H|T] = erlang:apply(???, ???, [H, T]).
> >>
> >>
> >> Thanks
> >>
> >>                            Liu zhongzheng
> >> _______________________________________________
> >> erlang-questions mailing list
> >> erlang-questions@REDACTED
> >> http://erlang.org/mailman/listinfo/erlang-questions
> >
> >
> > _______________________________________________
> > erlang-questions mailing list
> > erlang-questions@REDACTED
> > http://erlang.org/mailman/listinfo/erlang-questions
> >
> >
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://erlang.org/mailman/listinfo/erlang-questions
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20171116/21c3bc06/attachment.htm>


More information about the erlang-questions mailing list