Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • Apr 04 12:26
    @dom96 banned @acroobat
  • Mar 03 2017 15:52
    @dom96 banned @Octopoda7
  • Feb 12 2017 23:57
    @dom96 banned @zzz125
  • Dec 23 2016 19:43
    @dom96 banned @Izrab
Alexander Ivanov
@alehander92
my pr
Helmut Jarausch
@HJarausch_gitlab
I'd like to write a proc 'Sum' which has a can be passed a Slice or 'countup(...)'. What type should this parameter have. I cannot pass 'countup(..)' to parameter of type Slice. Thanks for a hint, Helmut
From IRC (bridge bot)
@FromIRC
<PMunch> Well, unfortunately for you countup is an iterator
<PMunch> And iterators (not closure iterators) work by rewriting the AST, so they don't really have a type as such
<PMunch> There is a way around this however, and that is by creating an Iterateable concept and wrapping it in a closure iterator
<PMunch> Or by making your sum proc a macro instead
From IRC (bridge bot)
@FromIRC
<FromDiscord> <haxscramper> Or make a proc that returns closure iterator. https://play.nim-lang.org/#ix=2F5i
<FromDiscord> <haxscramper> Kind of strange there is no items overload for closure iterators though
Helmut Jarausch
@HJarausch_gitlab
@PMunch How to "Iterateable concept and wrapping it in a closure iterator". @FromDiscord thanks for the example, still, I don't see how to pass [in Python syntax] either 'range(0,7)' or 'range(0,7,2)' - and 'Sum' was only a simple example
From IRC (bridge bot)
@FromIRC
<PMunch> Weeeell, it's a bit tricky..
<PMunch> For now just create a template wrap that wraps an iterator into a closure iterator and use that instead
咚咔
@cupen
In nim way, how to write for (int i = 0; i < 100; i++)??
From IRC (bridge bot)
@FromIRC
<PMunch> for i in 0..<100
咚咔
@cupen
Thanks
From IRC (bridge bot)
@FromIRC
<FromDiscord> <haxscramper> @HJarausch_gitlab if you only need something like python range you can do it just ifne with regular iterators - https://play.nim-lang.org/#ix=2F5t
<FromDiscord> <haxscramper> Although range is an identifier name for a type from system, so you might want to use different name. That is, for python-like 'range'
<PMunch> @haxscramper, I think he wants to take the equivalent of Pythons range as an argument
<FromDiscord> <haxscramper> Then https://play.nim-lang.org/#ix=2F5y
From IRC (bridge bot)
@FromIRC
<FromDiscord> <haxscramper> Python's range is a class actually (I thought it is some kind of magic built-in) with index index defined, so example above should be pretty similar both from use-case standpoint and implementation (object (or object-like thing in case of iterator(): int) with some special magic going on inside).
Helmut Jarausch
@HJarausch_gitlab
@FromDiscord Yes thanks, that's exactly what I was looking for. Still, why do I need that 'iterator itemsT: T): T', isn't that built into Nim already?
From IRC (bridge bot)
@FromIRC
<FromDiscord> <haxscramper> apparently no, although I was also surprised that it isn't
<FromDiscord> <haxscramper> E.g. it is probably very logical thing to do
<FromDiscord> <haxscramper> when you have closure iterator and want to use it in for loop
<FromDiscord> <haxscramper> Maybe I should just PR it into stdlib now
Helmut Jarausch
@HJarausch_gitlab
I'd like to suggest to extend the 'collect' macro to include (standard Nim's bit) set. If that would be available I wouldn't need that "passing an iterator around" stuff in my current case. Still, it is very interesting.
From IRC (bridge bot)
@FromIRC
<FromDiscord> <lqdev> that's a good idea
<FromDiscord> <lqdev> i'm quite surprised it doesn't support them
<FromDiscord> <lqdev> probably an oversight
<FromDiscord> <lqdev> @HJarausch_gitlab can you open an issue on github?
<FromDiscord> <haxscramper> https://play.nim-lang.org/#ix=2F5K
<FromDiscord> <haxscramper> It does support set[T]
<FromDiscord> <haxscramper> But again, you need to use some non-obvious proc initSet[A](): set[A] = discard thing
<FromDiscord> <haxscramper> Which does not come with stdlib
From IRC (bridge bot)
@FromIRC
<FromDiscord> <haxscramper> I can add initSet too - will be PR'ing items for iterator(): T anyway so
<FromDiscord> <haxscramper> Although I don't know where I should put it exactly. newSeq is in std/system, probably makes sense to add initSet too.
Helmut Jarausch
@HJarausch_gitlab
@FromDiscord I've tried to adapt your example (https://play.nim-lang.org/#ix=2F5R) but is crashes Nim 1.5.1 git hash: d9038ed792b923cfbb9593ab82825fdb48728adc)
From IRC (bridge bot)
@FromIRC
<FromDiscord> <lqdev> @haxscramper imo something like collect(set[uint16] {}) should be supported too
Helmut Jarausch
@HJarausch_gitlab
I've fixed my example https://play.nim-lang.org/#ix=2F5T but it still crashes
From IRC (bridge bot)
@FromIRC
<FromDiscord> <lqdev> btw @HJarausch_gitlab, FromDiscord is the bot that bridges discord to IRC and Gitter. if you want to ping any of us, use the name in <> in the bot's message
<FromDiscord> <haxscramper> nnkCall, nnkIdent, nnkSym - @HJarausch_gitlab you can only use identifier or call in collect argument
<FromDiscord> <haxscramper> E.g. you probably expect it to work like this, but not it is not supported. But probablt should be though,
<FromDiscord> <haxscramper> Becase it took me a good 10 minutes to figure out how return types are derived from argument+body
<FromDiscord> <haxscramper> E.g. collect(seq[int]) is perfectly reasonable way to write things
<FromDiscord> <haxscramper> Well, not 'reasonable', but I can clearly see how someone tries to do this
<FromDiscord> <lqdev> the details are revealed if you use collect(set[uint16]({})) - it does set[uint16]({})[typeof(<body>)]
<FromDiscord> <lqdev> but you have to have an understanding of macros to actually know what the error message means
<FromDiscord> <haxscramper> If only expandMacros worked for malformed code. But I guess it is quite hard to do right in the first place
咚咔
@cupen
Sorry, I have a new stupid question. why it's a syntax error?
proc new*(url: string): Benchmarks =
  var u = uri.parseUri(url)
  var obj = Benchmarks(url:url, host:u.hostname, port:parseInt(u.port).Port)
  obj.client = redis.open(host=u.hostname, port=parseInt(u.port).Port)
  obj.init()  # Error: attempting to call undeclared routine: 'init'
  return obj

proc init(this: Benchmarks): void =
  var key = "nim_redis:test"
  var val = "Hello World"
  this.client.setk(key, val)
  var resp = this.client.get(key)
  assert resp == val

oh, I see.

proc init(this: Benchmarks): void =
  var key = "nim_redis:test"
  var val = "Hello World"
  this.client.setk(key, val)
  var resp = this.client.get(key)
  assert resp == val


proc new*(url: string): Benchmarks =
  var u = uri.parseUri(url)
  var obj = Benchmarks(url:url, host:u.hostname, port:parseInt(u.port).Port)
  obj.client = redis.open(host=u.hostname, port=parseInt(u.port).Port)
  obj.init()
  return obj

this would be ok.

Helmut Jarausch
@HJarausch_gitlab
Oh well, yet another problem. If I invoke Nim as
nim c -d:DEBUG:true -r mytest.nim
how can I get at the value of 'DEBUG' within a 'when' clause in mytest.nim?
Checking
when defined(DEBUG)
works.