Re: Problem to get a list of list in C++ predicate

From: Joachim Schimpf <j.schimpf_at_icparc.ic.ac.uk>
Date: Thu 23 Jun 2005 12:49:40 PM GMT
Message-ID: <42BAAFE4.9080901@icparc.ic.ac.uk>
ludovic picouays wrote:
> I have a problem with a C predicate I've written. I have a list of
> list in input ([[1,2,3],[4,5,6]]). And I would like to put that in a
> short **. I don't know how I can do that.
> 
> I have these lines in my fonction :
> /*************************************************************************/
> i=0;
> for(ecword_list = ecword_liste_trou ; ecword_list.is_list(car,cdr) ==
> EC_succeed; ecword_list = cdr)//walk through the main list
> {//construction of the list but I'm not sure, I think the problem is here
> 	list_tmp = list(car,cdr); 
         ^^^^^^^^^^^^^^^^^^^^^^^^
You don't need list_tmp.  You can use car directly, because it is the
sublist you want (i.e. the content of the outer list element).


> 	nb = liste_taille_domaine[i]; //get the length of the list
> 	if(nb>0)
> 	{
> 		liste_trou[i] = (short *)malloc(nb*sizeof(short)); // allocation of memory
> 		j=0;
> 		for(ecword_list2 = list_tmp ; ecword_list2.is_list(car2,cdr2) ==
> EC_succeed; ecword_list2 = cdr2)//walk through the little list
> 		{
> 			res = car2.is_long(&x);//recuperation of the element
> 			if (res != EC_succeed) return res;
> 			liste_trou[i][j]=x;//I put element in my short **
> 			j++;
> 		}
> 	}
> 	i++;
> }
> /*************************************************************************/
> 
> The problem is when I would like to build the list which in the other list.
> 


So your code should look like this:

i=0;
for(ecword_list = ecword_liste_trou ; ecword_list.is_list(car,cdr) ==
	EC_succeed; ecword_list = cdr)	//walk through the main list
{
	nb = liste_taille_domaine[i]; //get the length of the list
	if(nb>0)
	{
		liste_trou[i] = (short *)malloc(nb*sizeof(short)); // allocation of memory
		j=0;
		for(ecword_list2 = car ; ecword_list2.is_list(car2,cdr2) ==
			EC_succeed; ecword_list2 = cdr2) //walk through the little list
		{
			res = car2.is_long(&x);//recuperation of the element
			if (res != EC_succeed) return res;
			liste_trou[i][j]=x;//I put element in my short **
			j++;
		}
	}
	i++;
}


-- 
  Joachim Schimpf              /             phone: +44 20 7594 8187
  IC-Parc                     /      mailto:J.Schimpf@imperial.ac.uk
  Imperial College London    /    http://www.icparc.ic.ac.uk/eclipse
Received on Thu Jun 23 13:55:47 2005

This archive was generated by hypermail 2.1.8 : Wed 16 Nov 2005 06:07:37 PM GMT GMT