with the conversion of first element in the `seq` `B(val:1).A` you tell the
compiler, that you create a `seq[A]`. For the remaining elements you don't need
the conversion:
var a:seq[A] = @[B(val:1).A, B(val:2)]
Run
and you can even omit the type declaration for `a`:
I recently had a problem with `sink` parameter inference in exported procs. I
haven't looked how it is now, but I think that exported procs should never have
inferred `sink` parameters, because nim can't be sure in that case.
hmm the logo somehow reminds of the Haxe logo
I like - in the order of appearance in my life:
* pascal for showing me that Apple Basic was crap
* forth for showing me how powerful it can be to do things in the reverse
order
* delphi for simplifying GUI development in 1995
* haxe for giving me the ability to program JavaScript or php
a binary search makes only sense on a sorted array.
if a hash is useful depends on the problem. Hashes are good when you have a
_big_ dictionary which does not change (much). If you have only some elements
in the dictionary, then the costs for calculating the hash values might be
higher than the costs for some compares. And don't forget the costs
> Has anyone thought of using Nim with Lazarus LCL or Delphi's VCL?
there are several problems here:
* memory management
* compatibility of standard types like string and dynamic array (=seq)
* calling convention
The first two are feasible with the new `destructors`. I am writing a libra
SUCCESS!
now I am completely confused. When there is a `ashr` (which I have never
noticed), why is there the need to change the behavior of `shr` for signed
`int`? I can't see the point.
I agree that `shr` on signed `int` is error prone, but that is how the things
are now. To have a save transition I would suggest to have 2 operators `shr`
and another one `ashr` or `sar` or whatever with signed shift behavior. We
should then deprecate `shr` for signed `int` and in the future mak
I don't know if I am overreacting, but just realized that
Run
has changed its meaning from unsigned shit to sign preserving shift. IMHO this
breaks a lot of code in a very dangerous way. A more thoughtful solution would
have been to introduce a sign preserving operator
for property access you can use a distinct type and for assignment an operator
like :=
type
Obj = ref object
fStep: int
ObjStepProperty = distinct Obj
template step(self: Obj): ObjStepProperty = self.ObjStepProperty
proc `:=` (self: ObjStepProper
type specific allocators sound a bit weird for me, but since they are a debug
only feature I am ok with it. The distinction between owned and not owned refs
is a step forward and worth the work for the change I guess. Deterministic
memory and resource management is the way to go. The destructors
@dataman thanks that was a really helpful link.
@araq I tested my simple hash algorithm against brute forth and BM with that
smart tool. It always wins against brute forth. Against BM it wins always for
pattern lengths under 16. Given that the BM has always an overhead for the
first search I wo
playing around with text search (strutils.find) I realized, that the nim find
implementation uses a Boyer-Moore algorithm. This is nice in many cases, but
there are scenarios where a naive brute force search is faster (small search
patterns and/or a simple one shot search like find("nim is a gre
I am OK with the current state - I don't want a vote. If Andreas wants to
change it I am OK with it too.
But real DOS fun is compiling to 16bit and handling of XMS :) I don't know if
Nim supports 16bit word sizes.
use `..<` without space between `..` and `<`
now I downgraded my gcc from 8.1 to 7.3 and it works.
strange it works when I boot with:
koch boot -d:release --cc:vcc --cpu:i386
but with
koch boot -d:release --cc:vcc --cpu:amd64
I get now another error: msgs.nim(85, 39) Error: ambiguous call; both
tables.[](t: var Table[[].A, [].B], key: A)[declared in
..libpurecollectionstables.nim(187, 5)]
Is it only me ? With actual nim from git, koch boot fails on third iteration
with: cannot open file: ../doc/basicopt.txt but only on windows.
With nim on linux it works. Any ideas ?
@cblake thanks for the explanation. I will check with the profiler. From what
you said I tried this and get almost the same results - now for gcc and g++ and
for clang a speed up of about 4x.
proc fib(n: int): uint64 =
if n > 1 and n != 30: return fib(n - 1) + fib(n - 2)
Hi, on twitter I saw that Nim performed better on fibonacci benchmark than C
and C++ ([https://github.com/drujensen/fib](https://github.com/drujensen/fib))
and wondered why. I did my own tests and these are quite interesting:Language|
Time in s| compiled with
---|---|---
Nim| 0.456| nim cpp
Hi, I try to subclass a C++ class in nim and implement some features in nim.
Here is what I do:
{.emit:"""
class Foo {
public:
int data;
Foo() {}
};
class Bar: public Foo {
public:
int d2;
Bar() : Foo() {}
~Bar();
}
Sorry I was a bit quick with that question - it is not really necessary. I can
live with just going over the source directories and add all .nim files to the
project.
Hi,
I want to integrate nim in C++ Builder. Currently it already works quite nice
and I can compile a hybrid project (nim, c++, delphi) from inside C++ Builder.
But when I want to debug the the nim code (by using --lineDir:on and
--debugInfo) it would be nice to have all the .nim files which ar
for embedding ssl - have you tried mbedtls
[https://tls.mbed.org/](https://tls.mbed.org/). Never used it, but maybe it is
what you are looking for.
thank you for your effort
from my point of view things that should go out:
* `do` every time I read code which uses do I have to think hard what's going
on.
* `using` never used it and looks a bit strange to me
* `method` is not really usable in it current shape. But we need some OOP.
things that should stay or i
I did some deeper research. wrapping the nimbase.h would be wrong it is enough
to wrap the TFrame stuff conditionally into a namespace Nim. In the generated
code the wrapping should start after the #undef unix or before the first
declaration until the end.
Would you accept a pull request when I
I am trying to use Embarcadero C++ Builder with Nim. The problem is that by
default C++ Builder pulls in all namespaces. So you have name clashes for
example with TFrame or Exception. There is a way to avoid this by defining
DELPHIHEADER_NO_IMPLICIT_NAMESPACE_USE which should prevents this. But
Hi,
what do you think about an optional parameter to compile nim code into its own
namespace "Nim" (or configurable). When compiling nim code together with a big
c++ library it is very likely to get name clashes with the existing code - for
example names like TFrame or Exception are used very o
What does yield inside a template do ? The documentations says yield is only
valid inside an iterator.
nice
I agree that would be fine. The two are very similar. To avoid the polling,
threadpool should be able to transfer the result of its work to the async
dispatch list of the calling thread when its done.
expanding my example you could do:
import os, asyncdispatch, threadpool
you can also busy poll the result of the spawned proc in an async proc like
that:
import os, asyncdispatch, threadpool
proc doWork(): bool =
# staff use sql
echo "starting..."
sleep(5000)
# complete the future var
echo "... ok"
why should it be called ? x is global and gets never out of scope.
not a real problem - but for JavaScript there is no inlining of procs. And for
converters I would prefer to have the choice if they are inlined by nim or not,
but the more I think about it, the benefit would be just cosmetic.
Hi,
just wanted to know if there is a reason (other than we more important things
to do than that), why procs and converters are not inlined by nim when marked
as such. I know you can always use a template - but not for converters
(normally they are just a cast to make the typing the way you wa
@rayman22201 what I have seen is, that each proc that has a var of a type which
is handled by a destructor needs a hidden try finally block (currently even if
the var is not used). This can be a big overhead for small routines. The c
target needs setjump/longjump which is a big overhead. The cpp
object variants are not exactly the same, because you always need the extra tag
- byte b here. In pascal you don't need a stored tag (like in the question). I
guess the union should result in the same memory layout.
very nice library ! @Ward: How did you translate the interfaces ? manually,
with c2nim or another tool. It would be nice to have a tool to import type
libraries.
Its not about refuting your educated guess - because you know and we are only
guessing. On the contrary its only for the understanding for the simpler minds
like me With increasing the ref count for the strings in the array I partly
disabled the GC for these strings but not for the other GCed d
I just made a small test and increased the ref count of each string in the
array at the beginning and decreased it at the end. The result is, that the
time of array variant decreased from 15sec to 2 sec on my PC.
import random
import hashes
import times
import math
i
you are right, my conclusion was to simplistic. It doesn't matter if an array
on the stack holds non ref data.
> I do not understand currently why the seq is no problem for the GC
I don't know either, but I guess its because the GC has to check all the roots
on the stack. For the seq it has onl
Good to know. Than any consideration to have data allocated on the stack to
avoid allocations, turns out as a performance killer as long as the GC plays
its game in the background.
> Ahhh damn, I thought you'd go for the first option and add the feature soon
me too - normally documentation takes longer than implementation...
congrats! How can I activate the VTable types described in the manual
[https://nim-lang.org/docs/manual.html#generics-vtable-types](https://nim-lang.org/docs/manual.html#generics-vtable-types)
? I tried thy example from the manual but the compiler complains about
undeclared identifier vtref.
should have done it a lot earlier
For anybody who is interested in converting object pascal to nim, I have
created a fork of pas2nim
[https://github.com/AdrianV/pas2nim](https://github.com/AdrianV/pas2nim) which
parses and converts a big amount of object pascal code:
* class is converted to ref object
* class, object and
@Araq cool
nice post - now the perl guys can use nim too
52 matches
Mail list logo