Re: Lambdas?

2019-09-28 Thread juancarlospaco
[https://play.nim-lang.org/#ix=1XgA](https://play.nim-lang.org/#ix=1XgA)


Re: Lambdas?

2019-09-28 Thread kaushalmodi
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?

2019-09-28 Thread moigagoo
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?

2019-09-28 Thread jackhftang
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?

2019-09-27 Thread SolitudeSF
[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?

2019-09-27 Thread eko23
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

2018-10-10 Thread mratsim
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

2018-10-10 Thread mashingan
@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

2018-10-07 Thread idobai
@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

2018-10-07 Thread mratsim
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

2018-10-07 Thread juancarlospaco
`(func: auto = "Lambda")() `

Run


Type inference and pragma issues in lambdas

2018-10-07 Thread idobai
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

2018-10-07 Thread idobai
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.