How to convert C++ const_iterator and more to Lisp

Discussion of Common Lisp

How to convert C++ const_iterator and more to Lisp

Postby joeish80829 » Thu May 15, 2014 5:10 am

How do I convert this section of C++ code into Lisp using Lisp lists. I don't really need to show it but I have a C++ vector<int>. I converted into lisp using CFFI. I converted the vector<int> filled with 5 numbers ,to a Lisp List.

Here is the final Lisp list:

Code: Select all
(1 2 3 4 5)


I would like you to hopefully ignore what I said previously and pretend that I'm just starting out with the previously mentioned Lisp list and know I need to operate on it precisely as below so it will fit into the other C++ code I'm converting to Lisp. can you kind gentleman possible show my the exact Lisp equivelant of the below statement, operating on this exact list...
Code: Select all
(1 2 3 4 5)
....thanks in advance for any help on this.

Code: Select all
       for( vector<int>::const_iterator r = number.begin(); r != number.end(); r++ )
        {
            number.push_back(1);
        }
joeish80829
 
Posts: 153
Joined: Tue Sep 03, 2013 5:32 am

Re: How to convert C++ const_iterator and more to Lisp

Postby Goheeca » Thu May 15, 2014 10:28 am

What should that snippet of code do? Because by every iteration you are extending the vector and you can't reach the end of it. Moreover, the iterator is invalidated by performing the push_back action.
cl-2dsyntax is my attempt to create a Python-like reader. My mirror of CLHS (and the dark themed version).
User avatar
Goheeca
 
Posts: 198
Joined: Thu May 10, 2012 12:54 pm

Re: How to convert C++ const_iterator and more to Lisp

Postby joeish80829 » Fri May 16, 2014 4:41 am

It is valid code from a working function..I changed the name of the vector<Rect> to vector<int> to show it here and to save confusion. Here is the original snippet:


Code: Select all
        for( vector<Rect>::const_iterator r = faces2.begin(); r != faces2.end(); r++ )
        {
            faces.push_back(Rect(smallImg.cols - r->x - r->width, r->y, r->width, r->height));
        }


It is from line 193 at this link :

https://github.com/Itseez/opencv/blob/m ... detect.cpp

There is a lot of code at that link and could get confusing. I did simplify right though and it is a valid expression
joeish80829
 
Posts: 153
Joined: Tue Sep 03, 2013 5:32 am

Re: How to convert C++ const_iterator and more to Lisp

Postby joeish80829 » Fri May 16, 2014 7:45 am

Actually I grabbed the wrong one it was this I need to convert from line 199 at the above link:


Code: Select all
    for( vector<Rect>::iterator r = faces.begin(); r != faces.end(); r++, i++ ) {}



Also on the line 223 code:

Code: Select all
smallImgROI = smallImg(*r);


I'll have to call r as a pointer because calling as:

Code: Select all
smallImgROI = smallImg(r);


breaks the code. So a hint on that would really help as well eg don't know how to call as a pointer in CFFI yet.

You don't have to read all that code at the link...even a general idea would get me farther, Thanks for your attention to this so far:)
joeish80829
 
Posts: 153
Joined: Tue Sep 03, 2013 5:32 am

Re: How to convert C++ const_iterator and more to Lisp

Postby Goheeca » Fri May 16, 2014 9:41 am

The dereference for an iterator is an overloaded operator, thus you can call it in this way:
Code: Select all
smallImgROI = smallImg(r.operator*());

So manage invoking a method and you should be right.
cl-2dsyntax is my attempt to create a Python-like reader. My mirror of CLHS (and the dark themed version).
User avatar
Goheeca
 
Posts: 198
Joined: Thu May 10, 2012 12:54 pm


Return to Common Lisp

Who is online

Users browsing this forum: No registered users and 4 guests