Hi,<br><p>I cannot say I fully understand the error message. However the reference manual says:</p><p>"List comprehensions are written with the following syntax:
</p>
<div class="example"><pre>[Expr || Qualifier1,...,QualifierN]<br> <br></pre></div>
<p><span class="code">Expr</span> is an arbitrary expression, and each
<span class="code">Qualifier</span> is either a generator or a filter.
</p>
<p>
</p><ul><li>
A <strong>generator</strong> is written as: <br>
<span class="code">Pattern <- ListExpr</span>. <br>
<span class="code">ListExpr</span> must be an expression which evaluates to a
list of terms.
</li><li>A <strong>filter</strong> is an expression which evaluates to
<span class="code">true</span> or <span class="code">false</span>."</li></ul><br>Some of the Qualifiers you use in your list comprehension (e.g. Lhs = lists:sublist(Lst, 1, N)) are neither generators nor filters since they do not contain "<-" and evaluates to lists rather than true or false.
<br><br>I suggest rewriting the last function clause to:<br><br>ppar(Lst) -><br> [SP ||<br> N <- lists:seq(1,length(Lst)),<br> SP <- sp(lists:sublist(Lst, 1, N), lists:sublist(Lst, N+1, length(Lst)))].<br>
<br>or (to maintain the variables for clarity)<br><br>ppar(Lst) -><br> [SP || N <- lists:seq(1,length(Lst)),<br> SP <- begin<br> Lhs = lists:sublist(Lst, 1, N),<br> Rhs = lists:sublist(Lst, N+1, length(Lst)),
<br> sp(Lhs, Rhs)<br> end].<br><br><br>Gives:<br><br>2> test4:ppar([2,2,3]).<br>[[[2],[2],[3]],[[2],[2,3]],[[2,2],[3]],[[2,2,3]]]<br><br>Hope this helps.<br><br>BR /Fredrik<br><br><br><div class="gmail_quote">
On Jan 1, 2008 1:08 PM, Yoel Jacobsen <<a href="mailto:yoel@emet.co.il">yoel@emet.co.il</a>> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
Hello,<br><br><br>I want to implement some sort of list partitioning in Erlang.<br><br><br>The ppar function should work like that:<br><br>ppar [2,2,3] -> [[[2],[2],[3]], [[2],[2,3]], [[2,2],[3]],[ [2,2,3]]]<br>ppar [2,2,3,4] -> [[[2],[2],[3],[4]], [[2],[2],[3,4]], [[2],[2,3],[4]],
<br>[[2],[2,3,4]], [[2,2],[3],[4]], [[2,2],[3,4]], [[2,2,3],[4]], [[2,2,3,4]]]<br><br><br>This is the code I have written:<br><br>-module(ppar).<br>-export([ppar/1]).<br><br><br>sp(Lhs, []) -><br> [[Lhs]];<br>sp(Lhs, Rhs) ->
<br> [lists:append([Lhs], P) || P <- ppar(Rhs)].<br><br>ppar([]) -><br> [[[]]];<br>ppar([H|[]]) -><br> [[[H]]];<br>ppar(Lst) -><br> [SP ||<br> N <- lists:seq(1,length(Lst)),<br> Lhs = lists:sublist(Lst, 1, N),
<br> Rhs = lists:sublist(Lst, N+1, length(Lst)),<br> SP <- sp(Lhs, Rhs)].<br><br>Yet, when I try it I get an error:<br><br>1> ppar:ppar([1,2,3]).<br>** exception error: no case clause matching [1]<br> in function ppar:'-ppar/1-lc$^0/1-0-'/2
<br><br>Why is that?<br><font color="#888888"><br>Yoel<br><br><br></font><br>_______________________________________________<br>erlang-questions mailing list<br><a href="mailto:erlang-questions@erlang.org">erlang-questions@erlang.org
</a><br><a href="http://www.erlang.org/mailman/listinfo/erlang-questions" target="_blank">http://www.erlang.org/mailman/listinfo/erlang-questions</a><br></blockquote></div><br>