_@true not [false]. _@false not [true]. _@true ifTrue: block ifFalse: _ [block value]. _@false ifTrue: _ ifFalse: block [block value]. bool@(traits boolean) ifTrue: block [ bool ifTrue: block ifFalse: [] ]. bool@(traits boolean) ifFalse: block [ bool ifTrue: [] ifFalse: block ]. _@true /\ _@true [true]. _@(traits boolean) /\ _@(traits boolean) [false]. _@false \/ _@false [false]. _@(traits boolean) \/ _@(traits boolean) [true]. bool@(traits boolean) and: block@(traits method) [ bool ifTrue: block ifFalse: [false] ]. bool@(traits boolean) or: block@(traits method) [ bool ifTrue: [true] ifFalse: block ]. bool@(traits boolean) and: x@(traits method) and: y@(traits method) [ (bool and: x) and: y ]. bool@(traits boolean) or: x@(traits method) or: y@(traits method) [ (bool or: x) or: y ]. condition@(traits method) whileTrue: body@(traits method) [ condition value ifFalse: [^ nil]. body value. condition whileTrue: body ]. condition@(traits method) whileFalse: body@(traits method) [ condition value ifTrue: [^ nil]. body value. condition whileTrue: body ]. count@(traits integer) timesRepeat: block@(traits method) [ [count > 0] whileTrue: [ block value. count: count - 1 ] ]. start@(traits integer) upTo: end@(traits integer) do: block@(traits method) [ [start <= end] whileTrue: [ block value: start. start: start + 1 ] ]. start@(traits integer) downTo: end@(traits integer) do: block@(traits method) [ [start >= end] whileTrue: [ block value: start. start: start - 1 ] ]. start@(traits number) to: end@(traits number) by: inc@(traits number) do: block@(traits method) [ [start <= end] whileTrue: [ block value: start. start: start + inc ] ]. c@(traits collection) first [c at: 0]. c@(traits collection) last [c at: c size - 1]. c@(traits collection) first: value [c at: 0 put: value]. c@(traits collection) last: value [c at: c size - 1 put: value]. c@(traits collection) isEmpty [c size = 0]. c@(traits collection) notEmpty [c isEmpty not]. c@(traits collection) do: block [| index | index: 0. [index < c size] whileTrue: [block value: (c at: index). index: index + 1] ]. c@(traits collection) inject: result into: block@(traits method) [ c do: [| :element | result: (block value: result value: element)]. result ]. c@(traits collection) detect: succeed ifNone: fail [ c do: [| :element | (succeed value: element) ifTrue: [^ value]]. fail value ]. c@(traits collection) anySatisfy: predicate [ c do: [| :element | (predicate value: element) ifTrue: [^ true]]. false ]. c@(traits collection) allSatisfy: predicate [ c do: [| :element | (predicate value: element) ifFalse: [^ false]]. true ]. c@(traits collection) noneSatisfy: predicate [ c do: [| :element | (predicate value: element) ifTrue: [^ false]]. true ]. n@(traits number) factorial [ n <= 1 ifTrue: [1] ifFalse: [n * (n - 1) factorial] ]. x@(traits number) max: y@(traits number) [ x > y ifTrue: [x] ifFalse: [y] ]. x@(traits number) min: y@(traits number) [ x < y ifTrue: [x] ifFalse: [y] ]. traits addSlot: #linkedList. traits linkedList: traits collection clone. traits linkedList addDelegate: #collection. traits linkedList collection: traits collection. _@(traits linkedList) new [linkedList clone clear]. globals addSlot: #link. link: cloneable clone. link addSlot: #next. link addSlot: #previous. globals addSlot: #linkedList. linkedList: collection clone. linkedList addDelegate: #linkedList. linkedList linkedList: traits linkedList. linkedList addSlot: #next. linkedList addSlot: #previous. ll@(traits linkedList) clear [ ll next: ll. ll previous: ll. ]. ll@(traits linkedList) isEmpty [ll next = ll]. ll@(traits linkedList) first [ll next]. ll@(traits linkedList) last [ll previous]. ll@(traits linkedList) at: index@(traits integer) [| position | position _ ll next. index timesRepeat: [position: position next]. position ]. ll@(traits linkedList) add: newObject before: oldObject [ newObject next: oldObject. newObject previous: oldObject previous. oldObject previous: newObject. newObject previous next: newObject. newObject ]. ll@(traits linkedList) add: newObject after: oldObject [ ll add: newObject before: oldObject next ]. ll@(traits linkedList) addFirst: newObject [ ll add: newObject before: ll next ]. ll@(traits linkedList) addLast: newObject [ ll add: newObject after: ll previous ]. traits addSlot: #orderedCollection. traits orderedCollection: traits collection clone. traits orderedCollection addDelegate: #collection. traits orderedCollection collection: traits collection. _@(traits orderedCollection) new [traits orderedCollection new: 4]. _@(traits orderedCollection) new: capacity@(traits integer) [| oc | oc: orderedCollection clone. oc contents: (traits array new: capacity). oc ]. globals addSlot: #orderedCollection. orderedCollection: collection clone. orderedCollection addDelegate: #orderedCollection. orderedCollection orderedCollection: traits orderedCollection. orderedCollection addSlot: #firstIndex. orderedCollection addSlot: #lastIndex. orderedCollection addSlot: #contents. orderedCollection firstIndex: 0. orderedCollection lastIndex: -1. orderedCollection contents: {}. oc@(traits orderedCollection) size [oc lastIndex - oc firstIndex + 1]. oc@(traits orderedCollection) capacity [oc contents size]. oc@(traits orderedCollection) at: index@(traits integer) [oc contents at: oc firstIndex + index]. oc@(traits orderedCollection) at: index@(traits integer) put: value [ oc contents at: oc firstIndex + index put: value ]. oc@(traits orderedCollection) clear [ oc firstIndex: 0. oc lastIndex: -1. oc ]. oc@(traits orderedCollection) growFirst [| newContents offset | oc lastIndex >= (oc capacity - 1) ifTrue: [newContents: (traits array new: oc capacity * 2)] ifFalse: [newContents: oc contents]. offset: newContents size - oc lastIndex - 1. oc lastIndex downTo: oc firstIndex do: [| :index | newContents at: index + offset put: (oc contents at: index) ]. oc firstIndex: oc firstIndex + offset. oc lastIndex: oc lastIndex + offset. oc contents: newContents ]. oc@(traits orderedCollection) growLast [| newContents | oc firstIndex = 0 ifTrue: [newContents: (traits array new: oc capacity * 2)] ifFalse: [newContents: oc contents]. oc firstIndex upTo: oc lastIndex do: [| :index | newContents at: index - oc firstIndex put: (oc contents at: index) ]. oc lastIndex: oc lastIndex - oc firstIndex. oc firstIndex: 0. oc contents: newContents ]. oc@(traits orderedCollection) addFirst: value [ oc firstIndex = 0 ifTrue: [oc growFirst]. oc firstIndex: oc firstIndex - 1. oc contents at: oc firstIndex put: value ]. oc@(traits orderedCollection) addLast: value [ oc lastIndex >= (oc capacity - 1) ifTrue: [oc growLast]. oc lastIndex: oc lastIndex + 1. oc contents at: oc lastIndex put: value ].