fork download
  1. class Lists
  2. {
  3. Void main()
  4. {
  5. //literals
  6. //access
  7. //modify
  8. //stack
  9. //iteration
  10. //search
  11. //join
  12. //map
  13. //reduce
  14. //sorting
  15. readOnly
  16. }
  17.  
  18.  
  19.  
  20. Void readOnly()
  21. {
  22. q := ["a", "b", "c"]
  23. r := q.rw; show(r, "rw on read/write returns this (r === q)")
  24. s := q.ro; show(s, "s is readonly with items in q")
  25. t := s.ro; show(t, "ro on readonly returns this (t === s)")
  26. u := s.rw; show(u, "read/write with items in s (u !== s)")
  27. show(s.isRO, "returns true")
  28. show(s.isRW, "return false")
  29. }
  30.  
  31. Void show(Obj? result, Str what)
  32. {
  33. resultStr := "" + result
  34. if (resultStr.size > 40) resultStr = resultStr[0..40] + "..."
  35. echo(what.padr(40) + " => " + resultStr)
  36. }
  37.  
  38. }
Success #stdin #stdout 1.61s 106104KB
stdin
Standard input is empty
stdout
rw on read/write returns this (r === q)  => [a, b, c]
s is readonly with items in q            => [a, b, c]
ro on readonly returns this (t === s)    => [a, b, c]
read/write with items in s (u !== s)     => [a, b, c]
returns true                             => true
return false                             => false