2024-10-21 23:56:58 +09:00
|
|
|
|
|
|
|
class Collection: Object {
|
|
|
|
fun length() {
|
|
|
|
return (core.basicSize self)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class IndexedCollection: Collection {
|
|
|
|
fun slice(index count) {
|
|
|
|
return (core.slice self index count)
|
|
|
|
}
|
|
|
|
|
|
|
|
fun at(index) {
|
|
|
|
return (core.basicAt self index)
|
|
|
|
}
|
|
|
|
|
|
|
|
fun atPut(index value) {
|
|
|
|
return (core.basicAtPut self index value)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class FixedSizedCollection: IndexedCollection {
|
2025-09-17 22:51:43 +09:00
|
|
|
fun[#class] new(size) {
|
2024-10-21 23:56:58 +09:00
|
|
|
| obj iv |
|
|
|
|
obj := (core.basicNew self size)
|
|
|
|
if (self:respondsTo "initValue") { ## TODO: change "initValue" to a symbol once supported
|
|
|
|
i := 0
|
|
|
|
iv := (self:initValue)
|
|
|
|
while (< i size) { ## TODO: change to i < size after having implemented these methods on integer/smallintger
|
|
|
|
core.basicAtPut obj i iv
|
2025-09-17 22:51:43 +09:00
|
|
|
i := (i + 1) ## TODO: change to i + 1 ## TODO: change to i < size after having implemented these methods on integer/smallintger
|
2024-10-21 23:56:58 +09:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return obj
|
|
|
|
}
|
|
|
|
|
2025-09-17 22:51:43 +09:00
|
|
|
##fun[#class] initValue() {
|
2024-10-21 23:56:58 +09:00
|
|
|
## return nil
|
|
|
|
##}
|
|
|
|
}
|
|
|
|
|
2025-09-17 22:51:43 +09:00
|
|
|
class[#varying] Array: FixedSizedCollection {
|
2024-10-21 23:56:58 +09:00
|
|
|
}
|
|
|
|
|
2025-09-17 22:51:43 +09:00
|
|
|
class[#char #varying] String: FixedSizedCollection {
|
|
|
|
fun[#class] initValue() {
|
2024-10-21 23:56:58 +09:00
|
|
|
##return '\0'
|
|
|
|
return ' '
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class SequenceableCollection: Collection {
|
2025-09-17 22:51:43 +09:00
|
|
|
fun iterate(action) {
|
2024-10-21 23:56:58 +09:00
|
|
|
| i x |
|
|
|
|
i := 0; x := (self:size)
|
|
|
|
while (i < x) {
|
|
|
|
action:value (self:at i)
|
2025-09-17 22:51:43 +09:00
|
|
|
i := (i + 1)
|
2024-10-21 23:56:58 +09:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|