<html><body><div style="color:#000; background-color:#fff; font-family:HelveticaNeue, Helvetica Neue, Helvetica, Arial, Lucida Grande, sans-serif;font-size:10pt"><div style="" class=""><span style="" class="">Thanks for getting back to me...quick ? pertaining to this:</span></div><div class="" style="color: rgb(0, 0, 0); font-size: 13.3333px; font-family: HelveticaNeue,Helvetica Neue,Helvetica,Arial,Lucida Grande,sans-serif; background-color: transparent; font-style: normal"><br style="" class=""><span style="" class=""></span></div><div class="" style="color: rgb(0, 0, 0); font-size: 13.3333px; font-family: HelveticaNeue,Helvetica Neue,Helvetica,Arial,Lucida Grande,sans-serif; background-color: transparent; font-style: normal"><br style="" class="">(foreign-alloc :pointer :initial-contents <br style="" class="">  (mapcar (p) (c-pointer (point (car p) (cdr p))))<br style="" class=""> '((1 . 2) (3 . 4) ...))</div><div class="" style="color: rgb(0, 0,
 0); font-size: 13.3333px; font-family: HelveticaNeue,Helvetica Neue,Helvetica,Arial,Lucida Grande,sans-serif; background-color: transparent; font-style: normal"><br style="" class=""></div><div class="" style="color: rgb(0, 0, 0); font-size: 13.3333px; font-family: HelveticaNeue,Helvetica Neue,Helvetica,Arial,Lucida Grande,sans-serif; background-color: transparent; font-style: normal"><br style="" class=""></div><div class="" style="color: rgb(0, 0, 0); font-size: 13.3333px; font-family: HelveticaNeue,Helvetica Neue,Helvetica,Arial,Lucida Grande,sans-serif; background-color: transparent; font-style: normal"><br style="" class=""></div><div class="" style="color: rgb(0, 0, 0); font-size: 13.3333px; font-family: HelveticaNeue,Helvetica Neue,Helvetica,Arial,Lucida Grande,sans-serif; background-color: transparent; font-style: normal">How would I do the above when what I would like the user to enter is this <br style="" class=""></div><div class=""
 style="color: rgb(0, 0, 0); font-size: 13.3333px; font-family: HelveticaNeue,Helvetica Neue,Helvetica,Arial,Lucida Grande,sans-serif; background-color: transparent; font-style: normal"><br style="" class=""></div><div class="" style="color: rgb(0, 0, 0); font-size: 13.3333px; font-family: HelveticaNeue,Helvetica Neue,Helvetica,Arial,Lucida Grande,sans-serif; background-color: transparent; font-style: normal">(list (point i j) (point i j))</div><div class="" style="color: rgb(0, 0, 0); font-size: 13.3333px; font-family: HelveticaNeue,Helvetica Neue,Helvetica,Arial,Lucida Grande,sans-serif; background-color: transparent; font-style: normal"><br style="" class=""></div><div class="" style="color: rgb(0, 0, 0); font-size: 13.3333px; font-family: HelveticaNeue,Helvetica Neue,Helvetica,Arial,Lucida Grande,sans-serif; background-color: transparent; font-style: normal">How would mapcar over that to add a c-pointer to every (point i j)  with it being as
 close to a 0(1) operation as poss. so my code doesn't get any slower..(expanded on at bottom of page)<br></div><div class="" style="color: rgb(0, 0, 0); font-size: 13.3333px; font-family: HelveticaNeue,Helvetica Neue,Helvetica,Arial,Lucida Grande,sans-serif; background-color: transparent; font-style: normal"><br style="" class=""></div><div class="" style="color: rgb(0, 0, 0); font-size: 13.3333px; font-family: HelveticaNeue,Helvetica Neue,Helvetica,Arial,Lucida Grande,sans-serif; background-color: transparent; font-style: normal">Pertaining to your other suggestions...I have read the curl doc. twice and still can't figure out how to apply it to my situation. It really helped when you showed me an exact example on the finalizers...I was able to understand that and implement it in my library..Pls excuse the fact that I'm still new to advanced CFFI stuff...but I could use help with exact example on this or the below one(keeping in mind that I would
 probably defer to your best recommendation on which one to implement...I do love my new types:) ):</div><div class="" style="color: rgb(0, 0, 0); font-size: 13.3333px; font-family: HelveticaNeue,Helvetica Neue,Helvetica,Arial,Lucida Grande,sans-serif; background-color: transparent; font-style: normal"><br style="" class=""></div><div class="" style="color: rgb(0, 0, 0); font-size: 13.3333px; font-family: HelveticaNeue,Helvetica Neue,Helvetica,Arial,Lucida Grande,sans-serif; background-color: transparent; font-style: normal"><br style="" class=""></div><div class="" style="color: rgb(0, 0, 0); font-size: 13.3333px; font-family: HelveticaNeue,Helvetica Neue,Helvetica,Arial,Lucida Grande,sans-serif; background-color: transparent; font-style: normal">1.  In my mind, a best practice is that you only call foreign-alloc in<br style="" class="">    `translate-to-foreign` method.<br style="" class=""><br style="" class="">2.  You should
 design a type like `point-vector` with `define-foreign-type`.<br style="" class=""><br style="" class="">3.  The `translate-to-foreign` method should look like:<br style="" class=""><br style="" class="">    (defmethod translate-to-foreign ((lisp-data list) (c-type point-vector))<br style="" class="">       ...)</div><div class="" style="color: rgb(0, 0, 0); font-size: 13.3333px; font-family: HelveticaNeue,Helvetica Neue,Helvetica,Arial,Lucida Grande,sans-serif; background-color: transparent; font-style: normal"><br style="" class=""></div><div class="" style="color: rgb(0, 0, 0); font-size: 13.3333px; font-family: HelveticaNeue,Helvetica Neue,Helvetica,Arial,Lucida Grande,sans-serif; background-color: transparent; font-style: normal"><br style="" class=""></div><div class="" style="color: rgb(0, 0, 0); font-size: 13.3333px; font-family: HelveticaNeue,Helvetica Neue,Helvetica,Arial,Lucida Grande,sans-serif;
 background-color: transparent; font-style: normal"><br style="" class=""></div><div class="" style="color: rgb(0, 0, 0); font-size: 13.3333px; font-family: HelveticaNeue,Helvetica Neue,Helvetica,Arial,Lucida Grande,sans-serif; background-color: transparent; font-style: normal"><br style="" class=""></div><div class="" style="color: rgb(0, 0, 0); font-size: 13.3333px; font-family: HelveticaNeue,Helvetica Neue,Helvetica,Arial,Lucida Grande,sans-serif; background-color: transparent; font-style: normal">or, keeping in mind that I don't want to slow down my code any more, should I convert my defmacro for foreign-alloc which I expose to the users to have a conditional that if it receives a metaobject to add the c-pointer prefixes to them in a fast operation,  keeping in mind the (list ...), if supplied could be infinite...</div><div class="" style="color: rgb(0, 0, 0); font-size: 13.3333px; font-family: HelveticaNeue,Helvetica Neue,Helvetica,Arial,Lucida
 Grande,sans-serif; background-color: transparent; font-style: normal"><br style="" class=""></div><div class="" style="color: rgb(0, 0, 0); font-size: 13.3333px; font-family: HelveticaNeue,Helvetica Neue,Helvetica,Arial,Lucida Grande,sans-serif; background-color: transparent; font-style: normal"><br style="" class=""></div><div class="" style="color: rgb(0, 0, 0); font-size: 13.3333px; font-family: HelveticaNeue,Helvetica Neue,Helvetica,Arial,Lucida Grande,sans-serif; background-color: transparent; font-style: normal">(defmacro alloc (&optional type value)<br style="" class="">       (cond ((listp value)<br style="" class="">          `(foreign-alloc ,type ,:initial-contents ,value))<br style="" class="">         (t `(foreign-alloc ,type ,:initial-element ,value))))<br style="" class=""></div><div style="display: block;" class="yahoo_quoted">
 <div class="" style="font-family: HelveticaNeue, Helvetica Neue, Helvetica, Arial, Lucida Grande, sans-serif; font-size: 10pt"> <div class="" style="font-family: HelveticaNeue, Helvetica Neue, Helvetica, Arial, Lucida Grande, sans-serif; font-size: 12pt"> <div style="" class="" dir="ltr"> <font style="" class="" face="Arial" size="2"> On Tuesday, April 29, 2014 1:51 PM, Willem Rein Oudshoorn <woudshoo@xs4all.nl> wrote:<br style="" class=""> </font> </div> <blockquote class="" style="">  <div style="" class="">Joeish W <<a style="" class="" ymailto="mailto:joeish80829@yahoo.com" href="mailto:joeish80829@yahoo.com">joeish80829@yahoo.com</a>> writes:<br style="" class=""><br style="" class="">> I have this conditional from a cond statement I need to satisfy<br style="" class="">><br style="" class="">><br style="" class="">>     ((listp (first args))<br style="" class="">>     
 (c-arr-to-vector-point (first args)))<br style="" class="">><br style="" class="">><br style="" class="">> The (first args)  will be this but it should be able to have  an infinite number <br style="" class="">> of (point i j) in it.<br style="" class="">><br style="" class="">> (foreign-alloc :pointer :initial-contents  (LIST (POINT 1 2) (POINT 3 4)))<br style="" class=""><br style="" class=""><br style="" class="">Few points:<br style="" class=""><br style="" class="">0.  My gut feeling is that you have actually on the C++ side:<br style="" class="">    vector<Point> and not vector<Point*> so the approach you are taking<br style="" class="">    will not work.   However if you are talking about vector<Point*><br style="" class="">    (or you C wrapper takes as type:   Point*[].  The following points<br style="" class="">    should guide
 you.<br style="" class=""><br style="" class="">1.  In my mind, a best practice is that you only call foreign-alloc in<br style="" class="">    `translate-to-foreign` method.<br style="" class=""><br style="" class="">2.  You should design a type like `point-vector` with `define-foreign-type`.<br style="" class=""><br style="" class="">3.  The `translate-to-foreign` method should look like:<br style="" class=""><br style="" class="">    (defmethod translate-to-foreign ((lisp-data list) (c-type point-vector))<br style="" class="">       ...)<br style="" class=""><br style="" class="">4.  For memory management you should also implement a suitable version of:<br style="" class=""><br style="" class="">     (defmethod free-translated-object (c-data (c-type point-vector) extra-data)<br style="" class="">         ...)<br style="" class=""><br style="" class=""><br style=""
 class="">However I cannot expand on this right now.  But this should give you<br style="" class="">pointers on how to start.  <br style="" class="">I strongly recommend reading the CFFI manual including the chapter<br style="" class="">describing the example on how to wrap the curl library.<br style="" class=""><br style="" class="">    <br style="" class="">><br style="" class="">><br style="" class="">> The thing is that the output of (point i j) is a metaobject<br style="" class="">> e.g. #<CV-POINT {10038888E3}> . That is how I have my return for point<br style="" class="">> defined. When I need to use foreign-alloc to define an array of point<br style="" class="">> I have to  do it like this...<br style="" class="">><br style="" class="">><br style="" class="">> (foreign-alloc :pointer :initial-contents  (LIST (c-pointer (POINT 1 2)) (c-pointer (POINT 3 4))))<br style="" class=""><br
 style="" class="">Or like this:<br style="" class=""><br style="" class="">(foreign-alloc :pointer :initial-contents <br style="" class="">  (mapcar (p) (c-pointer (point (car p) (cdr p))))<br style="" class=""> '((1 . 2) (3 . 4) ...))<br style="" class=""><br style="" class=""><br style="" class=""><br style="" class=""><br style="" class="">> (defun vector-point (&rest args)<br style="" class="">>   (cond<br style="" class="">>     ((fourth args)<br style="" class="">>      (error "odd number of args to VECTOR-POINT"))<br style="" class="">>     ((null (first args))<br style="" class="">>      (%vector-point))<br style="" class="">>     ((listp (first args))<br style="" class="">>      (%c-arr-to-vector-point (foreign-alloc :pointer :initial-contents (first args))))<br style="" class="">>    
 ((eq :size (second args))<br style="" class="">>      (%vector-point-size (first args)))<br style="" class="">>     ((and (eq (type-of (first args)) 'std-vector-point) (second args) (not (third args))) <br style="" class="">>      (mem-aref (c-pointer <br style="" class="">>         (%vector-point-to-c-array (first args))) :pointer (second args)))<br style="" class="">>     ((and (eq (type-of (first args)) 'std-vector-point) (second args) (third args)) <br style="" class="">>      (mem-aref (c-pointer <br style="" class="">>         (mem-aref (c-pointer <br style="" class="">>                (%vector-point-to-c-array (first args))) :pointer (second args))) <br style="" class="">>    
        :int (third args)))<br style="" class="">>     ((not (eq (type-of (first args)) 'std-vector-point))<br style="" class="">>      (error "The value ~a is not of type (STD-VECTOR-POINT)." (first args)))))<br style="" class=""><br style="" class="">I suggest reading up on keyword arguments and optional arguments.  <br style="" class="">This is not really understandable.  <br style="" class=""><br style="" class="">Wim Oudshoorn<br style="" class=""><br style="" class=""><br style="" class="">_______________________________________________<br style="" class="">Cffi-devel mailing list<br style="" class=""><a style="" class="" ymailto="mailto:Cffi-devel@common-lisp.net" href="mailto:Cffi-devel@common-lisp.net">Cffi-devel@common-lisp.net</a><br style="" class=""><a style="" class="" href="http://common-lisp.net/cgi-bin/mailman/listinfo/cffi-devel"
 target="_blank">http://common-lisp.net/cgi-bin/mailman/listinfo/cffi-devel</a><br style="" class=""><br style="" class=""><br style="" class=""></div> </blockquote>  </div> </div>   </div> </div></body></html>