'From Squeak2.7 of 5 January 2000 [latest update: #1762] on 14 May 2003 at 6:18:02 pm'! UndefinedObject subclass: #Trampoline instanceVariableNames: 'collection iterationMessage ' classVariableNames: '' poolDictionaries: '' category: 'Collections-Support'! !Collection methodsFor: 'enumerating' stamp: 'mpw 1/1/1901 00:17'! collect ^(Trampoline new) collection:self; iterationSelector:#collect:. ! ! !Collection methodsFor: 'enumerating' stamp: 'mpw 1/1/1901 00:17'! do ^(Trampoline new) collection:self; iterationSelector:#do:. ! ! !Collection methodsFor: 'enumerating' stamp: 'apb 3/3/2000 12:29'! inject: thisValue | msg | msg _ Message selector:#inject:into: arguments:(Array with:thisValue with:nil). ^(Trampoline new) collection:self; iterationMessage:msg. ! ! !Collection methodsFor: 'enumerating' stamp: 'mpw 1/1/1901 21:43'! reject ^(Trampoline new) collection:self; iterationSelector:#reject:. ! ! !Collection methodsFor: 'enumerating' stamp: 'mpw 1/1/1901 00:17'! select ^(Trampoline new) collection:self; iterationSelector:#select:. ! ! !Integer methodsFor: 'testing' stamp: 'apb 2/10/2000 11:50'! isPrime "Answers true if I am prime" "Examples: (510510 isPrime) which should answer false (49999 isPrime), which should answer true" | primes | self > 1000000 ifTrue: [self error: 'please use a better algorithm for larger integers']. primes _ Integer primesUpTo: self sqrt. ^ (primes anySatisfy: [:p | self \\ p = 0]) not! ! !Integer methodsFor: 'testing' stamp: 'apb 2/10/2000 11:44'! primeFactors "Answers a collection containing my prime factors, excluding 1 and myself" "Example: (510510 primeFactors) which should answer (2 3 5 7 11 13 17 )" | primes | self > 1000000 ifTrue:[ self error: 'please use a better algorithm for larger integers']. primes _ Integer primesUpTo: self sqrt. ^primes select: [:p | self \\ p = 0].! ! !Message methodsFor: 'sending' stamp: 'mpw 1/1/1901 00:22'! value:receiver lookupClass _ nil. ^self sentTo:receiver. ! ! !Message methodsFor: 'sending' stamp: 'mpw 1/1/1901 20:27'! value:receiver value:arg1 args at:1 put:arg1. ^self value:receiver. ! ! !Symbol methodsFor: 'block compatibility' stamp: 'mpw 1/1/1901 00:01'! value:receiver ^receiver perform:self. ! ! !Symbol methodsFor: 'block compatibility' stamp: 'mpw 1/1/1901 01:38'! value:receiver value:arg ^receiver perform:self with:arg. ! ! !Trampoline reorganize! ('printing' printOn: storeOn:) ('initialization' collection: iterationMessage: iterationSelector:) ('forwarding' doesNotUnderstand:) ('as yet unclassified') ! !Trampoline methodsFor: 'printing' stamp: 'apb 2/9/2000 21:26'! printOn: aStream self perform: #printOn: withArguments: { aStream } inSuperclass: Object. ! ! !Trampoline methodsFor: 'printing' stamp: 'apb 2/9/2000 21:27'! storeOn: aStream self perform: #storeOn: withArguments: { aStream } inSuperclass: Object. ! ! !Trampoline methodsFor: 'initialization' stamp: 'mpw 1/1/1901 00:13'! collection:target collection _ target. ! ! !Trampoline methodsFor: 'initialization' stamp: 'mpw 1/1/1901 21:31'! iterationMessage:msg iterationMessage _ msg. ! ! !Trampoline methodsFor: 'initialization' stamp: 'mpw 1/1/1901 21:41'! iterationSelector:sel | msg | msg _ Message selector:sel arguments:(Array new:sel numArgs). ^self iterationMessage:msg. ! ! !Trampoline methodsFor: 'forwarding' stamp: 'apb 2/9/2000 21:06'! doesNotUnderstand:aMessage | args | self shiftHalt. args _ iterationMessage arguments. args at:args size put:aMessage. ^iterationMessage sentTo:collection. ! ! !Trampoline class reorganize! ('instance creation' new) ! !Trampoline class methodsFor: 'instance creation' stamp: 'mpw 1/1/1901 00:18'! new ^self basicNew. ! !