[View]  [Edit]  [Lock]  [References]  [Attachments]  [History]  [Home]  [Changes]  [Search]  [Help] 

test[jl8] 20

.
self running: 'coreOptimizations'
nil class === UndefinedObject
nil isNil
self nativeLanguage ~= #py or: [ #{None} isNil ]
1 notNil
0 notNil
true notNil
false notNil
'' notNil
#hello notNil
#() notNil

true
false not
true = true
false = false
true ~= false
1 ~= true
0 ~= true
false ~= true
1 ~= false
0 ~= false

self nativeLanguage ~= #py or: [ nil ~~ #{None} ]
0 ~~ nil
0 ~~ 1
1 ~~ nil
1 ~~ 0
#() ~~ nil
#() ~~ 0

true || false
false || false = false
true || true

(Smalltalk current basicAt: #String) == String
(Smalltalk current basicAt: #String ifAbsent: [#missing]) == String
(Smalltalk current basicAt: 'not found' ifAbsent: [#missing]) = #missing
(Smalltalk current basicAt: #cookie put: #cookie) = #cookie

self nativeLanguage ~= #py or: [ (#{None} ifUndefined: [true]) notNil ]

self running: 's8Optimizations'

| result | result := true ifTrue: [ true ]. ^result
true ifTrue: [ ^true ]. ^false
| result | result := false ifFalse: [ true ]. ^result
false ifFalse: [ ^true ]. ^false

| result | result := true ifTrue: [ true ] ifFalse: [ false ]. ^result
| result | result := false ifTrue: [ false ] ifFalse: [ true ]. ^result
true ifTrue: [ ^true ] ifFalse: [ false ]
false ifTrue: [ false ] ifFalse: [ ^true ]

| x | x := 10. [x>0] whileTrue: [ x := x - 1 ].^x=0
| x | x := 10. ^([x>0] whileTrue: [ x := x - 1 ]) isNil
| x | x := 10. [(x := x - 1)>0] whileTrue.^x=0
| x | x := 10. ^([(x := x - 1)>0] whileTrue) isNil

| x | x := 10. [x=0] whileFalse: [ x := x - 1 ].^x=0
| x | x := 10. ^([x=0] whileFalse: [ x := x - 1 ]) isNil
| x | x := 10. [(x := x - 1)=0] whileFalse.^x=0
| x | x := 10. ^([(x := x - 1)=0] whileFalse) isNil

|x| x := 1. ^(x := x - 1)=0
| x y | x := 10. [ y := (x := x - 1) > 0 ] whileTrue.^x=0

self nativeLanguage ~= #py or: [ #{None} orNil isNil ]
nil orNil isNil
3 orNil = 3

3 isKindOf: Object
3 isKindOf: Number
Point zero isKindOf: Point
"Point isKindOf: Class
(Point isKindOf: nil) not
(Point isKindOf: 123) not
(Point isKindOf: #hello) not
(#hello isKindOf: #()) not
#hello isKindOf: Collection

Point respondsTo: #new
nil respondsTo: #yourself
(nil respondsTo: nil) not
(nil respondsTo: nil class) not
(nil respondsTo: 123) not

nil ifNil: [ true ]
12 ifNotNil: [ true ]
nil ifNil: [ true ] ifNotNil: [ false ]
true ifNil: [ false ] ifNotNil: [ true ]
nil ifNil: [ true ] ifNotNil: nil
true ifNil: nil ifNotNil: [ true ]

self running: 'magnitudeOptimizations'
12 > 11
77 > 7
1 < 2
-1 < 1
-1 < 0
0 < 1
1>=0
0>=0
0<=0
1<=2

self running: 'mathOptimizations'
(1 max: 2) = 2
(2 min: 1) = 1
12 mustBeNumber = 12
3+4 = 7
8-1=7
3*4=12
12/4=3

self running: 'printingOptimizations'
12 toString isString
24 toString class == String
#hello printString = '''hello'''
#hello asString = #hello
12 asString = #12
64 asCharacter = $@
9 asCharacter = String tab
100 asCharacter asciiValue = 100

self running: 'booleanOptimizations'
true isBoolean
false isBoolean
12 isBoolean not
nil isBoolean not
#hello isBoolean not
(true and: [ false ]) = false
(false and: [false]) not
(true and: [false]) not
(false and: [true]) not
false and: [ ^false ]. ^true
true or: [false]
false or: [true]
false or: [1 < 2]
false or: [^true]. ^false
true or: [^false]. ^true