help overloading 2 functions in Lisp with optional parameter

Discussion of Common Lisp

help overloading 2 functions in Lisp with optional parameter

Postby joeish80829 » Sat Apr 12, 2014 5:22 pm

I have the 2 defcfuns below and the 2 defun's with &optional params to go with them. I'm trying to write a function called NORM that will run either NORM0 or NORM4 based on the parameters entered. My half a NORM funtion is at the bottom of the page:), still incomplete. Since both functions have 2 optional params a piece I cant wrap my head around how to write the cond function for it. I was hoping someone could show me how to do it. If I could incorporate the optional params into the NORM function so it could just call the defcfuns without calling the intermediary NORM0 or NORM4 defuns, that would be best...Any help is appreciated,
Code: Select all
;;double norm(InputArray src1, int normType=NORM_L2, InputArray mask=noArray())
;;double cv_norm(Mat* src1, int normType, Mat* mask)
(defcfun ("cv_norm" %norm0) :void
    (src1 (:pointer mat))
    (norm-type :int)
    (mask (:pointer mat)))

(defun norm0 (src1 &optional (norm-type +norm-l2+) (mask (mat)))
  (%norm0 src1 norm-type mask))


;;double norm(InputArray src1, InputArray src2, int normType=NORM_L2, InputArray mask=noArray())
;;double cv_norm4(Mat* src1, Mat* src2, int normType, Mat* mask)
(defcfun ("cv_norm4" %norm4) :void
    (src1 (:pointer mat))
     (src2 (:pointer mat))
    (norm-type :int)
    (mask (:pointer mat)))

(defun norm4 (src1 src2 &optional (norm-type +norm-l2+) (mask (mat)))
  (%norm4 src1 src2 norm-type mask))




(defun norm (&optional arg1 arg2 ar3 arg4)
      (cond ((numberp arg2)
        (norm0 arg1 arg2 arg3))
       ((...)
        (norm4 ...))
       (t nil)))
joeish80829
 
Posts: 153
Joined: Tue Sep 03, 2013 5:32 am

Return to Common Lisp

Who is online

Users browsing this forum: No registered users and 2 guests