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

Dmytro Lytovchenko dmytro.lytovchenko@REDACTED
Tue Nov 14 11:15:12 CET 2017


Operation [H|T] and [H] ++ [T] probably too, is replaced by the compiler
with a `put_list` instruction. If you want it to be callable for high order
functions it must be located inside some fun, so give it a lambda: fun(H,
T) -> [H|T] end, or create your own function,
which will conveniently compile into:

func_info some_name 2 (the arity)
put_list X0 X1 X0
return

or something like this. And it will become usable in HOFs now

2017-11-14 11:04 GMT+01:00 Pierre Fenoll <pierrefenoll@REDACTED>:

> It would be nice to have a cons function, either in the erlang or lists
> module.
> One usage for it I have had is as the accumulator function of
> filelib:fold_dirs/5
>
> On Tue 14 Nov 2017 at 10:55, Roger Lipscombe <roger@REDACTED>
> wrote:
>
>> See this thread from earlier this year:
>> http://erlang.org/pipermail/erlang-questions/2017-January/091560.html
>>
>> On 14 November 2017 at 08: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.
>> >
>> >
>> >
>> >
>> >         /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
>>
> --
>
> Cheers,
> --
> Pierre Fenoll
>
>
> _______________________________________________
> 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/20171114/e175d1c3/attachment.htm>


More information about the erlang-questions mailing list