If so, please make the current aggressive warning an option - and provide
copy() to suppress it. Not sure what the default should be, but one of the the
reason I switched back from C++ back to C is because it's way too easy to
introduce unwanted operations (copies and other) -- which is usually
type GraphMap[T] = ref object
> keyToNode: Table[T, Node]
>
> nodeToKey: Table[Node, T]
proc newGraphMap[T](): GraphMap[T] =
result.new()
result.keyToNode = initTable[T, Node]()
result.nodeToKey = initTable[Node, T]()
You may see Araq's reply in
[https://forum.nim-lang.org/t/4827#30222](https://forum.nim-lang.org/t/4827#30222)
If this really should be not spam then you may see
[https://forum.nim-lang.org/t/5861](https://forum.nim-lang.org/t/5861)
Is there something similar to Java's File.length() method? I would like to know
the immediate disk usage for a directory.
A (1K)
-> B (3k)
-> C (9k)
Here, directory A's immediate disk usage is 1k. What proc provides me this
information?
(Reference Java solution):
public static long
Looks like what you found was a bug in ARC :)
[https://github.com/nim-lang/Nim/commit/8705ee7015382ac2957733dfef5e02a0831e7fb4](https://github.com/nim-lang/Nim/commit/8705ee7015382ac2957733dfef5e02a0831e7fb4)
The underlying mechanism needed for this is here:
[https://github.com/nim-lang/Nim/pull/12372](https://github.com/nim-lang/Nim/pull/12372)
It contains a race condition that needs to be fixed, and then flowVar
refactored to use this mechanism.
Unfortunately, Progress has stalled due to several
I think this warning _would be_ super-useful and a major feature if it would be
supported properly. Copying regular structs is not a good idea - explicitly
notifying users about copies would be nice for performance sensitive programs.
@leorize \- when I use the variable first to calculate the other thing and
_then_ move it, there is no segfault. If I don't move at all there is also no
segfault.
I am just playing around with FFI just for my learning (I am a newbie). I have
the code [here](https://github.com/mantielero/VapourSynth.nim). I will put in
this thread my questions.
My first question is about how to make an struct with methods:
*
how can i satisfy parallel bounds checker in this example?
it fails with
test.nim(18, 19) Error: cannot prove: y * w8 + x <= len(s) + -1 (bounds check)
strutils
import math
import threadpool
{.experimental: "parallel".}
proc getc() : char = 'b'
let
There is no copy() yet, but I think it is good idea. I suggest placing it at
github as a feature request issue.
This warning is much too aggressive, I'm thinking of a better heuristic. One
idea is that the warning will only be produced for `seq` as usually that's the
really expensive copy.
If you do an explicit move, the variable will be cleared, so it can be reused.
The segfault is an indicator of a different problem.
type Example* = object
str: string
code: int
proc x0(s: string): int = s.len
proc x1(b: bool): Example =
var x = "abc"
if b:
return Example(str: move x, code: x0(x))
else:
return Example(str: "...")
echo x1(true)
Is there a copy operator I can use to suppress this hint? Both the move() and
copy operators can be useful in certain situations.
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
Yap, compiling with -d:release only adds range checker helper function
static N_INLINE(NI, chckRange)(NI i, NI a, NI b)
Run
This is a design decision, should the codegen generate range checker with
-d:danger, not my call :P
Well it said `-d:danger` (in case you don't know, it disables all runtime
checks). Also you won't be able to find types like these in C, because they
just don't exist. Nim instead implements these via checked conversions IIRC.
$ cat example.nim
type iX = range[1..5]
var a: iX = 3
var b = 10
a = b
$ nim c -r -d:release -d:danger --rangeChecks:on example.nim
Hint: 8022 LOC; 0.029 sec; 11.656MiB peakmem; Dangerous Release build;
proj: Hint: /home/juan/code/temp1/example [Exec]
type iX = range[1..5]
var a: iX = 3
var b = 10
a = b
Run
When you compile this with -d:release -d:danger it doesn't throw any error. In
the generated C file, type iX doesn't exist at all
I think the "kernel" is more or less a proof of concept / experiment. If you
find it Interesting: play with it! I can imagine dom96 is open for pr's.
It is _not_ a macro.
:)
In the ideal world,this should compile
var b = 10
var a: iX = 5
if b >= 1 and b<=5:
a = b
Run
and if you remove that `if` it doesn't. Of course it is hard(it's called
subtraction type or something)
Otherwise it is still implicit downcast and it's
You can try running this code with different mode:
import winim/lean, strutils
var bufLen = GetLogicalDriveStrings(0, nil)
var buffer = T(bufLen)
GetLogicalDriveStrings(bufLen, buffer)
echo buffer
echo buffer.repr
echo ($buffer).repr
echo
Thanks
I know it's trivial, but it's still nice to have, and I'm against overuse marco.
Now support the `else` branch too.
> It's known at compile time as int32
int, not int32
> It's known at compile time as int32, not iX, while nim compiler totally
> ignores this and assume they are compatible. But they aren't. [...] the more
> sane option is not provide a subrange type in the first place.
again, not-a-bug.
Think it is called dqeues now
[https://nim-lang.org/docs/deques.html](https://nim-lang.org/docs/deques.html)
import queues var q = initQueue[int]() q.add(8) q.add(18) Error: cannot open
file: queues
What problems are you having? Can you post code that demonstrates your
problems?
That is literally an example on the documentation:
[https://github.com/nim-lang/Nim/wiki/Nim-for-Python-Programmers#Templates](https://github.com/nim-lang/Nim/wiki/Nim-for-Python-Programmers#Templates)
Is it deprecated?
> b is know at RT, not CT.
It's known at compile time as int32, not `iX`, while nim compiler totally
ignores this and assume they are compatible. But they aren't. Of course it's
hard to use CFA or whatever technique to make compile time check possible, but
the more sane option is not provide a
@trtt & @miran, Thanks very much. Yes, i notice I made the mistake of the
return type in the proc.
There are few problems with your Nim version, e.g. returning `string` instead
of `seq[string]` (cause this is what the Python version does - it returns a
list).
Here is a correct Nim version:
proc cross(xs, ys: string): seq[string] =
## Cross product of elements in A and
That's not list comprehension in nim, you just iterated over two strings and
then joined the elements without using them.
proc cross(a, b: string): seq[string] =
for ac in a:
for bc in b:
result.add(ac & bc)
let digits = "123456789"
let letters =
Hi, I'm new to Nim-lang.
I wanted to convert a Python script to Nim to improve my understanding of Nim.
I have the following Python code:
# Python codes:
def cross(A, B):
"""Cross product of elements in A and elements in B."""
return [a+b for a in A for b in B]
> and it translates in a badge saying build failing or passing on
> [https://github.com/nim-lang/Nim](https://github.com/nim-lang/Nim)
Nothing has been pushed after I disabled Travis. So don't jump to conclusions
just yet.
[https://travis-ci.org/nim-lang/Nim](https://travis-ci.org/nim-lang/Nim) still
shows at least travis is still in use; and it translates in a badge saying
build failing or passing on
[https://github.com/nim-lang/Nim](https://github.com/nim-lang/Nim)
createShared doesn't really work well with datatypes like Table.
41 matches
Mail list logo