It is time for [Advent of Code 2018](https://adventofcode.com/)!
Nim is organizing [private
leaderboard](https://adventofcode.com/2018/leaderboard/private) where you can
compete against other Nim users. To join the Nim leaderboard, all you have to
do is use `40415-c732e66e` code in the previous
> What's a FE lib?
Did you, just as I did, thought this might be about Finite Elements? :)
After I've read the whole thread, I'm guessing it means Front End.
> But strict typing is killing us
I'll repeat what I have already tried to tell you several times, based on the
examples/questions you have posted previously.
I don't think 'strict typing' is what is killing you. It is your idea to do
things "the old way", like you did them in some other langua
> I want an object field to be able to handle two differents types with a clean
> syntax on the user side
Take a look at [Object
variants](https://nim-lang.org/docs/manual.html#types-object-variants) section
in the manual, maybe that is something you can use in your case.
> any major changes in the last few months?
You don't have to initialize your strings and sequences manually anymore.
@moerm
> So I find it utterly illogical to have Myvar, myvar, MyVar,My_var, my_var,
> My_Var, all boiling down to one and the same.
They are not one and the same. The first letter is case-sensitive.
* * *
@shashlick
> my vote is to liberalize further - no restrictions with (...) case sensitiv
> I am not experienced enough to see where I could make improvements.
I've just skimmed through your repo and the first place where I would start
with the improvements is that [loong case
statement](https://github.com/NIMNIMNIMNIM/NIM16/blob/master/src/engine.nim#L121).
You coul
;)
> I am using python
In Python variables are allowed to exit the scope of the loop/conditional where
they're defined. For example:
for i in range(5):
print(i)
print(2*i) # prints 8
Run
In Nim these kind of things are not allowed, as others have already
> invalid type: 'Complex'
It might have to do with [the recent
changes](https://github.com/nim-lang/Nim/commit/cc5b8c6ad25b2db62274ca8fa76c4a5b3e794515)
of the Complex type.
We have 1400+ open issues.
Is the name of the devel branch (How many of total Nim users even use devel
branch? How many of them care about its name?) really something we should spend
our time discussing?
Look at the error and what it tells you:
> Error: type mismatch: got but expected one of: proc sleep(milsecs:
> int)
Your `sleeptime` is `int64`, and `sleep` procedure expects an `int`.
The easiest way to fix this is to convert `sleeptime` to `int`:
sleep(sleeptime.int) # the sa
> (P.S. Would someone kindly tell me how to get code properly formatted here?)
For inline code put double backticks around your code block. (RST-way)
For code block, put three backticks followed by 'nim', and then paste your
code, and then finish with three backticks. (markdown-way)
(Yes, it is
> handy function like 'ifelse' in R
Yes, you can do `let c = if a == b: a*b else: a+b`
If you want to operate on vectors/arrays like that, you might need to define
your `+` and `*` functions.
I know that moderation on this forum is quite loose, but please @kcvinu, we
have high-quality general discussion here, don't thread-jack this one with your
personal problems.
> This is the result of dumpTree
... for something else, not for your example ;)
* * *
I have made your macro, but I won't (yet) post a complete solution. I'll try to
guide you so you can make it on your own.
This is what I have before I even start with macro:
import macros
Use `dumpTree` to see if your DSL (your second snippet) is valid. (It isn't.
You need to lose the dots in front of every line)
* * *
Next, you can use `dumpAstGen` on the wanted result (your first snippet) to see
what your final results look like. This does 90% of the job for you — you can
cop
You can specify just the first member:
const LOOKUP_TABLE: array[4, byte] = [byte(1), 2, 3, 4]
Run
If that's ok with the others, I would like to delete the rfcs repo, since that
is the only way to delete "my" 88 issues (these have ruined my Github
profile/dashboard).
After that, we can open a new, clean, rfcs repo.
> I don't think we can have two templates in the same repo: one for issues and
> one for RFC-s.
I've checked and it allows me to make multiple templates. So this shouldn't be
a problem.
> What is the problem with PascalCase ?
You are making your code harder to understand. For some style guidelines see
[https://nim-lang.org/docs/nep1.html](https://nim-lang.org/docs/nep1.html)
-1 if it stays the way it is (it really messed up my Github profile, as I later
realized), but I'm not against rfcs repo per se.|
---|---
I agree with the comments that we should review the existing proposals and
close the ones that do not satisfy some minimal criteria or are not relevant
There was an idea by @araq to move all (future) RFC-labeled issues to their own
repo. But the problem is: what to do with the current issues? (You cannot just
move issues from one repo to another)
Fortunately, we found a script which helps with transferring the existing
issues to a new repo. Yo
> We can add a Github issue template
+1
This should standardize what a good issue looks like (e.g. the code that fails,
its output, the expected output, etc.) and it will make it easier to reproduce,
test, and finally fix it.
> There are currently 144 open pull requests
>
> the faster PR's get reviewed/merged, the more likely a PR author will be to
> contribute more PR's, leading to increased rate of bug fixes and enhancements.
Just a quick update for those who don't follow Nim's github.
Since @Araq has returned fro
> I want to install 0.19 but i am afraid that whether my current code will work
> or not.
0.19 brings lots of improvements and bugfixes, my recommendation would be to
use it.
And if you want to have multiple versions installed, and you want to easily
switch between them: [choosenim](https://gi
> it is like driving a car without any knowledge of physics and how engine,
> gears and brake basically work internally. Fortunately most people know the
> basics already.
Fortunately, most people drive cars just fine without any knowledge of "how
cars really work internally" ;)
Source: my fri
> Where Beginner means more someone with some programming experience but new to
> Nim, not someone with absolutely no computer-programming background.
I've tried to make Nim Basics fall as much as possible in the latter category
(while keeping it reasonably brief, and moving at a reasonable pace
> all of the existing documentation uses it...
...wrongly ;)
E.g. The amount of single backticks denoting code/verbatim (like it is in
markdown) instead of double backticks (the RST way) is astounding.
> Araq is on vacation as far as I can tell
And that should not be a reason to have zero commits, zero merged pull
requests, and zero closed issues* for four days.
OP is exactly about that: if Araq is busy or absent, this should not put the
whole project to a halt!
* Besides three issues closed
> works both perfect
@cblake's version works only if the length is power of two, my version should
be more general
To mitigate negative numbers you need to add the length of the array:
`i = ((i - 1) + 4) mod 4`
leaving you with:
`i = (i + 3) mod 4`
See the error message:
> type mismatch: got but expected 'tuple of (int8,
> OneRow)'
It seems to me that your `return (0, @[])` is not automatically converted to
`'tuple of (int8, OneRow)'` like you would expect. See if changing that line to
`result = (0, @[])` solves the issue.
> it's hard to know when the example ends and real code begins (indent is not
> that clear)
Agreed.
To partly mitigate this, I decided that the initial indent of runnableExamples
in my code should be 4 spaces instead of two. (I've tried even larger
indentations, but it becomes awkward very soo
Thank you @flaviu for taking you time to go through the examples!
* * *
> I generally prefer keeping the scope of local variables as small as possible
I used to do that, but at some point I decided to declare the variables outside
of the loops. I thought it might be a bit faster, but it is prob
A new version of [Nim basics](https://narimiran.github.io/nim-basics) tutorial
is out.
It uses Nim 0.19.0, meaning sequences and strings are automatically initialized
so we don't have to do it explicitly. (But there is a note for users of older
Nim versions)
And if you haven't seen it in the l
On my end `nim cpp` is twice _slower_ than `nim c`.
Oh and btw, whichever version of code you use — the result is not correct ;)
Try running `fib(2)` and you'll see what I'm talking about.
> Sorry for disturbing you with my questions. Next time, when i face any
> obstacles in nim coding, i will insist myself to not to ask in this forum.
Please read the wiki article I linked. Not only that you shouldn't react like I
was personally attacking you, but you you should see that the arti
> [XY problem](https://en.wikipedia.org/wiki/XY_problem)
> This gave me error.
>
> `var mySeq : seq[ int | float | string]`
This cannot be used for declaring a variable, but you can use it for arguments
in a function:
proc foo(a: seq[int|float|char]): string =
return $a[0]
echo foo(@[3, 5, 7])
echo foo(@[3.5, 5.7, 7.3]
> (But i think you forgot to init the seq with "@[]")
@mratsim is using `devel` version of Nim, and in it (and in the upcoming v0.19)
you don't have to explicitly do that anymore. (The same goes for strings)
> But I think it needs more correctness tests.
Indeed!
My quick and dirty test showed these results:
[fraction = $result: dtoa(result)]
7 / 3 = 2.333: 2.3337
10 / 3 = 3.333: 3.3337
7 / 6 = 1.167: 1.1666
Can this be part of v0.19 pretty please?
("5 time faster float to string conversion" would look really nice in the
release notes :))
> For reading, there should be good articles which written for beginners.
[Nim basics tutorial](https://narimiran.github.io/nim-basics/) is written with
beginners in mind. But it teaches only the basic concepts (which should be
enough to continue the exploration on your own).
> all articles abo
The pseudo code you have written is **exactly** the thing that cascade helps
you to do.
The example in cascade's readme is quite straight-forward and I don't see why
that would be "chinese" nor why there is a need to dismiss templates/macros
(written by somebody else, in this case) because of "
> Is there any container data type like list in Python ? In which, we can put
> int, float, string, objects etc at the same time
If you're using lists in Python for that — you're not using lists, you are
_abusing_ them!
Although Python allows lists to have elements of a different type, you shou
Thanks for taking the time to analyze the problem!
I was surprised what were you talking about, until I realized these are my
solutions for AoC **2016** (not 2017) :)
In the mean time, my Nim knowledge has improved — here are my [AoC 2017
solutions](https://github.com/narimiran/AdventOfCode2017
I've played a bit with this and I have created a simple macro (as a part of my
macro-learning process):
import macros
macro `?`(a: bool, body: untyped): untyped =
let
b = body[1]
c = body[2]
result = quote:
if `a`: `b` else: `c
> is it possible to create one with the help of templates ? If so, then please
> give me some direction.
See if [this example from the
manual](https://nim-lang.org/docs/manual.html#templates-passing-a-code-block-to-a-template)
helps you.
So basically the existing:
var a = if 0 == 1: 1 else: 2
var b = if 0 == 0: 1 else: 2
Run
with a bit different syntax?
> I put together a reference implementation for a problem that nicely
> illustrates the fundamental principles which make Julia so productive and
> scalable for numeric libraries.
>
> (...)
>
> I can't really imagine writing those in any other language, so I dare you to
> teach me! Use Python
> `let foo:float64 = 200.`, it just doesn't look as something expected to work.
If you're coming from other languages, this is not unusual to see and to expect
it works.
(It is not something I (would) do, but I have seen it in other people's
(numerical) code)
> i don't want to use discard nor anything i want to use my proc without any
> declaration any kind of variables
If you don't want your procedure to return anything (so you don't have to use
discard), don't declare it like it will return a string (`proc input(str = ""):
string`) but like this:
> you made a mistake on the range
`1 .. iterations` is the same (and a bit cleaner, IMO) as `0 ..< iterations`
> I thought the numbers in versions mean year and month, so I wouldn't expect
> 0.19.0 anytime before 2019
By that logic, v1.0 would be released in year [integer overflow]. Seems
accurate enough! :D :D
Congrats to both of you!! Looks like you had much fun, bravo!
@cantanima: see the
[readme](https://github.com/frol/completely-unscientific-benchmarks/tree/master/nim)
for the instructions how to compile.
On my machine, if I use `nim c -d:release main_fast.nim` I get 0.42 seconds,
but if I use what it is recommended (`nim compile -d:release --passC:-flto
> Always use a `main` proc in Nim.
>
> \
>
> I noticed in another thread
> ([https://forum.nim-lang.org/t/1268/1#7848](https://forum.nim-lang.org/t/1268/1#7848))
> Araq telling to wrap the code in a main proc.
That thread is 3 years old. I've been told recently that using `main` is not
re
> the rationale is Python
Python's ranges have upper limit excluded, while Nim has upper limit included.
To mimic Python's range, use `..<`.
> I had the same code from pre-0.18.0 and it worked with ^0,
This reminds me of [this issue](https://github.com/nim-lang/Nim/issues/7444).
The previous behaviour, where null terminator is ignored, is just wrong. You
should change your program and use `^1` for the last character.
* * *
Btw, sin
Windows, version 0.18.0:
'Some String'
> solved, my bad, sorry
It would be much more beneficial if you could also post _how_ did you solve it,
to help others in the future that might search forum for the same /similar
problem.
Thanks @SolitudeSF!
Here are my results for i7-970 hexa-core @ 3.2 GHz. Nim 0.18.1 (devel), GCC
7.3.1, Linux kernel 4.9
10_000_000_000 0.544 secs
50_000_000_000 2.954 secs
100_000_000_000 5.513 secs
500_000_000_000 73.863 secs
1_000_000_000_000 15
Windows 8.1, cannot reproduce.
> I was hoping a few people would be curious enough to run the code and post
> (or send me via email) their results on their systems
Is there a way to easily automate this?
I have tried to call it with `./twinprimes_ssoz 100`, but I still have to
enter manually the wanted number in the next
If you're working with matrices (and don't want to re-invent everything by
yourself), I can recommend using Neo:
[https://github.com/unicredit/neo](https://github.com/unicredit/neo)
> [https://www.youtube.com/watch?v=pXhcPJK5cMc](https://www.youtube.com/watch?v=pXhcPJK5cMc)
There is a port of docopt to Nim:
[https://github.com/docopt/docopt.nim](https://github.com/docopt/docopt.nim)
...and there is count in sequtils:
[https://nim-lang.org/docs/sequtils.html#count,openArray[T],T](https://nim-lang.org/docs/sequtils.html#count,openArray\[T\],T)
> But I encourage, implore, welcome, people to beat on the code to improve it
> and make it faster. What idioms are faster than the ones I used, etc.
Here is [my
gist](https://gist.github.com/narimiran/f9c1df45036cff34a725baad2e89af44) \- I
took your improved version, went quickly through it, a
> show that Nim can be a player in the numerical analysis arena, particularly
> for parallel algorithms
IMO, it would be nice if you would convert this to a blog post, which could be
shared on Reddit/HN/etc.
Maybe something similar to this:
[https://nim-lang.org/blog/2018/01/22/yes-command-in-
Lots of new users here. Decided to BUMP this to see if there are any new
thoughts about it.
Maybe I'm misunderstanding the question, but to me this looks like a case where
you would want to use [tables](https://nim-lang.org/docs/tables.html) instead
of seq.
> Syntactically I would prefer something that aligns the loop variables with
> the containers
Yes, this looks nice.
Btw, a similar syntax exists in Julia, but what it does is completely different
- it is syntactic sugar for nested for-loops.
> Indeed that's a much better syntax, I have absolut
> scientists are also using Python and for any kind of data munching, a repl
> and a data visualization package are non-negotiable.
As a (wannabe) scientist, I can confirm.
Jupyter Notebooks are the tool of trade and they are very very helpful when
prototyping. I was pleasantly surprised when I
> Since vscode doesn't work on all platforms
Wait, what?
[https://code.visualstudio.com/Download](https://code.visualstudio.com/Download)
\- you can have it on Windows, Linux, and Mac.
> There are some updates here:
> [https://github.com/konqoro/nimgnuplotlib](https://github.com/konqoro/nimgnuplotlib)
If the author is reading this - a readme would be very helpful, at least to
tell us why this is preferred over his previous library (gnuplot-nim).
Most of the points you mention are tracked in [Are we scientists
yet?](https://github.com/nim-lang/needed-libraries/issues/77)
> I've coded some simple things myself ...
Maybe you can add some of your stuff to this list
> Hacker News is one of the most popular tech sites and it does not have any of
> these fancy "forum features".
Not true.
> 3\. How do I share a link to a specific comment in the thread?
On HN, this "fancy" feature is available by simply clicking "X hours/days ago"
above the comment. How to do
> > How do I share a link to a specific comment in the thread?
>
> [https://forum.nim-lang.org/t/3534/1#22078](https://forum.nim-lang.org/t/3534/1#22078)
You did that by simply clicking something and not by manually trying to find
the exact message ID, right? Please teach me how.
> The forum looks fine
1\. How do I open a thread on the last comment?
> This forum is fully functional
2\. How do I open a thread on a new comment (one under the last one I read
previously)?
> The forum is very usable
3\. How do I share a link to a specific comment in the thread?
* * *
4\.
> This forum is fully functional
[citation needed]
> Nim Weekly
This seems like too short period to get enough relevant/interesting stuff, but
(once v1.0 is out) "Nim Monthly" might be a good idea!
> What can I do to help get nim to a v1.0 release?
Make [this number](https://github.com/nim-lang/Nim/issues) go under 1000
> Maybe you could ask @Araq what he thinks about this
I just did on IRC and he confirms he is not satisfied with the current
implementation.
I created a [Github issue](https://github.com/nim-lang/Nim/issues/7047).
Thank you for the working example! Now it works as it should.
* * *
Your second example always return 1 in a loop, because it yields a.
Your output is:
1
1
1
1
1
10
100
and one could think new iterators have been invoked (with the starting values
of a
Consider this example:
iterator fibo(a, b: int): int {.closure.} =
var
a = a
b = b
while true:
yield a
(a, b) = (b, a+b)
let x = fibo
for _ in 1 .. 5:
echo x(1, 1)
echo x(10, 20)
echo x(100, 999)
Udiknedormin, thank you for the very detailed and helpful answer!
I changed flip and transpose per your suggestion and transform is now just:
iterator transform(s: var seq[seq[bool]]): seq[seq[bool]] =
for _ in 1 .. 4:
yield s; s.transpose
yield s; s.flip
Thanks for the suggestions, def!
> Compile with -d:release
I always do.
> use seq[bool] instead of seq[string]
Just tried this and it makes no difference speed-wise.
> avoid copying, avoid resizing, avoid allocating more seqs.
I'm too tired currently, but tomorrow I'll see what can I do about
I was solving [AoC Day 21](http://adventofcode.com/2017/day/21), which for part
B asks you to run 18 iterations.
First I've made Python/numpy solution (runs in 0.40 sec), which scales nicely
even to 24 iterations (runs in ~16 sec).
My [Nim
solution](https://gist.github.com/anonymous/bc528ced2c
> Unless I'm mistaken, it seems that seq can accept negative array indexes too.
Unless I'm mistaken, it cannot
The "negative" indices that works are ^1, ^2, etc., not -1, -2.
A wild guess, have you used -d:release flag when compiling?
I've just made a PR:
[https://github.com/nim-lang/Nim/pull/6577](https://github.com/nim-lang/Nim/pull/6577)
> Probably it was on moderation. Now it's visible.
Yeah, it was fixed in the mean time.
Any comments/tips on the code maybe?
I've added [day
12](https://github.com/narimiran/advent_of_nim_2016/blob/master/day12.nim)
solution, and updated some earlier tasks.
Any comments on the coding style? Something I could improve?
* * *
P.S. Why is this thread visible only if I'm logged in?
(This is a copy of a [Reddit thread I posted
yesterday](https://www.reddit.com/r/nim/comments/73dssr/advent_of_nim/))
* * *
I'm a complete beginner in Nim, and I've been trying to learn the basics by
solving [Advent of Code](http://adventofcode.com/2016) tasks.
I have previous Python experienc
201 - 295 of 295 matches
Mail list logo