Do you mean from Nim to Python or from Python to Nim? Which use cases do you
have in mind?
Good point. This comes up from time to time in the forum. It would be really
nice if there was some documentation on `testament` (or if there's some, a link
to it). Also, I vaguely remember that `testament` also has disadvantages over
`unittest`, so the tradeoff when to use one or the other shou
I think for small simple modules it's ok to have the tests (with doAssert, not
assert) in the same file. Apart from that, I prefer a test module using the
[unittest](https://nim-lang.org/docs/unittest.html) module for each module to
test.
In my experience, putting the tests in the same file as
What I meant here is that in some cases you can use object variants where you
would otherwise use inheritance in a more "traditional" design. That doesn't
mean that object variants can do everything that inheritance can do. Both
object variants and inheritance are different design tools and thei
I don't expect that you can replace _all_ uses of inheritance with object
variants. But some. :-)
gested I should write down the changes first to discuss them on the Nim
forum.
So here are the potential changes:
[https://gist.github.com/sschwarzer/ff9f3f7092f132b17e2b33e7a5a2fe81](https://gist.github.com/sschwarzer/ff9f3f7092f132b17e2b33e7a5a2fe81)
. What do you think?
Just to be sure, are you using the command `Nim` (uppercase N) or `nim`
(lowercase n)? The command is `nim` (lowercase n).
There's the Nim package manager [Nimble](https://github.com/nim-lang/nimble)
and its README has a section on [project
structure](https://github.com/nim-lang/nimble#project-structure).
Also, if you use `nimble init` on the command line, it will create the
structure for you to have an easy start.
Python code usually uses a _leading_ underscore to mark an identifier "private"
and _trailing_ underscores to distinguish identifiers from keywords.
[https://www.python.org/dev/peps/pep-0008/#descriptive-naming-styles](https://www.python.org/dev/peps/pep-0008/#descriptive-naming-styles)
> I'm surprised noone answered OP's question so far.
The question was why the code shown by the OP wasn't possible in Nim. :-)
> Since Nim is not a functional, but imperative language,
I think we shouldn't think too much in language categories. If a language is
mostly imperative, this doesn't m
Here's a Nim library for pattern matching on values:
[https://github.com/alehander92/gara](https://github.com/alehander92/gara)
The reason I suggest comparing against Python 3 is that Python 2 is no longer
supported by the CPython project. Also, by far most of the people who start
with Python will use Python 3.
If Python 2 is faster in many string benchmarks that's most likely because the
default string type in Python 2
For the record: In Python 3, "some string" is a unicode string where the items
are code points. The model more similar in semantics to the Nim version is the
`bytes` type. That said, I get the same time for multiplying `b"x"` (`bytes`)
as for `"x"` (`str`).
I can imagine migrations that don't change the schema. For example, you have a
`varchar` field and change the format from `part1 - part2` to `part2 - part1`,
i. e. swap two strings in the same string attribute.
Two things about the Python version:
* Using `xrange` tells me you're on Python 2. I suggest you use a
current/recent Python 3 version for your benchmarks.
* The recommended way to concatenate a big number of strings is with
`separator.join(iterable)`.
So you could use: `s = "".join(("x"
I'm interested in the following use case:
type
MyType* = object
x: int
...
proc x*(mt: MyType): int =
# This is also the user API for the type.
# Have some side effect, for example update a cache.
...
mt.x
var mt = MyTy
Hm, it's clearly after Tuesday now and the conference is only two days away. It
would be really nice to get a timetable of the talks. :-)
> I don't like popularity, I like what it comes with popularity: more brains,
> more libraries, better maintained packages, ... This thread could be titled:
> "Nim's ecosystem" or even better "How could Nim's ecosystem be improved".
Agreed, I wouldn't go for popularity in itself, but for the imp
ly do other things with the node.
...
Run
If you delete a node, the iterator doesn't descend into the children of the
deleted node. Recursive iteration continues with the node after the deleted
node.
I have an [implementation](https://hg.sr.ht/~sschwarzer/lazytree/browse) th
> Now that I think more about it, with the current implementation, I'd expect
> this behavior:
>
> * If you delete a node and insert another node instead, the iterator should
> go over the child nodes of the new node. I think that's actually reasonable.
> * If you insert a node after the one
Many thanks for your feedback!
> Your test suite looks like it could maybe use a mixture of inserts & deletes
> in either order while iterating
The inserts are "missing" because they were not relevant for my use case and I
hadn't thought a lot about them. As far as I did think about insertions,
I also recommend including the branch name in your shell prompt. For bash, I
have in my `.bashrc`:
PS1='\u@\h:\w$(__git_ps1 " [%s]")\$ '
Run
Depending on your distribution, you may need to install a package or source
some shell script to the `__git_ps1` command. For
I assume the pull got you stuck in a merge because of a merge conflict. The
output of `git status` should say something about this. If it's confirmed by
`git status`, you can either try to resolve the merge conflict by editing the
file, `git add` it and use `git merge --continue`, or you can sto
I just saw this is mentioned as a possible enhancement in
[https://github.com/nim-lang/Nim/issues/5114](https://github.com/nim-lang/Nim/issues/5114)
.
Um, _what_ was the initial goal then? :-)
Maybe we could add the question "Where do Nim's name and logo come from?" or
something similar together with the answer to the FAQ (even if it's not
strictly a _frequently_ asked question ;-) ).
@cblake Thanks for your encouragement, it _did_ motivate me. :-) Unfortunately,
I only found the time this week.
So finally, here's a new take on the recursive tree iterator:
[https://hg.sr.ht/~sschwarzer/lazytree](https://hg.sr.ht/~sschwarzer/lazytree)
(clone with
hg
For me, from this thread and the blog post it always looked like the
registration was only for the case that you want to give a talk. So "regular"
participants maybe wouldn't look at the form to begin with.
That said, I had looked at the form when the conference was announced for June
1st, but
After thinking more about it, I suppose the problem with understanding isn't
about hitting a wall, but the nature of the wall. ;-)
In this forum, there are frequently questions along the lines, "How can I make
this Nim code faster?", so you could say the post authors _did_ hit an
optimization w
As long as the audience is just watching a stream, I agree. Participants also
talking to each other, possibly in groups or with video, would be more
complicated.
Maybe we can target this for a future conference. :-)
I know the expression, but even then I might not have been sure about the
meaning in this context.
What about putting the time and the "location"/technology for the conference in
the blog post? Or would you rather add these details in an upcoming post? The
end time might depend on how many talks we have.
The conference time (or at least timezone to get an idea) is rather important
because de
> "Idiomatic Nim code is fast and Nim does not have "optimization walls." "
To me, the "... Nim ... and Nim ..." doesn't flow so well. What about
"Idiomatic Nim code is fast and there are no "optimization walls" if you want
to make it even faster."
(even if it's a bit longer)? But I guess this
Sorry for nitpicking ... ;-)
> > It's not that Nim is fast, it's that Nim does not have "optimization walls."
>
> Great quote! Can we put it on the website? It says in one sentence what I've
> always tried to express.
If I was completely new to Nim, this sounded to me like "Idiomatic Nim isn't
Regarding `with` and `else` in Python:
$ cat with_else.py
with open("/etc/passwd") as fobj:
pass
else:
pass
$ python3.8 with_else.py
File "with_else.py", line 3
else:
^
SyntaxError: invalid syntax
Run
At least
The output is hard to read. You can use literal (code) formatting by putting
triple backticks on a line before and after your code, [as in
Markdown](https://github.com/adam-p/markdown-here/wiki/Markdown-Cheatsheet#code-and-syntax-highlighting).
Syntax highlighting also works.
I'm really tired of these tabs vs. spaces discussions.
There are good reasons for either approach, and I don't see why one approach
would be _objectively_ better than the other.
People who prefer the pro/con combination of tabs over the pro/con combination
of spaces, prefer tabs.
People who pr
Here's a thread on the version numbering:
[https://forum.nim-lang.org/t/5606](https://forum.nim-lang.org/t/5606)
I'm not really after the possibility of leading underscores in Nim. That said,
I'd be interested in what conventions you use to distinguish a private name and
the name of a corresponding accessor proc.
So, which conventions do you use or have seen?
> People don't complain about Python not allowing unicode characters as
> identifiers (something possible in Julia for example).
For the record, Python 3 _does_ allow unicode characters in identifiers. :-)
$ python3
Python 3.7.5 (default, Oct 17 2019, 12:09:47)
[GCC 9.2.1 2
> How underscores improve readability?
The idea is that you could use `_name` for a private field and `name` for an
accessor proc. It's a nice convention. So I agree, it doesn't improve
readability directly, or maybe just in the sense that you avoid less readable
names like my `privateX` above.
> Yet I am new to Nim (coming from C, C++, Python) and wonder, what this.x then
> will mean in my Euler class. Is it the pointer to the method x or is it the
> attribute x?
I tried Skaruts's code in the [Nim
playground](https://play.nim-lang.org/#ix=27xV) and it seems accessing
`Euler(x: 3.0).
_At least_ in Python, an underscore at the beginning of a variable means it's
private and shouldn't be accessed by client code.
At some point I was wondering the same as the OP, but I think in Nim you just
use the `*` suffix to distinguish "public" and "private" fields:
type
Thanks!
I had heard of `npegs`, but so far chose `pegs` because it's in the standard
library and understands standard PEG syntax. That said, `npeg`'s features are
very impressive. :-)
> Afaik, stdlib peg is designed for nim compiler itself and somewhat limited.
So I guess there's not much moti
Assume I have the following PEG definition:
import pegs
let examplePeg = peg"""
A <- {L}? {D}?
L <- \a+
D <- \d+
"""
Run
If I test strings against this PEG, I get:
if "abc" =~ examplePeg:
# `["abc", "", "", "", "", "",
I'm experimenting with a `sorted` proc that takes a `key` argument instead of a
`cmp` argument (see also
[https://docs.python.org/3/library/functions.html#sorted](https://docs.python.org/3/library/functions.html#sorted)
).
This is my attempt (also [on Nim
playground](https://play.nim-lang.org/
Every `XMLNode` [has a kind](https://nim-lang.org/docs/xmltree.html#7) and I
guess the reason you get this error is that you use the `text` field although
the node isn't a text node. In that case you must check the node kind first:
if node.kind == xnText and node.text != "":
It's the other way around; I want to turn a string literal into an identifier.
The
[program](https://hg.sr.ht/~sschwarzer/todoreport/browse/default/src/todoreport.nim)
parses a [todo.txt](https://github.com/todotxt/todo.txt#todotxt-format-rules)
file and displays the information groupe
Thanks a lot everyone. I'm glad it's so simple. :-) I thought I had tried this,
but it seems I didn't. (On the other hand, defining the proc as an anonymous
one actually was something I tried.)
Now I have a follow-up question. To replace my lengthy proc with the template,
I have to create a cmp
In [my
code](https://hg.sr.ht/~sschwarzer/todoreport/browse/default/src/todoreport/task.nim)
I have a proc that returns a `cmp` proc for sorting with `algorithm.sorted`:
type
Task* = object
isComplete*: string
priority*: string
# We could model the
@FernandoTorres
Maybe this is the posting you had in mind:
[https://forum.nim-lang.org/t/5036](https://forum.nim-lang.org/t/5036)
The related RFC is
[https://github.com/nim-lang/RFCs/issues/19](https://github.com/nim-lang/RFCs/issues/19)
I'd like to see one of these approaches implemented. :-)
Ok, I understand what's the problem with the condition and can reproduce the
bug in a unit test.
These are my thoughts about possible fixes:
* As far as I can tell, the only way to recognize that the client of the
iterator has deleted a child, is checking the number of children in the parent
My top wishes for the Nim _language_ :
* Recursive iterators. Their lack is such a pain for algorithms that are
"naturally" recursive.
* Recursive imports (or another solution?). So far I've only done small
projects, but I can imagine that the recursive module issue can be a huge pain
and I
I'd say my favorite programming language since about 20 years is Python and
it's also the language I use most professionally. I like that it's quite
expressive and has lots of libraries (not only external libraries, but I also
like the standard library a lot). _Especially_ for small tools the la
@e Yes, it seems that's a bug that wasn't revealed by my existing unit tests.
Thank you!
I'll look what I can do. :-)
I've written an iterator over an `XMLNode`:
[https://hg.sr.ht/~sschwarzer/vppdiff/browse/default/src/vppdiff/cleanxmi.nim#L46](https://hg.sr.ht/~sschwarzer/vppdiff/browse/default/src/vppdiff/cleanxmi.nim#L46)
Internally the iterator uses a stack.
Iterator features:
* You can modify the
If you know roughly how large the stack seq can get, you may want to try
[https://nim-lang.org/docs/system.html#newSeqOfCap%2CNatural](https://nim-lang.org/docs/system.html#newSeqOfCap%2CNatural)
to avoid or reduce reallocations.
In a small benchmark I wrote some time ago, using `newSeqOfCap` to
> That is common practice, see
> [https://en.wikipedia.org/wiki/Software_versioning#Odd-numbered_versions_for_development_releases](https://en.wikipedia.org/wiki/Software_versioning#Odd-numbered_versions_for_development_releases)
I wouldn't conclude from the Wikipedia section that it _is_ common
I guess the link to the Python 2 version of the library was only by accident.
If some new functionality in Nim should be modeled after Python, refer to the
documentation for Python 3.
For most older libraries, there shouldn't be a big difference, but for newer
libraries there may be, and even o
I think, as far as usage is concerned, Nim's `marshal` module corresponds more
to Python's `pickle` module. Compared to the `pickle` module, the `marshal`
module has quite a few caveats:
[https://docs.python.org/3/library/pickle.html#comparison-with-marshal](https://docs.python.org/3/library/pic
Currently I use the [unittest module](https://nim-lang.org/docs/unittest.html)
from the standard library and `nimble test` to test [my
code](https://hg.sr.ht/~sschwarzer/vppdiff/browse/default/tests/test_cleanxmi.nim).
I like unittest's DSL. The tests look very clean.
What I miss is
Here are some ideas/tips I use to navigate unknown code.
* As others have said, if possible use an IDE/editor that can go to
definitions.
Regardless of having an IDE or editor:
* Even if you know the module from using `from module import nil`, you don't
necessarily know _which_ proc is t
I wouldn't be so harsh. Sometimes things seem so "obvious" that it doesn't
occur to you that you may be wrong. I think this can happen to everyone. As the
article I linked points out, the imports in Nim are often misunderstood. When I
learned about Nim, I was also at least a bit suspicious.
There's a pretty good article on this subject at
[https://narimiran.github.io/2019/07/01/nim-import.html](https://narimiran.github.io/2019/07/01/nim-import.html)
:-)
Ouch, of course. I didn't see the forest for the trees. Thank you.
I'm writing a small tool in Nim and ran into the compiler error "expression ...
has no type (or is ambiguous)".
Here's a simplified example that still gives the error message:
[https://play.nim-lang.org/#ix=1Z5M](https://play.nim-lang.org/#ix=1Z5M)
Granted, the cleanedXmi proc has no return typ
I suppose the reason why I might want to override the compiler's analysis would
probably _not_ be that I want to "risk it" despite GC-unsafe code. I'd use the
pragma because there are - hopefully - clear rules what is GC-safe and what
isn't and I'd want to override the compiler in case the code
Re 1.: How would I be able to tell whether the code is safe in the future? Will
there be a new definition of "GC-safe" at some point or was my understanding of
GC safety wrong to begin with?
Thanks for your answers and the code suggestion. I see what you're doing here,
but I need the same temporary directory for all threads. :-)
Would the approach with `deepcopy` [as in the
manual](https://nim-lang.org/docs/manual.html#threads-gc-safety) be safe?
import os
import p
I have the following program:
import os
import posix_utils
import strformat
import threadpool
let tempRootPath = mkdtemp("vppdiff")
proc xmiFilePath(fileNumber: int, cleaned: bool): string =
let cleanedSuffix = "_cleaned"
return tempRootP
Thanks for your extensive reply!
I think I see where our misunderstanding comes from. As I understand, you're
seeing the term "open source" literally from the perspective of an individual
user. In contrast, my perspective is that of a software maintainer picking a
license for their publicly vis
The reason why I think the Peer Production License doesn't comply with the open
source definition (point 5) is that, even though the license doesn't restrict
_all_ commercial use, it restricts _some_ commercial use (point 4 c and d).
This isn't visible in the boxes at the top of the respective p
I find the license more restrictive than the open source definition. ;-)
As nice as the [project website](https://nimwc.org/) looks, I'm honestly a bit
confused about the
[license](https://github.com/ThomasTJdev/nim_websitecreator/blob/master/LICENSE),
which is linked from the website.
If I understand correctly, according to the [open source
definition](https://ope
I agree with Nimster and Stefan_Salewski. The proc does something quite
different from what its name (to me and probably most people) suggests.
Admittedly, the _use_ of the proc makes you look a second time at it and see
what the proc does, but still I wouldn't count this example as a good one.
I'm currently not using Nim for scientific computing, but I'm quite interested
in what's going on in this area and follow related discussions in the forum.
Have you tried reading the file and printing the start of its contents - at
least up to and a bit beyond the first null byte as known from the hex editor -
as hex strings to stdout? That way you could at least check if the problem
already occurs when reading.
What does the Nim support in Geany cover?
Originally, I used a Nim plugin for Vim which gave me "only" syntax
highlighting, but now I don't want to miss completions and "go to definition".
I find this very helpful, especially since I'm rather new to Nim.
I use the same combination. :-)
> Python, I started to learn Python and found it quite easy to pick up, however
> I decided that its growing way to big as a language, too many people are
> changing it too much, and for me on Windows it just became another scripting
> language, no better than say Perl... and yes Python may be v
As I understand it, this is still a pull request that hasn't been merged.
I think having aliases would be great, but I also see the potential conflict
with already defined operators that is mentioned in the comments of the PR.
> Typing nimble install blah is not hard. Those libraries can be as
> multiplatform as the stdlib.
In my opinion the main advantage of having a GUI toolkit in the standard
library isn't that it's easy to install (although that's a big plus), but that
there is a _default_.
> Python's "standard
I just found
[https://github.com/nim-lang/RFCs/issues/19](https://github.com/nim-lang/RFCs/issues/19)
which discussed the issue and has two suggestions for a possible syntax. (I had
already used a generic web search, but now searched in the Nim tickets.)
One of the syntax suggestions would look
It's worse if you have something like this:
type
MyKind =
enum kind1, kind2, kind3
MyObject = object
case kind: MyKind
of kind1:
field2: string,
field3: string
of kind2:
field1: string
field3: s
I'd like an object variant where both variants have the `kind` and `field1`
fields, but only in case of `kind == kind2`, I want an additional field
`field2`.
I can model this with
type
MyKind =
enum kind1, kind2
MyObject = object
case kind: MyKind
I'd like to define clean-up actions on an XML tree.
I have two clean-up kinds, one for removing whole nodes (specified by name),
another one for removing attributes on nodes with a given name (specified by
node name and attribute name).
At the moment, I'm modeling this with object variants:
@juancarlospaco Thanks!
firejail seems to do _much_ more than I want, and from reading a bit about the
Nim package and the underlying library, I must admit that I don't even
understand how I would apply it to my usecase. I only want to call the external
process from a small command line program
@Araq Thanks, I'll try it. :-)
First some background about me: I started to use Nim only recently. It looks
very interesting. :-) My programming experience of the last 20 years is mostly
Python (wrote a book and several articles, and gave about 15 talks), but I also
programmed in compiled languages, e. g. Pascal, C++ and Fort
88 matches
Mail list logo