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
Andreas Rumpf
@Araq
there are no "named" blocks. you can pass a block to a "routine"
Kaushal Modi
@kaushalmodi
Araq: OK
Andreas Rumpf
@Araq
well block foo: stuff would be a named block.
but that's not what we're discussing.
Kaushal Modi
@kaushalmodi
Yes, I was confusing foo: with that..
so foo: and foo(): are the same in those 2 examples above?
This discussion cleared up my confusion regarding the "special colon". I was focusing on the template definition as the wording used "parameter".
How about: "You can pass a block of statements as a last argument to the template call following a : as shown below:"?
Mamy Ratsimbazafy
@mratsim
why call? just “to a template” is enough no?
Kaushal Modi
@kaushalmodi
There were too many colons involved to confuse a template learner like me..
Colons in the template signature, try/finally blocks and finally where the template is "called"
So I want to tell the reader which exact colon that sentence is talking about
Vindaar
@Vindaar
One could maybe just add a comment to the example in the manual to highlight the line which is meant by the "special colon"
Kaushal Modi
@kaushalmodi
That works :)
Kaushal Modi
@kaushalmodi
Done in nim-lang/Nim#8133.
Vindaar
@Vindaar
:)
From IRC (bridge bot)
@FromIRC
<miran> btw, should the changes to the manual like this one be merged to devel or master?
Andreas Rumpf
@Araq
devel.
From IRC (bridge bot)
@FromIRC
<miran> ok
Kaushal Modi
@kaushalmodi
@mratsim and Araq: About https://gitter.im/nim-lang/Nim?at=5b3392066ceffe4eba37a337, I was referring to a hypothetical template use case like:
template foo(inp: string; body1, body2, body3: untyped) =
  case inp
  of "a":
    body1
  of "b":
    body2
  else:
    body3
Looks like, that's not doable?
The challenge is how would a user differentiate between body1, body2 and body3 arguments when using the template.
And my final template/untyped question for today. In https://nim-lang.org/docs/manual.html#templates-passing-a-code-block-to-a-template, the first example has return type as untyped, while the second example has no return type.
When do you need to set the return type of templates as untyped?
Mamy Ratsimbazafy
@mratsim
@kaushalmodi use a static string and “when” to switch at copile-time
untyped is useful to make sure the replacement is done before any semantic checking/type resolution
From IRC (bridge bot)
@FromIRC
<skrylar> just spitballing, but there might be a (probably obscure) opening to wedge nim in for sandstorm.io apps
<skrylar> was re-reading and poking it earlier and they are hit pretty hard by high-ram use middleware
Kaushal Modi
@kaushalmodi
@mratsim About the multiple bodies, I didn't understand how to apply what you said to that template. But I'll leave this question open for now as I don't yet have a real use like in that example.
About untyped being useful to make replacement before type checking.. I sort of understood that, but trying to fit some logic w.r.t the return type for templates. Isn't the return type of templates technically "void"? Because crudely speaking, they just replace the template instance with the template body?
So they aren't "returning" anything..
As an aside, the Nim tutorials, manual, etc. site are nicely readable in Emacs eww browser :)
image.png
Kaushal Modi
@kaushalmodi
Above screenshot (Nim Manual site on left, notes on right)
From IRC (bridge bot)
@FromIRC
<Araq> eww
Kaushal Modi
@kaushalmodi
yeah.. funny acronym
Emacs Web Browser
*Emacs Web (W)owser
Vindaar
@Vindaar
@kaushalmodi Do you have an example as to when and how you'd use such a template with multiple bodies?
Kaushal Modi
@kaushalmodi
@Vindaar No, I don't have a real use case. But that pseudo code shows how multiple bodies can probably be used.
Vindaar
@Vindaar
If one were to use such a template, would you want the user to supply all 3 bodies?
Kaushal Modi
@kaushalmodi
Think of wrappers for parsing CLI args, or user entered inputs.. where that template could be doing lot more than just adding a case statement.
Mamy Ratsimbazafy
@mratsim
template foo(): int = 1 does not return void
to fold over a tensor in parallel with: initialization body, folding, merging the parallel folds.
Kaushal Modi
@kaushalmodi
@mratsim That's a pretty concise and good example.. shows me that you cannot always leave out return type for templates. Thanks.
From IRC (bridge bot)
@FromIRC
<Araq> no, you can never leave out the return type. for templates or anything else.
ephja
@ephja
yeah I think libsoundio does spawn a thread. the inattentive brain strikes again :p
From IRC (bridge bot)
@FromIRC
<Araq> unless it's 'void'
Kaushal Modi
@kaushalmodi
If a template is accepting a block of statements, then is it safe to then always set its return type to untyped, in case you cannot be sure if the body will have a void return type?