[1,[2|3]] vs [1,2|3]

Samuel Rivas samuel@REDACTED
Sat Apr 29 17:32:08 CEST 2006


Roger Price wrote:
> Dear List,
> 
> The Erlang (BEAM) emulator version 5.4.9 [source] [hipe] with 
> Eshell V5.4.9 reports:
> 
> 1> [1,[2|3]] .          %% Valid list
> [1,[2|3]]                        
> 2> [1,2|3] .            %% Not a list
> [1,2|3]
> 
> My understanding is that [1,[2|3]] = 1::[2|3]::nil = 1::(2::3)::nil
>                      and [1,2|3]   = 1::2::3
> using the ML infix notation.
> 
> Is this correct?

  [A,B|C] is a shorthand for [A|[B|C]] so [1,2|3] = [1|[2|3]] which is
exactly 1::2::3 in ML. Both examples contain non proper lists though: you
are using something that is not a list (3) as tail in the cons operator

1> [1,[2|[3]]].
[1,[2,3]]
2> [1,2|[3]].
[1,2,3]

Regards
-- 
	Samuel



More information about the erlang-questions mailing list