Quantcast

Erlang cons function

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Erlang cons function

Garrett Smith-5
Is there a functional reference to the cons operator? Something
equivalent to this:

  fun(H, T) -> [H|T] end

I was hoping for erlang:'|'(H, T) but no dice.
_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Erlang cons function

Richard Carlsson-3
No, it's considered a language primitive, similar to fixed-size tuples {1,2}. That's not to say that there couldn't be a named function like the one you looked for, just that there isn't one because there has never been much of a need for it.

        /Richard

2017-01-31 16:16 GMT+01:00 Garrett Smith <[hidden email]>:
Is there a functional reference to the cons operator? Something
equivalent to this:

  fun(H, T) -> [H|T] end

I was hoping for erlang:'|'(H, T) but no dice.
_______________________________________________
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
|  
Report Content as Inappropriate

Re: Erlang cons function

Jesper Louis Andersen-2
It is easy to define:

cons(H,T) -> [H|T].

but you are perhaps better off by just using a fun-wrapper or writing it directly in places where you need it. Without support for currying much of the higher-order vocabulary seems somewhat weaker.

On Tue, Jan 31, 2017 at 7:26 PM Richard Carlsson <[hidden email]> wrote:
No, it's considered a language primitive, similar to fixed-size tuples {1,2}. That's not to say that there couldn't be a named function like the one you looked for, just that there isn't one because there has never been much of a need for it.

        /Richard

2017-01-31 16:16 GMT+01:00 Garrett Smith <[hidden email]>:
Is there a functional reference to the cons operator? Something
equivalent to this:

  fun(H, T) -> [H|T] end

I was hoping for erlang:'|'(H, T) but no dice.
_______________________________________________
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
Loading...