[erlang-questions] The reason for "no case clause matching" error?
Zvi
exta7@REDACTED
Thu Jan 3 13:15:43 CET 2008
Yoel, just a minor comment:
I would use [Lhs|P] or [Lhs]++P instead of lists:append([Lhs], P) :)
This is essentially the same as CONS in Lisp.
Zvi
Yoel Jacobsen-2 wrote:
>
> Hello,
>
>
> I want to implement some sort of list partitioning in Erlang.
>
>
> The ppar function should work like that:
>
> ppar [2,2,3] -> [[[2],[2],[3]], [[2],[2,3]], [[2,2],[3]],[ [2,2,3]]]
> ppar [2,2,3,4] -> [[[2],[2],[3],[4]], [[2],[2],[3,4]], [[2],[2,3],[4]],
> [[2],[2,3,4]], [[2,2],[3],[4]], [[2,2],[3,4]], [[2,2,3],[4]], [[2,2,3,4]]]
>
>
> This is the code I have written:
>
> -module(ppar).
> -export([ppar/1]).
>
>
> sp(Lhs, []) ->
> [[Lhs]];
> sp(Lhs, Rhs) ->
> [lists:append([Lhs], P) || P <- ppar(Rhs)].
>
> ppar([]) ->
> [[[]]];
> ppar([H|[]]) ->
> [[[H]]];
> ppar(Lst) ->
> [SP ||
> N <- lists:seq(1,length(Lst)),
> Lhs = lists:sublist(Lst, 1, N),
> Rhs = lists:sublist(Lst, N+1, length(Lst)),
> SP <- sp(Lhs, Rhs)].
>
> Yet, when I try it I get an error:
>
> 1> ppar:ppar([1,2,3]).
> ** exception error: no case clause matching [1]
> in function ppar:'-ppar/1-lc$^0/1-0-'/2
>
> Why is that?
>
> Yoel
>
>
>
> begin:vcard
> fn:Yoel Jacobsen
> n:Jacobsen;Yoel
> org:E&M Computing LTD
> adr:;;6 Achilazon st.;Ramat-Gan;;52522;ISRAEL
> email;internet:yoel@REDACTED
> tel;work:+972-3-5766999
> tel;fax:+972-3-7513626
> tel;pager:Skype: yoeljacobsen
> tel;cell:+972-54-4770078
> x-mozilla-html:TRUE
> url:http://www.emet.co.il
> version:2.1
> end:vcard
>
>
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://www.erlang.org/mailman/listinfo/erlang-questions
>
--
View this message in context: http://www.nabble.com/The-reason-for-%22no-case-clause-matching%22-error--tp14567237p14595941.html
Sent from the Erlang Questions mailing list archive at Nabble.com.
More information about the erlang-questions
mailing list