Advertisement
Guest User

Untitled

a guest
Jun 28th, 2016
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.18 KB | None | 0 0
  1. Object subclass: #'TorusPoint' instanceVariableNames: 'pos torus' classVariableNames: '' poolDictionaries: ''.
  2. Object subclass: #'Torus' instanceVariableNames: 'valDict dimensions' classVariableNames: '' poolDictionaries: ''.
  3. Collection subclass: #'TorusPath' instanceVariableNames: '' classVariableNames: '' poolDictionaries: ''.
  4. TorusPath subclass: #'TorusPathLoop' instanceVariableNames: 'point direction value' classVariableNames: '' poolDictionaries: ''.
  5. TorusPath subclass: #'TorusPathBlock' instanceVariableNames: 'point block' classVariableNames: '' poolDictionaries: ''.
  6. TorusPath subclass: #'TorusPathCons' instanceVariableNames: 'lhs rhs' classVariableNames: '' poolDictionaries: ''.
  7. TorusPath subclass: #'TorusPathMap' instanceVariableNames: 'path block' classVariableNames: '' poolDictionaries: ''.
  8. "=================================================TORUS============================================="
  9. Torus compile:
  10. 'init
  11. valDict := Dictionary new'.
  12. Torus compile:
  13. 'dimensions: d
  14. dimensions := d'.
  15. Torus compile:
  16. 'dimensions
  17. ^dimensions'.
  18. Torus compile:
  19. 'value: pos
  20. ^valDict at: pos ifAbsent: [nil]'.
  21. Torus compile:
  22. 'value: pos put: val
  23. ^valDict at: pos put: val'.
  24. Torus class compile:
  25. 'shape: s
  26. |t|
  27. t := (self new) dimensions: s; init; yourself.
  28. ^(TorusPoint new) pos: (Array new: (s size) withAll: 0); torus: t; yourself'.
  29. "=================================================TORUS POINT============================================="
  30. TorusPoint compile:
  31. 'pos: p
  32. pos := p'.
  33. TorusPoint compile:
  34. 'torus: t
  35. torus := t'.
  36. TorusPoint compile:
  37. 'torus
  38. ^torus'.
  39. TorusPoint compile:
  40. 'pos
  41. ^pos'.
  42. TorusPoint compile:
  43. 'value
  44. ^torus value: pos'.
  45. TorusPoint compile:
  46. 'value: v
  47. Transcript show: v printString.
  48. torus value: pos put: v'.
  49. TorusPoint compile:
  50. 'printOn: s
  51. (self value) printOn: s'.
  52. TorusPoint compile:
  53. '+ j
  54. |val ins |
  55. ^(j > 0)
  56. ifTrue: [
  57. val := ((pos at: j) + 1) \\ (torus dimensions at: j).
  58. ^TorusPoint new pos: (pos copy at: j put: val; yourself); torus: torus; yourself.
  59. ]
  60. ifFalse: [
  61. (j < 0)
  62. ifTrue: [
  63. val := ((pos at: j negated) - 1) \\ (torus dimensions at: j negated).
  64. ^TorusPoint new pos: (pos copy at: j negated put: val; yourself); torus: torus; yourself.
  65. ]
  66. ifFalse: [^self]
  67. ]'.
  68. TorusPoint compile:
  69. '- j
  70. ^self + j negated'.
  71. TorusPoint compile:
  72. '@ v
  73. |ins|
  74. ins := self copy.
  75. 1 to: (v size) do: [:i |
  76. |val|
  77. val := ((pos at: i) + (v at: i)) \\ (torus dimensions at: i).
  78. ins pos at: i put: val
  79. ].
  80. ^ins'.
  81. TorusPoint compile:
  82. '| j
  83. |len|
  84. (j == 0) ifTrue: [len := 1] ifFalse: [len := torus dimensions at: (j abs)].
  85. ^TorusPathLoop point: self direction: j value: len'.
  86. TorusPoint compile:
  87. '% a
  88. ^TorusPathLoop point: self direction: a value value: a key'.
  89. TorusPoint compile:
  90. '& b
  91. ^ TorusPathBlock point: self block: b'.
  92. "=================================================TORUS PATH============================================="
  93. TorusPath compile:
  94. ', rhs
  95. ^TorusPathCons lhs: self rhs: rhs'.
  96. TorusPath compile:
  97. '| x
  98. ^TorusPathMap path: self block: [:p | p | x]'.
  99. TorusPath compile:
  100. '% x
  101. ^TorusPathMap path: self block: [:p | p % x]'.
  102. TorusPath compile:
  103. 'species
  104. ^OrderedCollection'.
  105. TorusPath class compile:
  106. 'new
  107. ^self shouldNotImplement'.
  108. TorusPath class compile:
  109. 'new: k
  110. ^self shouldNotImplement'.
  111. TorusPath compile:
  112. 'add: x
  113. ^self shouldNotImplement'.
  114. TorusPath compile:
  115. 'remove: x ifAbsent: y
  116. ^self shouldNotImplement'.
  117. TorusPath compile:
  118. 'first: anInteger
  119. | answer i |
  120. answer := OrderedCollection new.
  121. anInteger > 0 ifFalse: [^answer].
  122. i := anInteger.
  123. self do:
  124. [:each |
  125. answer add: each.
  126. i := i - 1.
  127. i = 0 ifTrue: [^answer]].
  128. ^answer'.
  129. "=================================================TORUS PATH LOOP============================================="
  130. TorusPathLoop compile:
  131. 'do: aBlock
  132. (direction == 0) ifTrue: [aBlock value: point]
  133. ifFalse: [
  134. | p |
  135. p := point.
  136. 1 to: value do: [:_ |
  137. aBlock value: p.
  138. p := p + direction.
  139. ].
  140. ]'.
  141. TorusPathLoop compile:
  142. 'point: p direction: d value: v
  143. point := p.
  144. direction := d.
  145. value := v'.
  146. TorusPathLoop class compile:
  147. 'point: p direction: d value: v
  148. ^(super basicNew) point: p direction: d value: v; yourself'.
  149. "=================================================TORUS PATH CONS============================================="
  150. TorusPathCons compile:
  151. 'lhs: l rhs: r
  152. lhs := l.
  153. rhs := r'.
  154. TorusPathCons compile:
  155. 'do: aBlock
  156. lhs do: aBlock.
  157. rhs do: aBlock'.
  158. TorusPathCons class compile:
  159. 'lhs: l rhs: r
  160. ^(super basicNew) lhs: l rhs: r'.
  161. "=================================================TORUS PATH BLOCK============================================="
  162. TorusPathBlock compile:
  163. 'point: p block: b
  164. point := p.
  165. block := b'.
  166. TorusPathBlock compile:
  167. 'do: aBlock
  168. | val |
  169. aBlock value: point.
  170. val := block value: point.
  171. (val ~= nil) ifTrue: [ val do: aBlock ]'.
  172. TorusPathBlock class compile:
  173. 'point: p block: b
  174. ^(super basicNew) point: p block: b; yourself'.
  175. "=================================================TORUS PATH MAP============================================="
  176. TorusPathMap compile:
  177. 'path: p block: b
  178. path := p.
  179. block := b'.
  180. TorusPathMap compile:
  181. 'do: aBlock
  182. path do: [:p | (block value: p) do: aBlock]'.
  183. TorusPathMap class compile:
  184. 'path: p block: b
  185. ^(super basicNew) path: p block: b; yourself'.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement