compute-cplãèªã
Gaucheã®class.cããå¼ç¨ï¼
/* * compute-cpl */ ScmObj Scm_ComputeCPL(ScmClass *klass) { ScmObj seqh = SCM_NIL, seqt = SCM_NIL, ds, dp, result; /* a trick to ensure we have <object> <top> at the end of CPL. */ ds = Scm_Delete(SCM_OBJ(SCM_CLASS_OBJECT), klass->directSupers, SCM_CMP_EQ); ds = Scm_Delete(SCM_OBJ(SCM_CLASS_TOP), ds, SCM_CMP_EQ); ds = Scm_Append2(ds, SCM_LIST1(SCM_OBJ(SCM_CLASS_OBJECT))); SCM_FOR_EACH(dp, klass->directSupers) { if (!Scm_TypeP(SCM_CAR(dp), SCM_CLASS_CLASS)) Scm_Error("non-class found in direct superclass list: %S", klass->directSupers); if (SCM_CAR(dp) == SCM_OBJ(SCM_CLASS_OBJECT) || SCM_CAR(dp) == SCM_OBJ(SCM_CLASS_TOP)) continue; SCM_APPEND1(seqh, seqt, SCM_CLASS(SCM_CAR(dp))->cpl); } SCM_APPEND1(seqh, seqt, Scm_ObjectClass.cpl); SCM_APPEND1(seqh, seqt, ds); result = Scm_MonotonicMerge1(seqh); if (SCM_FALSEP(result)) Scm_Error("discrepancy found in class precedence lists of the superclasses: %S", klass->directSupers); return Scm_Cons(SCM_OBJ(klass), result); }
trické¢ä¿ã£ã½ãã®ã¨ã¨ã©ã¼ãã§ãã¯ãåãé¤ãã¨
/* * compute-cpl */ ScmObj Scm_ComputeCPL(ScmClass *klass) { ScmObj seqh = SCM_NIL, seqt = SCM_NIL, ds, dp, result; ds = klass->directSupers; SCM_FOR_EACH(dp, klass->directSupers) { SCM_APPEND1(seqh, seqt, SCM_CLASS(SCM_CAR(dp))->cpl); } SCM_APPEND1(seqh, seqt, ds); result = Scm_MonotonicMerge1(seqh); return Scm_Cons(SCM_OBJ(klass), result); }
ãããªæãï¼
SCM_APPEND1
ã¯gauche.hã«ï¼Scm_Delete
ï¼Scm_Append2
ï¼Scm_MonotonicMerge1
ã¯list.cã«å®ç¾©ããã¦ããï¼
ç´æ¥ã¹ã¼ãã¼ã¯ã©ã¹ã®CPLã®ãªã¹ãã«ç´æ¥ã¹ã¼ãã¼ã¯ã©ã¹ã®ãªã¹ããappendãã¦mergeï¼mergeã®æåã¯å¤§ã¾ãã«ãããªæãï¼
(monotonic-merge '((a b) (c d))) ; => (a b c d) (monotonic-merge '((a b) (c b))) ; => (a c b) (monotonic-merge '((a c) (b c))) ; => (a b c) (monotonic-merge '((a b) (b a))) ; => #f
ãã®mergeãã¢ã«ã´ãªãºã ã®æ ¸ãªæ°ãããï¼ããããMonotonic Mergeã®ã³ã¡ã³ãã®æã«
* The algorithm is used in C3 linearization of class precedence * calculation
ã¨æ¸ãã¦ãã£ãï¼Scm_MonotonicMerge1
ã®ä¸èº«ã¯ããããããã§ããï¼ãã¼ãï¼