[erlang-questions] create list quesion

Richard A. O'Keefe ok@REDACTED
Fri Jan 30 06:04:13 CET 2015


On 28/01/2015, at 7:23 am, Imants Cekusins <imantc@REDACTED> wrote:

> this works:
> 
> 
> -module(create).
> 
> 
> -export([create_list/2, create/1]).
> 
> create(0) ->
>  [];
> 
> create(Number) ->
>  create_list(Number, [] ).
> 
> create_list(0, List) ->   List;
> 
> create_list(Number, List) ->
>  create_list( Number -1, [Number | List] ).

In this code,
(1) The clause for create(0) is utterly pointless.
(2) A call create(-1) results in an infinite loop.
(3) create/1 and create_list/2 both create lists,
so the distinction between the names is inappropriate.
(4) Actually, neither create/1 nor create_list/2
*creates* anything, any more than 1+1 *creates* 2.

Programs in OO languages create objects;
programs in FP languages compute values.




More information about the erlang-questions mailing list