Hi,
I'm playing with => from future.nim, and I have a question. These lines are working:
import future
proc takeProcAndCallWith10(f: proc(x: int): int): int =
result = f(10)
echo takeProcAndCallWith10((x: int) => x+1) # prints 11
echo takeProcAndCallWith10((x) => x+1) # prints 11
echo takeProcAndCallWith10(x => x+1) # prints 11
assert takeProcAndCallWith10(x => x+1) == 11 # Easter egg: gives SIGSEGV, who knows why
I get some warning messages Typeless parameters are deprecated, which is strange, are these forms will disappear?
I can also create my own function without specifying types:
proc myProc[T](x: T): auto =
x + 1
echo takeProcAndCallWith10(myProc) # prints 11
So my question is: is it possible to make the following lines work?
echo map(@[1,2,3,4,5], (x: int) => x*10) # prints 11
echo map(@[1,2,3,4,5], (x) => x*10) # fails to compile
echo map(@[1,2,3,4,5], x => x*10) # fails to compile
echo map(@[1,2,3,4,5], myProc) # fails to compile
I know that this might require a smarter generic-type-matcher logic.
Motivation:
Let's consider the following two lines:
echo lines.mapIt(it.len)
echo lines.map(line => line.len) # currently fails to compile
I prefer the second one. It's a little bit longer, but I can give a good variable name instead of using it for everything. If the second line was working, that might kill the need for mapIt.
assert takeProcAndCallWith10(x => x+1) == 11 # Easter egg: gives SIGSEGV, who knows why
Works for me.
The rest of your questions have already been addressed:
http://forum.nim-lang.org/t/1451
https://github.com/nim-lang/Nim/issues/3127
@Araq: thank you for the links. I completely missed the other thread.
My branch was 5 days old. I've updated it, and the SIGSEGV disappeared.