2013-11-24 10:45:07 -08:00
|
|
|
// Returns characters (as strings).
|
2013-12-21 19:25:09 -08:00
|
|
|
IO.write("abcd"[0]) // expect: a
|
|
|
|
|
IO.write("abcd"[1]) // expect: b
|
|
|
|
|
IO.write("abcd"[2]) // expect: c
|
|
|
|
|
IO.write("abcd"[3]) // expect: d
|
2013-11-24 10:45:07 -08:00
|
|
|
|
|
|
|
|
// Allows indexing backwards from the end.
|
2013-12-21 19:25:09 -08:00
|
|
|
IO.write("abcd"[-4]) // expect: a
|
|
|
|
|
IO.write("abcd"[-3]) // expect: b
|
|
|
|
|
IO.write("abcd"[-2]) // expect: c
|
|
|
|
|
IO.write("abcd"[-1]) // expect: d
|
2013-11-24 10:45:07 -08:00
|
|
|
|
|
|
|
|
// Handle out of bounds.
|
2013-12-14 15:28:18 -08:00
|
|
|
// TODO: Should halt the fiber or raise an error somehow.
|
2013-12-21 19:25:09 -08:00
|
|
|
IO.write("abcd"[4]) // expect: null
|
|
|
|
|
IO.write("abcd"[-5]) // expect: null
|
2013-11-24 10:45:07 -08:00
|
|
|
|
|
|
|
|
// Handle wrong argument type.
|
2013-12-14 15:28:18 -08:00
|
|
|
// TODO: Should halt the fiber or raise an error somehow.
|
2013-12-21 19:25:09 -08:00
|
|
|
IO.write("abcd"[true]) // expect: null
|
2013-11-24 10:45:07 -08:00
|
|
|
|
|
|
|
|
// Handle non-integer index.
|
2013-12-14 15:28:18 -08:00
|
|
|
// TODO: Should halt the fiber or raise an error somehow.
|
2013-12-21 19:25:09 -08:00
|
|
|
IO.write("abcd"[1.5]) // expect: null
|