Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.2(pesnta/xelos-%I%) 9/18/84; site pesnta.UUCP Path: utzoo!lsuc!pesnta!earlw From: earlw@pesnta.UUCP (Earl Wallace) Newsgroups: pe.cust.sources Subject: Little Smalltalk Source, *New* Part 8 of 20 Message-ID: <2769@pesnta.UUCP> Date: Thu, 13-Jun-85 15:24:14 EDT Article-I.D.: pesnta.2769 Posted: Thu Jun 13 15:24:14 1985 Date-Received: Sat, 15-Jun-85 08:35:37 EDT Organization: Perkin-Elmer Data Systems Group / Customer Service Lines: 1367 #! /bin/sh # # This is an another posting of the Little Smalltalk source, the last posting # of this source went out in 5 parts and they were too big (>200k) for most # sites so I redid the whole mess to keep the files around the 50k range. # # The complete set is now 20 parts. # # P.S. - If you don't receive all 20 parts within 5 days, drop me a line. # Also, I have the Rand sources of May 1984, if someone has a more # updated copy, I'll be happy to post them (or YOU can post them :-)) # # -earlw@pesnta # #! /bin/sh # This is a shell archive, meaning: # 1. Remove everything above the #! /bin/sh line. # 2. Save the resulting text in a file. # 3. Execute the file with /bin/sh (not csh) to create the files: # prelude/number.st # prelude/object.p # prelude/object.st # prelude/point.p # prelude/point.st # prelude/process.p # prelude/process.st # prelude/radian.p # prelude/radian.st # prelude/random.p # prelude/random.st # prelude/savescript # prelude/scollection.p # prelude/scollection.st # prelude/semaphore.p # prelude/semaphore.st # prelude/set.p # prelude/set.st # prelude/smalltalk.p # prelude/smalltalk.st # This archive created: Thu Jun 13 11:32:13 1985 # By: Earl Wallace (Perkin-Elmer Data Systems Group / Customer Service) export PATH; PATH=/bin:$PATH if test -f 'prelude/number.st' then echo shar: will not over-write existing file "'prelude/number.st'" else cat << \SHAR_EOF > 'prelude/number.st' Class Number :Magnitude [ maxtype: aNumber ^ ifTrue: [self] ifFalse: [aNumber coerce: self ] | = aNumber ^ (self maxtype: aNumber) = (aNumber maxtype: self) | < aNumber ^ (self maxtype: aNumber) < (aNumber maxtype: self) | > aNumber ^ (self maxtype: aNumber) > (aNumber maxtype: self) | + aNumber ^ (self maxtype: aNumber) + (aNumber maxtype: self) | - aNumber ^ (self maxtype: aNumber) - (aNumber maxtype: self) | * aNumber ^ (self maxtype: aNumber) * (aNumber maxtype: self) | / aNumber ^ (self maxtype: aNumber) / (aNumber maxtype: self) | ^ aNumber ^ self asFloat ^ aNumber asFloat | @ aNumber ^ ( Point new x: self ) y: aNumber | abs ^ (self < 0) ifTrue: [ 0 - self ] ifFalse: [ self ] | exp ^ self asFloat exp | gamma ^ self asFloat gamma | ln ^ self asFloat ln | log: aNumber ^ self ln / aNumber ln | negated ^ 0 - self | negative ^ self < 0 | pi ^ self * 3.1415926 | positive ^ self >= 0 | radians ^ Radian new: self asFloat | raisedTo: aNumber ^ self asFloat ^ aNumber asFloat | reciprocal ^ 1.00 / self | roundTo: aNumber ^ (self / aNumber) rounded * aNumber | sign ^ (self < 0) ifTrue: [ -1 ] ifFalse: [ (self > 0) ifTrue: [ 1 ] ifFalse: [ 0 ] ] | sqrt ^ self asFloat sqrt | squared ^ self * self | strictlyPositive ^ self > 0 | to: highValue ^ Interval new ; from: self to: highValue by: 1 | to: highValue by: stepSize ^ Interval new ; from: self to: highValue by: stepSize | truncateTo: aNumber ^ (self / aNumber) truncated * aNumber ] SHAR_EOF if test 1597 -ne "`wc -c < 'prelude/number.st'`" then echo shar: error transmitting "'prelude/number.st'" '(should have been 1597 characters)' fi fi # end of overwriting check if test -f 'prelude/object.p' then echo shar: will not over-write existing file "'prelude/object.p'" else cat << \SHAR_EOF > 'prelude/object.p' temp <- > SHAR_EOF if test 2344 -ne "`wc -c < 'prelude/object.p'`" then echo shar: error transmitting "'prelude/object.p'" '(should have been 2344 characters)' fi fi # end of overwriting check if test -f 'prelude/object.st' then echo shar: will not over-write existing file "'prelude/object.st'" else cat << \SHAR_EOF > 'prelude/object.st' Class Object [ == anObject ^ | ~~ x ^ (self == x) not | = x ^ (self == x) | ~= x ^ (self = x) not | asString ^ self class printString | asSymbol ^ self asString asSymbol | class ^ | copy ^ self shallowCopy | deepCopy | size newobj | size <- . (size < 0) ifTrue: [^ self] "if special just copy object" ifFalse: [ newobj <- self class new. (1 to: size) do: [:i | copy ) > ]. ^ newobj ] | do: aBlock | item | item <- self first. ^ [item notNil] whileTrue: [aBlock value: item. item <- self next] | error: aString | first ^ self | isKindOf: aClass | objectClass | objectClass <- self class. [objectClass notNil] whileTrue: [(objectClass == aClass) ifTrue: [^ true]. objectClass <- objectClass superClass]. ^ false | isMemberOf: aClass ^ aClass == self class | isNil ^ false | next ^ nil | notNil ^ true | print | printString ^ self asString | respondsTo: cmd ^ self class respondsTo: cmd | shallowCopy | size newobj | size <- . (size < 0) ifTrue: [^ self] "if special just copy object" ifFalse: [ newobj <- self class new. (1 to: size) do: [:i | > ]. ^ newobj ] ] SHAR_EOF if test 1760 -ne "`wc -c < 'prelude/object.st'`" then echo shar: error transmitting "'prelude/object.st'" '(should have been 1760 characters)' fi fi # end of overwriting check if test -f 'prelude/point.p' then echo shar: will not over-write existing file "'prelude/point.p'" else cat << \SHAR_EOF > 'prelude/point.p' temp <- = " \ #( #[ 16 33 10 49 203 252 5 17 33 10 50 203 243 245] \ #( ) ) > = #<= #< ) \ temp 3 4 > > SHAR_EOF if test 2339 -ne "`wc -c < 'prelude/point.p'`" then echo shar: error transmitting "'prelude/point.p'" '(should have been 2339 characters)' fi fi # end of overwriting check if test -f 'prelude/point.st' then echo shar: will not over-write existing file "'prelude/point.st'" else cat << \SHAR_EOF > 'prelude/point.st' Class Point :Magnitude | xvalue yvalue | [ < aPoint ^ (xvalue < aPoint x) and: [yvalue < aPoint y] | <= aPoint ^ (xvalue <= aPoint x) and: [yvalue < aPoint y] | >= aPoint ^ (xvalue >= aPoint x) and: [yvalue >= aPoint y] | = aPoint ^ (xvalue = aPoint x) and: [yvalue = aPoint y] | * scale ^ (Point new x: (xvalue * scale)) y: (yvalue * scale) | + delta ^ (Point new x: (xvalue + delta x)) y: (yvalue + delta y) | - delta ^ (Point new x: (xvalue - delta x)) y: (yvalue - delta y) | / scale ^ (Point new x: (xvalue / scale)) y: (yvalue / scale) | // scale ^ (Point new x: (xvalue // scale)) y: (yvalue // scale) | abs ^ (Point new x: xvalue abs) y: (yvalue abs) | asString ^ xvalue asString , ' @ ' , (yvalue asString) | dist: aPoint ^ ((xvalue - aPoint x) squared + (yvalue - aPoint y) squared) sqrt | max: aPoint ^ (Point new x: (xvalue max: aPoint x)) y: (yvalue max: aPoint y) | min: aPoint ^ (Point new x: (xvalue min: aPoint x)) y: (yvalue min: aPoint y) | printString ^ xvalue printString , ' @ ' , (yvalue printString) | transpose ^ (Point new x: yvalue) y: xvalue | x ^ xvalue | x: aValue xvalue <- aValue | x: xValue y: yValue xvalue <- xValue. yvalue <- yValue | y ^ yvalue | y: aValue yvalue <- aValue ] SHAR_EOF if test 1288 -ne "`wc -c < 'prelude/point.st'`" then echo shar: error transmitting "'prelude/point.st'" '(should have been 1288 characters)' fi fi # end of overwriting check if test -f 'prelude/process.p' then echo shar: will not over-write existing file "'prelude/process.p'" else cat << \SHAR_EOF > 'prelude/process.p' temp <- > SHAR_EOF if test 1481 -ne "`wc -c < 'prelude/process.p'`" then echo shar: error transmitting "'prelude/process.p'" '(should have been 1481 characters)' fi fi # end of overwriting check if test -f 'prelude/process.st' then echo shar: will not over-write existing file "'prelude/process.st'" else cat << \SHAR_EOF > 'prelude/process.st' Class Process [ block (self state == #TERMINATED) ifTrue: [self termErr: 'block'. ^ nil]. . ^ self state | resume (self state == #TERMINATED) ifTrue: [self termErr: 'resume'. ^ nil]. . ^ self state | suspend (self state == #TERMINATED) ifTrue: [self termErr: 'suspend'. ^ nil]. . ^ self state | state | pstate | pstate <- . (pstate = 0) ifTrue: [pstate <- #READY. ^ pstate]. (pstate = 1) ifTrue: [pstate <- #SUSPENDED. ^ pstate]. (pstate = 2) ifTrue: [pstate <- #BLOCKED. ^ pstate]. (pstate = 3) ifTrue: [pstate <- #BLOCKED. ^ pstate]. (pstate >= 4) ifTrue: [pstate <- #TERMINATED. ^ pstate] | terminate . ^ self state | termErr: msgName ('Cannot ',msgName,' a terminated process.') print | unblock (self state == #TERMINATED) ifTrue: [self termErr: 'unblock'. ^ nil]. . ^ self state | yield ^ nil ] SHAR_EOF if test 1003 -ne "`wc -c < 'prelude/process.st'`" then echo shar: error transmitting "'prelude/process.st'" '(should have been 1003 characters)' fi fi # end of overwriting check if test -f 'prelude/radian.p' then echo shar: will not over-write existing file "'prelude/radian.p'" else cat << \SHAR_EOF > 'prelude/radian.p' temp <- > SHAR_EOF if test 848 -ne "`wc -c < 'prelude/radian.p'`" then echo shar: error transmitting "'prelude/radian.p'" '(should have been 848 characters)' fi fi # end of overwriting check if test -f 'prelude/radian.st' then echo shar: will not over-write existing file "'prelude/radian.st'" else cat << \SHAR_EOF > 'prelude/radian.st' Class Radian :Magnitude | value | [ new: x value <- | < arg ^ value < arg asFloat | = arg ^ value = arg asFloat | sin ^ | cos ^ | tan ^ / | asFloat ^ value | printString ^ value asString , ' radians' ] SHAR_EOF if test 459 -ne "`wc -c < 'prelude/radian.st'`" then echo shar: error transmitting "'prelude/radian.st'" '(should have been 459 characters)' fi fi # end of overwriting check if test -f 'prelude/random.p' then echo shar: will not over-write existing file "'prelude/random.p'" else cat << \SHAR_EOF > 'prelude/random.p' temp <- > SHAR_EOF if test 880 -ne "`wc -c < 'prelude/random.p'`" then echo shar: error transmitting "'prelude/random.p'" '(should have been 880 characters)' fi fi # end of overwriting check if test -f 'prelude/random.st' then echo shar: will not over-write existing file "'prelude/random.st'" else cat << \SHAR_EOF > 'prelude/random.st' Class Random | seed | [ new seed <- 1 | randomize seed <- | first ^ ) > | next ^ ) > | between: low and: high ^ (self next * (high - low)) + low | randInteger: limit ^ (self next * limit) truncated + 1 | next: n | newa | newa <- Array new: n. (1 to: n) do: [:x | newa at: x put: self next]. ^ newa ] SHAR_EOF if test 494 -ne "`wc -c < 'prelude/random.st'`" then echo shar: error transmitting "'prelude/random.st'" '(should have been 494 characters)' fi fi # end of overwriting check if test -f 'prelude/savescript' then echo shar: will not over-write existing file "'prelude/savescript'" else cat << \SHAR_EOF > 'prelude/savescript' )s stdsave SHAR_EOF if test 11 -ne "`wc -c < 'prelude/savescript'`" then echo shar: error transmitting "'prelude/savescript'" '(should have been 11 characters)' fi fi # end of overwriting check if test -f 'prelude/scollection.p' then echo shar: will not over-write existing file "'prelude/scollection.p'" else cat << \SHAR_EOF > 'prelude/scollection.p' temp <- > SHAR_EOF if test 3846 -ne "`wc -c < 'prelude/scollection.p'`" then echo shar: error transmitting "'prelude/scollection.p'" '(should have been 3846 characters)' fi fi # end of overwriting check if test -f 'prelude/scollection.st' then echo shar: will not over-write existing file "'prelude/scollection.st'" else cat << \SHAR_EOF > 'prelude/scollection.st' Class SequenceableCollection :KeyedCollection [ , aCollection ^ self coerce: (List new ; addAllLast: self ; addAllLast: aCollection ) | collect: aBlock ^ self coerce: (self inject: List new into: [:x :y | x addLast: (aBlock value: y) . x ] ) | copyFrom: start to: stop | newcol | newcol <- List new. (start to: stop) do: [:i | newcol addLast: (self at: i)]. ^ self coerce: newcol | copyWith: newElement ^ self coerce: (List new ; addAllLast: self ; addLast: newElement ) | copyWithout: oldElement | newcol | newcol <- List new. self do: [ :x | (x == oldElement) ifFalse: [ newcol addLast: x ]]. ^ self coerce: newcol | equals: aSubCollection startingAt: anIndex | i | i <- 0. self do: [:x | (x = (aSubCollection at: (anIndex + i) ifAbsent: [^ false])) ifFalse: [^ false]. i <- i + 1]. ^ true | findFirst: aBlock ^ self findFirst: aBlock ifAbsent: [self error: 'first element not found'] | findFirst: aBlock ifAbsent: exceptionBlock self do: [:x | (aBlock value: x) ifTrue: [ ^ self currentKey]]. ^ exceptionBlock value | findLast: aBlock self findLast: aBlock ifAbsent: [self error: 'last element not found'] | findLast: aBlock ifAbsent: exceptionBlock self reverseDo: [:x | (aBlock value: x) ifTrue: [ ^ self currentKey]]. ^ exceptionBlock value | indexOfSubCollection: aSubCollection startingAt: anIndex ifAbsent: exceptionBlock | n m | n <- anIndex. m <- self size - aSubCollection size. [n <= m] whileTrue: [(aSubCollection equals: self startingAt: n) ifTrue: [^ n]. n <- n + 1]. ^ exceptionBlock value | indexOfSubCollection: aSubCollection startingAt: anIndex ^ self indexOfSubCollection: aSubCollection startingAt: anIndex ifAbsent: [ self error: 'element not found'. nil] | last ^ (0 = self size) ifFalse: [ self at: self lastKey ] | replaceFrom: start to: stop with: repcol repcol inject: start into: [:x :y | self at: x put: y. x + 1] | replaceFrom: first to: stop with: repcol startingAt: repStart | i | i <- 0 . [(first + i) <= stop] whileTrue: [self at: (first + i) put: (repcol at: i + repStart). i <- i + 1 ] | reverseDo: aBlock | n m | n <- self lastKey. m <- self firstKey. [n >= m] whileTrue: [(self includesKey: n) ifTrue: [aBlock value: (self at: n)]. n <- n - 1]. ^ nil | reversed | newar i | newar <- Array new: (i <- self size). self do: [:x | newar at: i put: x. i <- i - 1]. ^ self coerce: newar | select: aBlock ^ self coerce: (self inject: List new into: [:x :y | (aBlock value: y) ifTrue: [x addLast: y]. x ] ) | sort ^ self sort: [:x :y | x <= y] | sort: sortBlock | index temp newArray | newArray <- self asArray. (2 to: newArray size) do: [ :highIndex | index <- highIndex - 1. [(index >= 1) and: [(sortBlock value: (newArray at: index) value: (newArray at: (index + 1))) not]] whileTrue: [temp <- newArray at: index. newArray at: index put: (newArray at: index + 1). newArray at: index + 1 put: temp. index <- index - 1 ]]. ^ self coerce: newArray | with: aSequenceableCollection do: aBlock | arg1 arg2 | arg1 <- self first. arg2 <- aSequenceableCollection first. [ arg1 notNil] whileTrue: [ aBlock value: arg1 value: arg2. arg1 <- self next. arg2 <- aSequenceableCollection next]. ^ nil ] SHAR_EOF if test 4499 -ne "`wc -c < 'prelude/scollection.st'`" then echo shar: error transmitting "'prelude/scollection.st'" '(should have been 4499 characters)' fi fi # end of overwriting check if test -f 'prelude/semaphore.p' then echo shar: will not over-write existing file "'prelude/semaphore.p'" else cat << \SHAR_EOF > 'prelude/semaphore.p' temp <- > SHAR_EOF if test 648 -ne "`wc -c < 'prelude/semaphore.p'`" then echo shar: error transmitting "'prelude/semaphore.p'" '(should have been 648 characters)' fi fi # end of overwriting check if test -f 'prelude/semaphore.st' then echo shar: will not over-write existing file "'prelude/semaphore.st'" else cat << \SHAR_EOF > 'prelude/semaphore.st' Class Semaphore :List | excessSignals | [ new excessSignals <- 0 | new: aNumber excessSignals <- aNumber | signal . "start atomic action" (self isEmpty) ifTrue: [excessSignals <- excessSignals + 1] ifFalse: [self removeFirst unblock]. "end atomic action" | wait . "start atomic actions" (excessSignals = 0) ifTrue: [self addLast: selfProcess. selfProcess block] ifFalse: [excessSignals <- excessSignals - 1]. "end atomic actions" ] SHAR_EOF if test 530 -ne "`wc -c < 'prelude/semaphore.st'`" then echo shar: error transmitting "'prelude/semaphore.st'" '(should have been 530 characters)' fi fi # end of overwriting check if test -f 'prelude/set.p' then echo shar: will not over-write existing file "'prelude/set.p'" else cat << \SHAR_EOF > 'prelude/set.p' temp <- > SHAR_EOF if test 788 -ne "`wc -c < 'prelude/set.p'`" then echo shar: error transmitting "'prelude/set.p'" '(should have been 788 characters)' fi fi # end of overwriting check if test -f 'prelude/set.st' then echo shar: will not over-write existing file "'prelude/set.st'" else cat << \SHAR_EOF > 'prelude/set.st' Class Set :Collection | list | [ new list <- List new | add: newElement (list includes: newElement) ifFalse: [list add: newElement] | remove: oldElement ifAbsent: exceptionBlock list remove: oldElement ifAbsent: exceptionBlock | size ^ list size | occurrencesOf: anElement ^ (list includes: anElement) ifTrue: [1] ifFalse: [0] | first ^ list first | next ^ list next ] SHAR_EOF if test 506 -ne "`wc -c < 'prelude/set.st'`" then echo shar: error transmitting "'prelude/set.st'" '(should have been 506 characters)' fi fi # end of overwriting check if test -f 'prelude/smalltalk.p' then echo shar: will not over-write existing file "'prelude/smalltalk.p'" else cat << \SHAR_EOF > 'prelude/smalltalk.p' temp <- > SHAR_EOF if test 1062 -ne "`wc -c < 'prelude/smalltalk.p'`" then echo shar: error transmitting "'prelude/smalltalk.p'" '(should have been 1062 characters)' fi fi # end of overwriting check if test -f 'prelude/smalltalk.st' then echo shar: will not over-write existing file "'prelude/smalltalk.st'" else cat << \SHAR_EOF > 'prelude/smalltalk.st' Class Smalltalk :Dictionary [ date ^ | debug: n ^ | display ^ | displayAssign ^ | doPrimitive: primNumber withArguments: argArray ^ | noDisplay ^ | perform: aMessage withArguments: argArray ^ | sh: command ^ | time: aBlock | start | start <- . aBlock value. ^ - start ] SHAR_EOF if test 517 -ne "`wc -c < 'prelude/smalltalk.st'`" then echo shar: error transmitting "'prelude/smalltalk.st'" '(should have been 517 characters)' fi fi # end of overwriting check # End of shell archive exit 0