ä¸ããããæ¨ãããåâ親ã¸ã®å¯¾å¿ãä½ã
æ¨æ§é ãä¸ããããã
http://practical-scheme.net/wiliki/wiliki.cgi?Scheme%3a%e3%83%aa%e3%82%b9%e3%83%88%e5%87%a6%e7%90%86#H-ne4pu7
:= ( ...) ã¨ããæ§é ã
ãããããåâ親ã®å¯¾å¿ã表ãalistãä½ãæç¶ããæ¸ããã¨ãããã®ã
ãã®åé¡ããã£ã¦ã¿ã
(use util.match) (define *tree* '(Root (Spine (Neck (Head)) (RClavicle (RUpperArm (RLowerArm (RHand)))) (LClavicle (LUpperArm (LLowerArm (LHand))))) (RHip (RUpperLeg (RLowerLeg (RFoot)))) (LHip (LUpperLeg (LLowerLeg (LFoot)))))) (define foo (match-lambda ((_) ()) ((p (c . cs) . ps) `(,(cons c p) ,@(foo (cons c cs)) ,@(foo (cons p ps))))))
å®è¡çµæ
gosh> (foo *tree*) ((Spine . Root) (Neck . Spine) (Head . Neck) (RClavicle . Spine) (RUpperArm . RClavicle) (RLowerArm . RUpperArm) (RHand . RLowerArm) (LClavicle . Spine) (LUpperArm . LClavicle) (LLowerArm . LUpperArm) (LHand . LLowerArm) (RHip . Root) (RUpperLeg . RHip) (RLowerLeg . RUpperLeg) (RFoot . RLowerLeg) (LHip . Root) (LUpperLeg . LHip) (LLowerLeg . LUpperLeg) (LFoot . LLowerLeg))