Re: Lambdas?
[https://play.nim-lang.org/#ix=1XgA](https://play.nim-lang.org/#ix=1XgA)
Re: Lambdas?
Being a Lisp fan too (Nim fan of course), I have a section for ["Lambdas in Nim"](https://scripter.co/notes/nim/#lambda) in my Nim notes.
Re: Lambdas?
I don't think so: [https://hub.docker.com/_/ubuntu?tab=tags](https://hub.docker.com/_/ubuntu?tab=tags) They do have devel tag (I'm using that BTW) but it means that this is the development version of Ubuntu, i.e. eoan, not that it contains some packages for developers. So, I have to install GCC and wget manually: [https://github.com/moigagoo/nimage/blob/develop/flavors/slim.nim#L8](https://github.com/moigagoo/nimage/blob/develop/flavors/slim.nim#L8)
Re: Lambdas?
You may also want to check out js-like arrow function. [https://nim-lang.org/docs/sugar.html#%3D%3E.m%2Cuntyped%2Cuntyped](https://nim-lang.org/docs/sugar.html#%3D%3E.m%2Cuntyped%2Cuntyped)
Re: Lambdas?
[https://nim-lang.github.io/Nim/manual.html#procedures-anonymous-procs](https://nim-lang.github.io/Nim/manual.html#procedures-anonymous-procs) just omit the procedure name
Lambdas?
i don't seem to find any documentation on lambdas, so far i'm enjoying programming in nim, but i would love to try those multi-line lambdas that nim says it features, so... how do i use 'em?
Re: Type inference and pragma issues in lambdas
Oh, right, the issue is for proc within tuples: [https://github.com/nim-lang/Nim/issues/7808](https://github.com/nim-lang/Nim/issues/7808)
Re: Type inference and pragma issues in lambdas
@adobai, this is work proc doIt(x: string, p: proc()) = echo x doIt("xx", proc() = echo "aa") Run
Re: Type inference and pragma issues in lambdas
@juancarlospaco what's that supposed to be? @mratsim the sugar module produces the same. Also, I REALLY don't want to type down {.closure.} every time I create a lambda function because it'd be insane. Also, I think it's wrong for a lambda to assume that it'll be a {.closure.} - it should allow everything by default unless explicitly defined otherwise.
Re: Type inference and pragma issues in lambdas
For some reason procvar (proc parameter) sometimes need some help with either {.closure.} or {.nimcall.} proc doIt(x: (string, proc(){.closure.})) = echo x[0] doIt(("xx", proc() {.closure.} = echo "aa")) Run Be sure to check the `sugar` module as well for `->` and `=>` shortcuts proc passTwoAndTwo(f: (int, int) -> int): int = f(2, 2) passTwoAndTwo((x, y) => x + y) # 4 Run
Re: Type inference and pragma issues in lambdas
`(func: auto = "Lambda")() ` Run
Type inference and pragma issues in lambdas
Hi, > Why is this an issue: proc doIt(x: (string, proc(): void)) = echo x[0] doIt(("xx", proc(): void = echo "aa")) Run Hint: used config file '/home/steven/.choosenim/toolchains/nim-0.19.0/config/nim.cfg' [Conf] Hint: system [Processing] Hint: t [Processing] t.nim(5, 5) Error: type mismatch: got but expected one of: proc doIt(x: (string, proc (): void)) expression: doIt(("xx", proc (): void = echo ["aa"])) Run Is there a sane way in nim to do lambdas?
Re: Type inference and pragma issues in lambdas
But this is ok: proc doIt(x: (string, proc(): void)) = echo x[0] proc make1(x: string, y: proc(): void): (string, proc(): void) = (x, y) doIt(make1("xx", proc(): void = echo "aa")) Run Doesn't make any sense.