<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns="http://www.w3.org/TR/REC-html40">

<head>
<meta http-equiv=Content-Type content="text/html; charset=us-ascii">
<meta name=Generator content="Microsoft Word 11 (filtered medium)">
<!--[if !mso]>
<style>
v\:* {behavior:url(#default#VML);}
o\:* {behavior:url(#default#VML);}
w\:* {behavior:url(#default#VML);}
.shape {behavior:url(#default#VML);}
</style>
<![endif]-->
<style>
<!--
 /* Font Definitions */
 @font-face
        {font-family:Tahoma;
        panose-1:2 11 6 4 3 5 4 4 2 4;}
 /* Style Definitions */
 p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0in;
        margin-bottom:.0001pt;
        font-size:12.0pt;
        font-family:"Times New Roman";}
a:link, span.MsoHyperlink
        {color:blue;
        text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
        {color:purple;
        text-decoration:underline;}
span.EmailStyle17
        {mso-style-type:personal-reply;
        font-family:Arial;
        color:navy;}
@page Section1
        {size:8.5in 11.0in;
        margin:1.0in 1.25in 1.0in 1.25in;}
div.Section1
        {page:Section1;}
-->
</style>
<!--[if gte mso 9]><xml>
 <o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
 <o:shapelayout v:ext="edit">
  <o:idmap v:ext="edit" data="1" />
 </o:shapelayout></xml><![endif]-->
</head>

<body lang=EN-US link=blue vlink=purple>

<div class=Section1>

<p class=MsoNormal><font size=2 color=navy face=Arial><span style='font-size:
10.0pt;font-family:Arial;color:navy'>It looks similar to the problem that I had
– the code worked only when subresult was evaluated.<o:p></o:p></span></font></p>

<p class=MsoNormal><font size=2 color=navy face=Arial><span style='font-size:
10.0pt;font-family:Arial;color:navy'><a
href="http://www.erlang.org/pipermail/erlang-questions/2008-January/032389.html">http://www.erlang.org/pipermail/erlang-questions/2008-January/032389.html</a><o:p></o:p></span></font></p>

<p class=MsoNormal><font size=2 color=navy face=Arial><span style='font-size:
10.0pt;font-family:Arial;color:navy'><o:p> </o:p></span></font></p>

<p class=MsoNormal><font size=2 color=navy face=Arial><span style='font-size:
10.0pt;font-family:Arial;color:navy'>maybe the patch here helps?<o:p></o:p></span></font></p>

<p class=MsoNormal><font size=2 color=navy face=Arial><span style='font-size:
10.0pt;font-family:Arial;color:navy'>http://www.erlang.org/pipermail/erlang-questions/2008-January/032410.html<o:p></o:p></span></font></p>

<p class=MsoNormal><font size=2 color=navy face=Arial><span style='font-size:
10.0pt;font-family:Arial;color:navy'><o:p> </o:p></span></font></p>

<p class=MsoNormal><font size=2 color=navy face=Arial><span style='font-size:
10.0pt;font-family:Arial;color:navy'><o:p> </o:p></span></font></p>

<div style='border:none;border-left:solid blue 1.5pt;padding:0in 0in 0in 4.0pt'>

<div>

<div class=MsoNormal align=center style='text-align:center'><font size=3
face="Times New Roman"><span style='font-size:12.0pt'>

<hr size=2 width="100%" align=center tabindex=-1>

</span></font></div>

<p class=MsoNormal><b><font size=2 face=Tahoma><span style='font-size:10.0pt;
font-family:Tahoma;font-weight:bold'>From:</span></font></b><font size=2
face=Tahoma><span style='font-size:10.0pt;font-family:Tahoma'>
erlang-questions-bounces@erlang.org
[mailto:erlang-questions-bounces@erlang.org] <b><span style='font-weight:bold'>On
Behalf Of </span></b>Adam Bozanich<br>
<b><span style='font-weight:bold'>Sent:</span></b> 11. helmikuuta 2008 5:10<br>
<b><span style='font-weight:bold'>To:</span></b> erlang-questions@erlang.org<br>
<b><span style='font-weight:bold'>Subject:</span></b> [erlang-questions] qlc
expression help.</span></font><o:p></o:p></p>

</div>

<p class=MsoNormal><font size=3 face="Times New Roman"><span style='font-size:
12.0pt'><o:p> </o:p></span></font></p>

<p class=MsoNormal style='margin-bottom:12.0pt'><font size=3
face="Times New Roman"><span style='font-size:12.0pt'>Hi all,<br>
<br>
I'm having trouble creating a qlc expression which does what I want.  I'm
basically trying to create a filter for QH1 with a predicate that depends on
QH2.  <br>
In the example below, test2/0 gives me the result I'm looking for, but it
requires the second QH to be eval'd.  I'd like the expression to look like
what's in the test1/0 function.  Any suggestions?<br>
<br>
Thanks,<br>
-Adam<br>
<br>
session:<br>
8> test_qlc:test2().<br>
[{1,6,7},{2,8,9}]<br>
9> test_qlc:test1().<br>
[{1,4,5},<br>
 {1,2,3},<br>
 {1,6,7},<br>
 {1,6,7},<br>
 {2,4,5},<br>
 {2,2,3},<br>
 {2,8,9},<br>
 {2,8,9},<br>
 {3,4,5},<br>
 {3,2,3}]<br>
<br>
code:<br>
<br>
-module(test_qlc).<br>
-include_lib("stdlib/include/qlc.hrl").<br>
-export([test1/0,test2/0,handroll/0]).<br>
<br>
-define(DB,[<br>
  {1,4,5},{1,2,3},{1,6,7},<br>
  {2,4,5},{2,2,3},{2,8,9},<br>
  {3,4,5},{3,2,3}<br>
]).<br>
-define(OBJ,[{2,3},{4,5}]).<br>
<br>
test1() -><br>
    qlc:eval(qlc:q([ {O1,C1,V1} ||<br>
                      
{O1,C1,V1} <- ?DB,<br>
                      
{C2,V2} <- ?OBJ,<br>
                      
C1 /= C2,<br>
                      
V1 /= V2])).<br>
test2() -><br>
    qlc:eval(qlc:q([ {O1,C1,V1} ||<br>
                    
{O1,C1,V1} <- ?DB,<br>
                    
lists:member({C1,V1},?OBJ) == false ])).<br>
<br>
handroll() -><br>
    S = mkset(?DB),<br>
    O = mkobj(?OBJ),<br>
    to_table(difference(O,related(O,S))).<br>
<br>
related(S1,D) -><br>
    dict:filter(fun(_,S2) -><br>
                       
sets:is_subset(S1,S2)<br>
               
end,D).<br>
<br>
difference(S1,D) -><br>
    dict:filter(fun(_,S2) -><br>
                       
sets:size(S2) > 0<br>
               
end,<br>
               
dict:map(fun(_,S2) -><br>
                                
sets:subtract(S2,S1)<br>
                        
end,D)).<br>
<br>
to_table(D) -><br>
    lists:flatmap(fun({K,V}) -><br>
                         
lists:map(fun({X,Y}) -><br>
                                           
{K,X,Y}<br>
                                   
end,<br>
                                   
sets:to_list(V))<br>
                 
end,<br>
                 
dict:to_list(D)).<br>
<br>
mkset(DB) -><br>
    dict:map(fun(_,V) -><br>
                    
sets:from_list(V)<br>
             end,<br>
            
lists:foldl(fun({O,C,V},Acc) -><br>
                                 
dict:append(O,{C,V},Acc)<br>
                        
end,<br>
                        
dict:new(),DB)).<br>
<br>
mkobj(OBJ) -><br>
    sets:from_list(OBJ).<o:p></o:p></span></font></p>

</div>

</div>

</body>

</html>