[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Recursive call of a macro-function
- To: clisp-list@ma2s2.mathematik.uni-karlsruhe.de
- Subject: Recursive call of a macro-function
- From: lemeunie@lium.univ-lemans.fr (Thierry Lemeunier (LIUM))
- Date: Fri, 6 Dec 1996 16:43:51 GMT
Hello,
I want to generalize the next method "construit-ksar" (a method to make ksar on a little blackboard)
by using a macro-function. This first method run with only 3 variables (ecs) and I want to make a macro which
expand a function for an undefined number of variables.
My problem:
-----------
The macro-function is recursive and I think there is a big problem with its environment (&environment ??)
Has anyone been succesful in using a recursive macro call ?
Please help me !!!!!!
; --------------------------------------------------------------------------------------------------------------------
; The original method for only 3 variables:
(defmethod construit-ksar ((oself KSOURCE))
(case (length (ecs-de oself))
(1 (loop for -var in (pile-de (car (ecs-de oself))) when
(funcall (condition-de oself) -var) do
(cree-ksar :ksource oself
:valeurs (list -var)
:interet (* (interet-de oself) (interet-de -var)))))
(2 (loop for -var1 in (pile-de (car (ecs-de oself))) do
(loop for -var2 in (pile-de (cadr (ecs-de oself))) when
(funcall (condition-de oself) -var1 -var2) do
(cree-ksar :ksource oself
:valeurs (list -var1 -var2)
:interet (* (interet-de oself) (interet-de -var1) (interet-de -var2))))))
(3 (loop for -var1 in (pile-de (car (ecs-de oself))) do
(loop for -var2 in (pile-de (cadr (ecs-de oself))) do
(loop for -var3 in (pile-de (caddr (ecs-de oself))) when
(funcall (condition-de oself) -var1 -var2 -var3) do
(cree-ksar :ksource oself
:valeurs (list -var1 -var2 -var3)
:interet (* (interet-de oself) (interet-de -var1) (interet-de -var2)
(interet-de -var3)))))))
(t (error "CONSTRUIT-KSAR: Les sources de connaissance ne doivent pas contenir plus de trois variables"))))
; --------------------------------------------------------------------------------------------------------------------
; The macro-function that doesn't work:
(defmethod construit-ksar ((oself KSOURCE))
(macro-construit-ksar oself (ecs-de oself) (list (gensym))))
(defmacro macro-construit-ksar (-ksource -conditions -variables)
(if (cdr -conditions)
`(loop for ,(car -variables) in (pile-de ,(car -conditions)) do
(macro-construit-ksar ,-ksource (cdr ,-conditions) (cons (gensym) ,-variables)))
`(loop for ,(car -variables) in (pile-de ,(car -conditions)) when
(funcall (condition-de ,-ksource) ,@-variables) do
(cree-ksar :ksource ,-ksource
:valeurs ,-variables))))
:interet ,(* (interet-de -ksource) (apply #'* (mapcar #'interet-de -variables)))))))
; --------------------------------------------------------------------------------------------------------------------
-------------------------------------------------------------------------
Thierry LEMEUNIER _/ _/ _/_/ _/_/_/ _/
groupe Langue et Dialogue _/ _/ _/ _/ _/ _/ _/ _/
_/ _/ _/ _/ _/ _/ _/ _/
Laboratoire d'Informatique _/ _/_/_/_/ _/ _/ _/ _/_/_/_/
UFR Sciences _/_/_/ _/ _/ _/_/_/ _/_/_/ _/ _/
Universite du Maine
Avenue Olivier Messiaen BP535 email : lemeunie@lium.univ-lemans.fr
F72017 LE MANS CEDEX web : http://bigiup.univ-lemans.fr/
-------------------------------------------------------------------------