get collection's item by given index Parameters get collection :complex :string :error :errorkind :date :binary :dictionary :object :store :block :range :bytecode
index :anyAttributes safe get value, overriding potential magic methods (only for Object values)
Returns Examples copy
user: #[
name: "John"
surname: "Doe"
]
print user\name ; John
print get user 'surname ; Doe
print user\surname ; Doe
copy
arr: ["zero" "one" "two"]
print arr\1 ; one
print get arr 2 ; two
y: 2
print arr\[y] ; two
copy
str: "Hello world!"
print str\0 ; H
print get str 1 ; e
z: 0
print str\[z+1] ; e
print str\[0..4] ; Hello
copy
a: to :complex [1 2]
print a\real ; 1.0
print a\imaginary ; 2.0
print a\1 ; 2.0
copy
define :person [
get: method [what][
(key? this what)? -> get.safe this what ; if the key exists, return the value
-> "DEFAULT" ; otherwise, do something else
]
]
Related