beginner question about Atom.intersection

Sep 1, 2007 at 4:07pm

beginner question about Atom.intersection

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<2;i++){
result = Atom.intersection(inputList1, inputList2);
}
post(“vedi ” +inputList1);
outlet(0, result);
}

public void bang() {
listIntersect(result);
}

}

#33499
Sep 1, 2007 at 4:47pm

On 1 sept. 07, at 18:07, matpe wrote:

> public void listIntersect(Atom[] a) {
> result = a;
> for (int i=1;i<2;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

#111669
Sep 1, 2007 at 5:07pm

Thanks Emmanuel
but it doesn’t work?

m

#111670
Sep 1, 2007 at 5:23pm

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

#111671
Sep 1, 2007 at 5:32pm

mmm…
no result from the outlet here

#111672
Sep 1, 2007 at 6:32pm

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:

http://www.e–j.com/dl/intersect.zip

It’s worth to mention than [mxj list.intersection] does the same.

ej

#111673
Sep 3, 2007 at 7:37am

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

#111674
Sep 3, 2007 at 7:43am

found it, list.multiplex…

m

#111675

You must be logged in to reply to this topic.