Scheme ãã表ç¾åã®å£ã Smalltalk ã«ç§»ããã¨ããã°ãå½ç¶ãããããã¨æãè½ã¡ã¦ãã¾ããçµæã¨ãã¦èº«ãèããªããªã£ã¡ãã£ã¦ãããã®ã§ããâ¦ãã¾ãããã¯ããã¨ãã¦(^_^;)ãå人çã«ã¯ nfunato ããã®ããæ°ã«å
¥ãã§ãã
ããã«ã¤ãã¦ããcopy fixTemps ã ããã§ãSqueak Smalltalk ã®ãããã¯ã§å帰ãªããããããããããªãã§ãããorzï¼ãã©ãããã§ãããaBlock copy fixTemps ã¨ããã®ã¯ããã®ã¾ã¾ã§ã¯åå
¥ã»å帰ãã§ããªã Squeak ã®ãããã¯ã§ãèªèº«ã¨ç°å¢ã®ã³ãã¼ãè¡ãªãããã®ä½æ¥ã§ãããã¡ãããç¡å颿°ã¨ãã¦ã®ãããã¯ãã¯ãã¼ã¸ã£ã§å®ç¾ããã¦ããé常㮠Smalltalk ã§ã¯ä¸è¦ï¼ã
â¼ idï¼scinfaxi ããã®
| tree result loop | tree := #(Root (Spine (Neck (Head)) (RClavicle (RUpperArm (RLowerArm (RHand)))) (LClavicle (LUpperArm (LLowerArm (LHand))))) (RHip (RUpperLeg (RLowerLeg (RFoot)))) (LHip (LUpperLeg (LLowerLeg (LFoot))))). result := OrderedCollection new. loop := [:xs :parent | xs allButFirst isEmpty ifTrue: [nil] ifFalse: [ xs allButFirst do: [:x | parent ifNotNil: [result add: x first -> parent]. loop copy fixTemps valueWithArguments: {x. xs first}]]]. loop copy fixTemps valueWithArguments: {tree. #f}. ^result
â¼ Pla ããã®
| tree result loop | tree := #(Root (Spine (Neck (Head)) (RClavicle (RUpperArm (RLowerArm (RHand)))) (LClavicle (LUpperArm (LLowerArm (LHand))))) (RHip (RUpperLeg (RLowerLeg (RFoot)))) (LHip (LUpperLeg (LLowerLeg (LFoot))))). result := OrderedCollection new. loop := [:tr | | parent children | tr size > 1 ifTrue: [ parent := tr first. children := tr allButFirst. children do: [:child | loop copy fixTemps value: child. result add: child first -> parent]]]. loop copy fixTemps value: tree. ^result
â¼ naoya_t ããã®
| tree appendMap itr foo2 foo3 | tree := #(Root (Spine (Neck (Head)) (RClavicle (RUpperArm (RLowerArm (RHand)))) (LClavicle (LUpperArm (LLowerArm (LHand))))) (RHip (RUpperLeg (RLowerLeg (RFoot)))) (LHip (LUpperLeg (LLowerLeg (LFoot))))). appendMap := [:proc :l | (l collect: proc) inject: OrderedCollection new into: [:colln :each | colln addAll: each; yourself]]. "foo1" itr := [:p :t | {t first -> p}, ( t allButFirst ifEmpty: [#()] ifNotEmpty: [ appendMap copy fixTemps value: [:x | itr copy fixTemps value: t first value: x] value: t allButFirst])]. appendMap copy fixTemps value: [:x | itr copy fixTemps value: tree first value: x] value: tree allButFirst. foo2 := [:l | | parent children | parent := l first. children := l allButFirst. appendMap copy fixTemps value: [:child | {child first -> parent}, ( child allButFirst isEmpty ifTrue: [#()] ifFalse: [ foo2 copy fixTemps value: child])] value: children]. foo2 copy fixTemps value: tree. foo3 := [:l | appendMap copy fixTemps value: [:child | {child first -> l first}, ( child allButFirst isEmpty ifTrue: [#()] ifFalse: [ foo3 copy fixTemps value: child])] value: l allButFirst]. foo3 copy fixTemps value: tree "foo4 ã¯çç¥ "
â¼ Shiro ããã®
| tree rec | tree := #(Root (Spine (Neck (Head)) (RClavicle (RUpperArm (RLowerArm (RHand)))) (LClavicle (LUpperArm (LLowerArm (LHand))))) (RHip (RUpperLeg (RLowerLeg (RFoot)))) (LHip (LUpperLeg (LLowerLeg (LFoot))))). "get-parent-alist" rec := [:p :t :s | | n ts | n := t first. ts := t allButFirst. {n -> p}, (ts inject: s into: [:result :each | rec copy fixTemps valueWithArguments: {n. each. result}])]. ^tree allButFirst inject: #() into: [:result :each | rec copy fixTemps valueWithArguments: {tree first. each. result}]
â¼ nfunato ããã®
| tree getParentAlist gather build | tree := #(Root (Spine (Neck (Head)) (RClavicle (RUpperArm (RLowerArm (RHand)))) (LClavicle (LUpperArm (LLowerArm (LHand))))) (RHip (RUpperLeg (RLowerLeg (RFoot)))) (LHip (LUpperLeg (LLowerLeg (LFoot))))). getParentAlist := [:p | (p allButFirst collect: [:c | c first -> p first]), (p allButFirst collect: getParentAlist copy fixTemps) concatenation]. getParentAlist copy fixTemps value: tree. "Shiroããã®ãå ã«ãããã®" build := nil. gather := [:p :soFar | p allButFirst inject: soFar into: [:result :each | build copy fixTemps valueWithArguments: {p. each. result}]]. build := [:p :c :soFar | {c first -> p first}, (gather copy fixTemps value: c value: soFar)]. gather copy fixTemps value: tree value: #()
â¼ nobsun ããã®
| tree appendMap dfs chpa | tree := #(Root (Spine (Neck (Head)) (RClavicle (RUpperArm (RLowerArm (RHand)))) (LClavicle (LUpperArm (LLowerArm (LHand))))) (RHip (RUpperLeg (RLowerLeg (RFoot)))) (LHip (LUpperLeg (LLowerLeg (LFoot))))). appendMap := [:proc :l | (l collect: proc) inject: OrderedCollection new into: [:colln :each | colln addAll: each; yourself]]. dfs := [:t | {t}, (appendMap copy fixTemps value: dfs copy fixTemps value: t allButFirst)]. "tree-child-parent-list" chpa := [:t | | p cs | p := t first. cs := t allButFirst. (cs collect: [:each | each first]) collect: [:each | each -> p]]. appendMap copy fixTemps value: chpa copy fixTemps value: (dfs copy fixTemps value: tree)