[erlang-questions] The reason for "no case clause matching" error?
Yoel Jacobsen
yoel@REDACTED
Tue Jan 1 13:08:49 CET 2008
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
-------------- next part --------------
A non-text attachment was scrubbed...
Name: yoel.vcf
Type: text/x-vcard
Size: 315 bytes
Desc: not available
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20080101/e328c5d8/attachment.vcf>
More information about the erlang-questions
mailing list