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).
when true:
proc bar(x: string): auto =
x.len
proc fn(a, b: var string): lent string =
var ret: ptr string
if a[0] <= b[0]: ret = a.addr
else: ret = b.addr
ret[]
proc main() =
var a = "abc"
var b = "defgh"
doAssert bar(fn(a, b)) == 3 # no copy is made
main()
Current Output
nim r --experimental:views main
t12080.nim(11, 5) Error: cannot borrow from
var ret: ptr string
if a[0] <= b[0]:
ret = addr(a)
else:
ret = addr(b)
ret[], it is not a path expression; see https://nim-lang.github.io/Nim/manual_experimental.html#view-types-algorithm-path-expressions for details
var ret: ptr string
Expected Output
works
Possible Solution
redesign --experimental:views from scratch, it's broken beyond repair; there's a much simpler design that doesn't have any of {.views}'s limitations and allows writing efficient code without getting in your way.
this causes CI failure in https://github.com/nim-lang/Nim/pull/17500 because of this test: tests/views/tcan_compile_nim.nim which compiler compiler with --experimental:views
Example
Current Output
nim r --experimental:views main
Expected Output
works
Possible Solution
redesign
--experimental:views
from scratch, it's broken beyond repair; there's a much simpler design that doesn't have any of{.views}
's limitations and allows writing efficient code without getting in your way.see also the many other issues plaguing {.views.} https://github.com/nim-lang/Nim/labels/view%20types, some of which are not fixable with this design.
Additional Information
1.5.1 8573160a44439ffe3fbbdd354188db9c976a2081
--experimental:views
reduced case from code referenced in https://github.com/nim-lang/Nim/pull/17500#discussion_r601972687