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

12 messages
Open this post in threaded view
|

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

 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 [hidden email] http://erlang.org/mailman/listinfo/erlang-questions
Open this post in threaded view
|

## Re: Which built-in function makes [H|T] ?

 Hi, I don't know if what you want is this, I'm newbie in Erlang: [H|T] = [H] ++ T. Miguel Ruiz > El 14 nov 2017, a las 8:56, Zhongzheng Liu <[hidden email]> escribió: > > 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 > [hidden email] > http://erlang.org/mailman/listinfo/erlang-questions_______________________________________________ erlang-questions mailing list [hidden email] http://erlang.org/mailman/listinfo/erlang-questions
Open this post in threaded view
|

## Re: Which built-in function makes [H|T] ?

 In reply to this post by Zhongzheng Liu 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 :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 [hidden email] http://erlang.org/mailman/listinfo/erlang-questions _______________________________________________ erlang-questions mailing list [hidden email] http://erlang.org/mailman/listinfo/erlang-questions
Open this post in threaded view
|

## Re: Which built-in function makes [H|T] ?

 See this thread from earlier this year: http://erlang.org/pipermail/erlang-questions/2017-January/091560.htmlOn 14 November 2017 at 08:50, Richard Carlsson <[hidden email]> 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 <[hidden email]>: >> >> 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 >> [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
Open this post in threaded view
|

## Re: Which built-in function makes [H|T] ?

 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/5On Tue 14 Nov 2017 at 10:55, Roger Lipscombe <[hidden email]> 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 <[hidden email]> 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 <[hidden email]>: >> >> 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 >> [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 -- Cheers,-- Pierre Fenoll _______________________________________________ erlang-questions mailing list [hidden email] http://erlang.org/mailman/listinfo/erlang-questions
Open this post in threaded view
|

## Re: Which built-in function makes [H|T] ?

 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 X0returnor something like this. And it will become usable in HOFs now2017-11-14 11:04 GMT+01:00 Pierre Fenoll :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/5On Tue 14 Nov 2017 at 10:55, Roger Lipscombe <[hidden email]> 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 <[hidden email]> 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 <[hidden email]>: >> >> 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 >> [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 -- Cheers,-- Pierre Fenoll _______________________________________________ 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
Open this post in threaded view
|

## Re: Which built-in function makes [H|T] ?

 In reply to this post by Richard Carlsson-3 On 14 Nov 2017, at 09:50, Richard Carlsson <[hidden email]> 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 :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 [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
Open this post in threaded view
|

## Re: Which built-in function makes [H|T] ?

 I'll make sure it gets named erlang:'[_|_]'/2 in your honour.        /Richard 2017-11-14 11:15 GMT+01:00 Cons T Åhs :On 14 Nov 2017, at 09:50, Richard Carlsson <[hidden email]> 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 :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 [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
Open this post in threaded view
|

## Re: Which built-in function makes [H|T] ?

 In reply to this post by Richard Carlsson-3 On 14/11/17 9:50 PM, Richard Carlsson 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 suggest rolling your own. cons(H, T) -> [H|T]. erlang:apply(?MODULE, cons, [H,T]) _______________________________________________ erlang-questions mailing list [hidden email] http://erlang.org/mailman/listinfo/erlang-questions
Open this post in threaded view
|

## Re: Which built-in function makes [H|T] ?

 In reply to this post by Roger Lipscombe-2 On reflection, the question needs to be asked: "why do you want to do this"? It's not wrong or stupid or anything, it just seems like a rather low-level thing to be passing around. I'd normally expect a function parameter to be a bit more, well, application-specific. What I'm getting at is that there might be a better way to do whatever it is you really want to do. _______________________________________________ erlang-questions mailing list [hidden email] http://erlang.org/mailman/listinfo/erlang-questions