Files
hak/src/kernel.hcl
hyung-hwan e2864bab55
All checks were successful
continuous-integration/drone/push Build is passing
added pf_core_put
2024-07-29 19:15:12 +09:00

89 lines
1.3 KiB
HCL

class Apex {
}
class Object :: Apex {
}
class Collection :: Object {
}
class IndexedCollection :: Collection {
}
class FixedSizedCollection :: IndexedCollection {
}
class Array :: FixedSizedCollection {
}
class String :: FixedSizedCollection {
}
fun Collection:length() {
return (core.length self)
}
fun Collection:slice(index count) {
return (core.slice self index count)
}
fun Collection:at(index) {
return (core.get self index)
}
fun Collection:atPut(index value) {
return (core.put self index value)
}
fun Class:name() {
return (core.class_name self)
}
##class String:: Array [a b c] {
##}
##class String:: Array [
## monaco
## duncan
## falcon
## deuce
## canival
## pebble
## godzilla
##] {
## fun Collection:slice(index count) {
## return (arr.slice self index count)
## }
##}
k := "abcdefghijklmn"
printf "string length %d\n" ("aaaa":length)
printf "substring [%s]\n" (k:slice 5 6)
try {
printf "substring [%c]\n" (k:at 13)
k:atPut 14 'A'
printf "[%s]\n" k
} catch (e) {
printf "EXCEPTION %O\n" e
}
k := #[1 2 3 4 5 6 7 8 9 10 11 12 13 14 15]
try {
k:atPut 2 'A'
printf "%O\n" k
} catch (e) {
printf "EXCEPTION %O\n" e
}
k := #b[1 2 3 4 5 6 7 8 9 10 11 12 13 14 15]
try {
k:atPut 2 -10
printf "%O\n" k
} catch (e) {
printf "EXCEPTION %O\n" e
}