Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Object subclass: #'TorusPoint' instanceVariableNames: 'pos torus' classVariableNames: '' poolDictionaries: ''.
- Object subclass: #'Torus' instanceVariableNames: 'valDict dimensions' classVariableNames: '' poolDictionaries: ''.
- Collection subclass: #'TorusPath' instanceVariableNames: '' classVariableNames: '' poolDictionaries: ''.
- TorusPath subclass: #'TorusPathLoop' instanceVariableNames: 'point direction value' classVariableNames: '' poolDictionaries: ''.
- TorusPath subclass: #'TorusPathBlock' instanceVariableNames: 'point block' classVariableNames: '' poolDictionaries: ''.
- TorusPath subclass: #'TorusPathCons' instanceVariableNames: 'lhs rhs' classVariableNames: '' poolDictionaries: ''.
- TorusPath subclass: #'TorusPathMap' instanceVariableNames: 'path block' classVariableNames: '' poolDictionaries: ''.
- "=================================================TORUS============================================="
- Torus compile:
- 'init
- valDict := Dictionary new'.
- Torus compile:
- 'dimensions: d
- dimensions := d'.
- Torus compile:
- 'dimensions
- ^dimensions'.
- Torus compile:
- 'value: pos
- ^valDict at: pos ifAbsent: [nil]'.
- Torus compile:
- 'value: pos put: val
- ^valDict at: pos put: val'.
- Torus class compile:
- 'shape: s
- |t|
- t := (self new) dimensions: s; init; yourself.
- ^(TorusPoint new) pos: (Array new: (s size) withAll: 0); torus: t; yourself'.
- "=================================================TORUS POINT============================================="
- TorusPoint compile:
- 'pos: p
- pos := p'.
- TorusPoint compile:
- 'torus: t
- torus := t'.
- TorusPoint compile:
- 'torus
- ^torus'.
- TorusPoint compile:
- 'pos
- ^pos'.
- TorusPoint compile:
- 'value
- ^torus value: pos'.
- TorusPoint compile:
- 'value: v
- Transcript show: v printString.
- torus value: pos put: v'.
- TorusPoint compile:
- 'printOn: s
- (self value) printOn: s'.
- TorusPoint compile:
- '+ j
- |val ins |
- ^(j > 0)
- ifTrue: [
- val := ((pos at: j) + 1) \\ (torus dimensions at: j).
- ^TorusPoint new pos: (pos copy at: j put: val; yourself); torus: torus; yourself.
- ]
- ifFalse: [
- (j < 0)
- ifTrue: [
- val := ((pos at: j negated) - 1) \\ (torus dimensions at: j negated).
- ^TorusPoint new pos: (pos copy at: j negated put: val; yourself); torus: torus; yourself.
- ]
- ifFalse: [^self]
- ]'.
- TorusPoint compile:
- '- j
- ^self + j negated'.
- TorusPoint compile:
- '@ v
- |ins|
- ins := self copy.
- 1 to: (v size) do: [:i |
- |val|
- val := ((pos at: i) + (v at: i)) \\ (torus dimensions at: i).
- ins pos at: i put: val
- ].
- ^ins'.
- TorusPoint compile:
- '| j
- |len|
- (j == 0) ifTrue: [len := 1] ifFalse: [len := torus dimensions at: (j abs)].
- ^TorusPathLoop point: self direction: j value: len'.
- TorusPoint compile:
- '% a
- ^TorusPathLoop point: self direction: a value value: a key'.
- TorusPoint compile:
- '& b
- ^ TorusPathBlock point: self block: b'.
- "=================================================TORUS PATH============================================="
- TorusPath compile:
- ', rhs
- ^TorusPathCons lhs: self rhs: rhs'.
- TorusPath compile:
- '| x
- ^TorusPathMap path: self block: [:p | p | x]'.
- TorusPath compile:
- '% x
- ^TorusPathMap path: self block: [:p | p % x]'.
- TorusPath compile:
- 'species
- ^OrderedCollection'.
- TorusPath class compile:
- 'new
- ^self shouldNotImplement'.
- TorusPath class compile:
- 'new: k
- ^self shouldNotImplement'.
- TorusPath compile:
- 'add: x
- ^self shouldNotImplement'.
- TorusPath compile:
- 'remove: x ifAbsent: y
- ^self shouldNotImplement'.
- TorusPath compile:
- 'first: anInteger
- | answer i |
- answer := OrderedCollection new.
- anInteger > 0 ifFalse: [^answer].
- i := anInteger.
- self do:
- [:each |
- answer add: each.
- i := i - 1.
- i = 0 ifTrue: [^answer]].
- ^answer'.
- "=================================================TORUS PATH LOOP============================================="
- TorusPathLoop compile:
- 'do: aBlock
- (direction == 0) ifTrue: [aBlock value: point]
- ifFalse: [
- | p |
- p := point.
- 1 to: value do: [:_ |
- aBlock value: p.
- p := p + direction.
- ].
- ]'.
- TorusPathLoop compile:
- 'point: p direction: d value: v
- point := p.
- direction := d.
- value := v'.
- TorusPathLoop class compile:
- 'point: p direction: d value: v
- ^(super basicNew) point: p direction: d value: v; yourself'.
- "=================================================TORUS PATH CONS============================================="
- TorusPathCons compile:
- 'lhs: l rhs: r
- lhs := l.
- rhs := r'.
- TorusPathCons compile:
- 'do: aBlock
- lhs do: aBlock.
- rhs do: aBlock'.
- TorusPathCons class compile:
- 'lhs: l rhs: r
- ^(super basicNew) lhs: l rhs: r'.
- "=================================================TORUS PATH BLOCK============================================="
- TorusPathBlock compile:
- 'point: p block: b
- point := p.
- block := b'.
- TorusPathBlock compile:
- 'do: aBlock
- | val |
- aBlock value: point.
- val := block value: point.
- (val ~= nil) ifTrue: [ val do: aBlock ]'.
- TorusPathBlock class compile:
- 'point: p block: b
- ^(super basicNew) point: p block: b; yourself'.
- "=================================================TORUS PATH MAP============================================="
- TorusPathMap compile:
- 'path: p block: b
- path := p.
- block := b'.
- TorusPathMap compile:
- 'do: aBlock
- path do: [:p | (block value: p) do: aBlock]'.
- TorusPathMap class compile:
- 'path: p block: b
- ^(super basicNew) path: p block: b; yourself'.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement