Nim is a statically typed compiled systems programming language. It combines successful concepts from mature languages like Python, Ada and Modula. Its design focuses on efficiency, expressiveness, and elegance (in that order of priority).
However, it does not compile (even with the one dangerous line commented out):
Example
{.experimental: "views".}
type
Obj = object
field: string
proc dangerous(s: var seq[Obj]) =
let v: lent Obj = s[0] # seal 's'
# commented out!! s.setLen 0 # prevented at compile-time because 's' is sealed.
echo v.field
var s = @[Obj(field: "fff")]
dangerous(s)
Current Output
nim c viewsfail.nim
Hint: used config file '/home/olli/.choosenim/toolchains/nim-1.4.2/config/nim.cfg' [Conf]
Hint: used config file '/home/olli/.choosenim/toolchains/nim-1.4.2/config/config.nims' [Conf]
....CC: stdlib_system.nim
CC: viewsfail.nim
/home/olli/.cache/nim/viewsfail_d/@mviewsfail.nim.c: In function ‘dangerous__jX7jyjvbdJfl3bjgqB5bmQ’:
/home/olli/.cache/nim/viewsfail_d/@mviewsfail.nim.c:398:6: error: incompatible types when assigning to type ‘tyObject_Obj__QFqSOLZkhelY8XYnDrOOog *’ {aka ‘struct tyObject_Obj__QFqSOLZkhelY8XYnDrOOog *’} from type ‘tyObject_Obj__QFqSOLZkhelY8XYnDrOOog’ {aka ‘struct tyObject_Obj__QFqSOLZkhelY8XYnDrOOog’}
398 | v = (*s)->data[((NI) 0)];
Additional information
Nim Compiler Version 1.4.2 [Linux: amd64]
Operating System: Ubuntu 20.04.1 LTS
Kernel: Linux 5.4.0-54-generic
Documentation page of experimental features has an example with views at Path expressions chapter: https://nim-lang.org/docs/manual_experimental.html#view-types-path-expressions
However, it does not compile (even with the one dangerous line commented out):
Example
Current Output
Additional information