beginner question about Atom.intersection


    Sep 01 2007 | 4:07 pm
    I'm learning programming java (first steps) and I don't understand why my code doesn't produce the expected result. I'm simply trying to intersecate two lists using the Atom syntax. I suppose solution is very esay for an expert?
    Many thanks
    Matteo
    import com.cycling74.max.*;
    public class Intersect2List extends MaxObject {
    private Atom[] inputList1; private Atom[] inputList2; private Atom[] result;
    private Intersect2List() { declareTypedIO("LL","L"); declareInlets(new int[]{DataTypes.LIST, DataTypes.LIST}); createInfoOutlet(false); setInletAssist(new String[] {"list a and bang", "list b"}); setOutletAssist(new String[] {"intersection list"}); }
    public void list(Atom[] args) { switch (getInlet()) { case 0: inputList1 = args; break; case 1: inputList2 = args; break; } }
    public void listIntersect(Atom[] a) { result = a; for (int i=1;i result = Atom.intersection(inputList1, inputList2); } post("vedi " +inputList1); outlet(0, result); }
    public void bang() { listIntersect(result); }
    }

    • Sep 01 2007 | 4:47 pm
      On 1 sept. 07, at 18:07, matpe wrote:
      > public void listIntersect(Atom[] a) { > result = a; > for (int i=1;i > result = Atom.intersection(inputList1, inputList2); > } > post("vedi " +inputList1); > outlet(0, result); > }
      I didn't try but the following should work:
      public class Intersect2List extends MaxObject {
      private Atom[] inputList1; private Atom[] inputList2; private Atom[] result;
      private Intersect2List() { declareTypedIO("LL","L"); declareInlets(new int[]{DataTypes.LIST, DataTypes.LIST}); createInfoOutlet(false); setInletAssist(new String[] {"list a and bang", "list b"}); setOutletAssist(new String[] {"intersection list"}); }
      public void list(Atom[] args) { switch (getInlet()) { case 0: inputList1 = args; bang(); // trigger because it arrived in the left inlet break; case 1: inputList2 = args; break; } }
      public void listIntersect(Atom[] a) { result = Atom.intersection(inputList1, inputList2); outlet(0, result); }
      public void bang() { listIntersect(); } }
      Cheers, ej
    • Sep 01 2007 | 5:07 pm
      Thanks Emmanuel but it doesn't work?
      m
    • Sep 01 2007 | 5:23 pm
      On 1 sept. 07, at 19:07, matpe wrote:
      > Thanks Emmanuel > but it doesn't work?
      import com.cycling74.max.*;
      public class Intersect2List extends MaxObject {
      private Atom[] inputList1; private Atom[] inputList2; private Atom[] result;
      private Intersect2List() { declareTypedIO("LL","L"); declareInlets(new int[]{DataTypes.LIST, DataTypes.LIST}); createInfoOutlet(false); setInletAssist(new String[] {"list a and bang", "list b"}); setOutletAssist(new String[] {"intersection list"}); }
      public void list(Atom[] args) { switch (getInlet()) { case 0: inputList1 = args; bang(); // trigger because it arrived in the left inlet break; case 1: inputList2 = args; break; } }
      public void listIntersect() { result = Atom.intersection(inputList1, inputList2); outlet(0, result); }
      public void bang() { listIntersect(); } }
      This one works! ej
    • Sep 01 2007 | 5:32 pm
      mmm... no result from the outlet here
    • Sep 01 2007 | 6:32 pm
      On 1 sept. 07, at 19:32, matpe wrote:
      > mmm... > no result from the outlet here
      It works fine here, try with the following archive:
      It's worth to mention than [mxj list.intersection] does the same.
      ej
    • Sep 03 2007 | 7:37 am
      many thanks emmanuel.
      My fault is a misunderstanding about the intersection function; it reports the elements in common. My goal is to have such a result:
      A: 13 8 90 B: 21 16 30 result: 13 21 8 16 90 30
      I'll keep to investigate.
      Thanks again
      m
    • Sep 03 2007 | 7:43 am
      found it, list.multiplex...
      m