by

Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • Mar 03 2017 15:52
    @dom96 banned @Octopoda7
  • Feb 12 2017 23:57
    @dom96 banned @zzz125
  • Dec 23 2016 19:43
    @dom96 banned @Izrab
Kaushal Modi
@kaushalmodi
and also [] and lc?
From IRC (bridge bot)
@FromIRC
<Yardanico> well, docs explain them pretty much
<Yardanico> lc is for list comprehension (like in python), but you need to specify types
<Yardanico> and there are examples for -> and =>
<Yardanico> (for lc too)
Kaushal Modi
@kaushalmodi
From IRC (bridge bot)
@FromIRC
<Yardanico> why?
Kaushal Modi
@kaushalmodi
What's the relationship between -> and f in that example?
And how does that link with the use of => in the next line?
From IRC (bridge bot)
@FromIRC
<Yardanico> well, this example just uses -> and => at the same time
<Yardanico> -> is for proc types, => is for lambdas
<Yardanico> line with => is the same as "echo passTwoAndTwo(proc (x, y: int): int = x + y)"
<Yardanico> and proc passTwoAndTwo(f: (int, int) -> int): int = is the same as proc passTwoAndTwo(f: proc (x, y: int): int): int =
<miran> regarding lc - the current syntax is IMO clumsy, so while i prefer list comprehensions in python, i use map in nim
Kaushal Modi
@kaushalmodi
Yardanico: Thanks. It's still not clear.. But let me play around with those for a bit. I'll get back if I have questions
From IRC (bridge bot)
@FromIRC
<Yardanico> miran, maybe use mapIt instead?
<miran> @Yardanico: yeah, mapIt is nice, i'm using it also
<Yardanico> and if you do a lot of mapIt filterIt etc and need performance you would use zero_functional module
<miran> @Yardanico: i use that too :⁠) very nice library!!
<miran> @kaushalmodi: start with =>
Govind KP
@reisub0

Hello and I'm sorry if my question is missing something very basic but, I seem to have encountered another issue

Trying to compile my very basic function

proc delayedStringGet(path: string) : Future[string] {.async.} =
    var response = await client.request(url=(Host & path), body=body)
    return response.body

Gives me this compile-time error. I seem to be matching the prototypes pretty accurately, so can't figure out what I'm doing wrong

proc request(client: AsyncHttpClient; url: string; httpMethod: string; body = "";
            headers: HttpHeaders = nil): Future[AsyncResponse]
  first type mismatch at position: 1
  required type: AsyncHttpClient
  but expression 'client' is of type: AsyncHttpClient
proc request(client: AsyncHttpClient; url: string; httpMethod = HttpGET; body = "";
            headers: HttpHeaders = nil): Future[AsyncResponse]
  first type mismatch at position: 1
  required type: AsyncHttpClient
  but expression 'client' is of type: AsyncHttpClient
From IRC (bridge bot)
@FromIRC
<miran> the problem with the example in the docs is that it unnecessary uses both -> and => at the same time
Kaushal Modi
@kaushalmodi
I am trying to convert this in emacs lisp to =>:
(let ((plus1 (lambda (x)
                (+ x 1))))
  (funcall plus1 1)) ; returns 2
Danil Yarantsev
@Yardanico
@reisub0 did you forget to create "body" variable?
From IRC (bridge bot)
@FromIRC
<miran> @kaushalmodi this is the simplest example of => i could make from the top of my head: http://ix.io/1fSS/
Govind KP
@reisub0
No it's been created with let body="type=task"
Andreas Rumpf
@Araq
use import, not include
AsyncHttpClient is probably some other type you introduced on your own
Govind KP
@reisub0
I am using import
Kaushal Modi
@kaushalmodi
miran: Thanks!
Govind KP
@reisub0
And this code is only literally one file
Danil Yarantsev
@Yardanico
@rtei
@reisub0 can you post full code on gist if you can?
also what is your nim version?
with this code I get another error (which is because .body from asyncresponse is a future and you need to "await" for it)
import httpclient, asyncdispatch

let client = newAsyncHttpClient()
let Host = "123"
let body = "123123"

proc delayedStringGet(path: string) : Future[string] {.async.} =
    var response = await client.request(url=(Host & path), body=body)
    return response.body

@Araq btw, with code:

import httpclient, asyncdispatch

let client = newAsyncHttpClient()
let Host = "123"

proc delayedStringGet(path: string) : Future[string] {.async.} =
    var response = await client.request(url=(Host & path), body=body)
    return response.body

I get error:

tta.nim(7, 32) Error: type mismatch: got <AsyncHttpClient, url: string, body: None>
but expected one of:
proc request(url: string; httpMethod = HttpGET; extraHeaders = ""; body = "";
            sslContext = getDefaultSSL(); timeout = -1; userAgent = defUserAgent;
            proxy: Proxy = nil): Response
  first type mismatch at position: 1
  required type: string
  but expression 'client' is of type: AsyncHttpClient
proc request(client: AsyncHttpClient; url: string; httpMethod: string; body = "";
            headers: HttpHeaders = nil): Future[AsyncResponse]
  first type mismatch at position: 1
  required type: AsyncHttpClient
...etc

Is this normal? "body: None"

Kaushal Modi
@kaushalmodi
hmm.. future is renamed to sugar on devel?
Danil Yarantsev
@Yardanico
yes it is
From IRC (bridge bot)
@FromIRC
<miran> yup
Andreas Rumpf
@Araq
<AsyncHttpClient, url: string, body: None> is the problem
plus some wrong compiler error message :-)
Govind KP
@reisub0
Are these optional parameters or are they all compulsory?
I did manage to get it to compile on this gist
From IRC (bridge bot)
@FromIRC
<Yardanico> @reisub0 if a proc has argument like "someName = someValue" then it's optional
<shashlick> @Araq: just posted about tissue on the forum - https://forum.nim-lang.org/t/4008
Govind KP
@reisub0
@Yardanico Well, that doesn't make any sense because, then, it should have matched the proc prototype?
Kaushal Modi
@kaushalmodi

this obviously doesn't work:

import sugar
echo 1.(x => x + 1)

what's the correct syntax?

From IRC (bridge bot)
@FromIRC
<miran> you're missing map
<miran> oops, no