Is it a list ?
Johan Garpendahl
Johan.Garpendahl@REDACTED
Thu Jul 10 14:45:48 CEST 2003
Hello Zoltan!
This is a slightly simplified explaination.
I think each element in a list has two parts.
The first part contains a pointer to the actual element and the other
part points to the next element in the list.
In a simple list, the first part points a number. In a less simple
list, the first element could point to another list.
At the end of a list, you usually want to put an emty list element.
That could be represented by a null pointer.
To modify your example, that would be:
1> X = [1,2|[]].
[1,2]
That is, [1,2|[]] and [1,2] is exactly the same thing.
[1,2] is somewhat shorter to write.
Hope I have explained more than I have confused.
Regards,
Johan
>>>>> "Zoltan" == Zoltan Peter Toth <Zoltan.Toth@REDACTED> writes:
Zoltan> Hi ! I've made a little test in the Erlang machine:
Zoltan> 1> X = [1|2].
Zoltan> [1|2]
Zoltan> Now, my big question is, WHAT an object is X ?
Zoltan> 2> is_list(X).
Zoltan> true
Zoltan> So, it is a list, but not a well formed one:
Zoltan> 3> list_to_tuple(X).
Zoltan> =ERROR REPORT==== 10-Jul-2003::11:09:15 === Error in process
Zoltan> <0.26.0> with exit value:
Zoltan> {badarg,[{erlang,list_to_tuple,[[1|2]]},{erl_eval,expr,3},{erl_eval,exprs,4},{shell,eval_loop,2}]}
Zoltan> ** exited: {badarg,[{erlang,list_to_tuple,[[1|2]]},
Zoltan> {erl_eval,expr,3}, {erl_eval,exprs,4}, {shell,eval_loop,2}]}
Zoltan> **
Zoltan> 9> length(X).
Zoltan> =ERROR REPORT==== 10-Jul-2003::11:12:42 === Error in process
Zoltan> <0.39.0> with exit value:
Zoltan> {badarg,[{erlang,length,[[1|2]]},{erl_eval,expr,3},{erl_eval,exprs,4},{shell,eval_loop,2}]}
Zoltan> ** exited: {badarg,[{erlang,length,[[1|2]]},
Zoltan> {erl_eval,expr,3}, {erl_eval,exprs,4}, {shell,eval_loop,2}]}
Zoltan> **
Zoltan> ... so what is the structure and what are the elements and the
Zoltan> length of this weird list ? Thanks for any answer, Zoltan
More information about the erlang-questions
mailing list