You may read again the manual section ncrosby cited, or read tutorial:
[https://nim-lang.org/docs/tut2.html#object-oriented-programming-type-conversions](https://nim-lang.org/docs/tut2.html#object-oriented-programming-type-conversions)
In Nim we generally avoid casts, but we may do type
Recently someone complained about gintro not working well with latest Nim
devel. Well not too surprising due to a few breaking changes.
[https://github.com/StefanSalewski/gintro/issues/28](https://github.com/StefanSalewski/gintro/issues/28)
I have just tried to try it with latest devel -- do
I think what you wants to do is plain text processing. For that you do not need
Nim macros, you may use module strutils and related modules, maybe also pattern
matching. Basically you parse the input nim file, and then write the pascal
interface file with that data.
> Got it. I will bookmark it in my mail folder, so i can send you the book
> later.
Why that effort? See google or Manning page:
[https://account.manning.com/support](https://account.manning.com/support)
Section shipping:
I need to change my shipping address on a pending order.
Please send a
Yes, the reordering can be much manual work.
For the gintro module, I do it automatically now, but it takes a few minutes to
finish -- and it is based on gobject-introspection.
The ugly way is to put all types into a single type section at the front of the
module. Many modules from early days
You can store variables of type Node all in one single seq.
For node2: I really think that there is no way to store variables of type
Node2[nkInt] and Node2[nkFloat] in the same seq.
So Node 1 is more dynamic. But I am not really sure, have never used object
variants...
> I say this as someone who spent decades writing C code
So you did exactly what I suggest
Of course it is difficult to make suggestions to puwad as we don't know him.
But starting with Nim TODAY for a real beginner is really hard. And Nim in
Action is not a book teaching Nim for beginners.
@cdunn2001 > partial-casing causes problems.
Can you provide examples?
For the gtk related libs, I had initially indeed problems two years ago when
Nimrod was fully style insensitive. But now with partial casing there are no
problems, types like Buffer start with capital letter, and procs or
I wonder if sequtils.deduplicate() should be renamed to deduplicated() as it
returns a seq like sorted()? And maybe it should be noted that it is O(n^2),
which is fine for small collections, but not so nice for large ones.
And maybe we should add a O(n) deduplicate to stdlib -- sets modul is
I just got version 9 of the meap.
I was curious about the actual improvement work of the manning people. My early
expectation was that they would not do much, indeed I think they can not do
much, just because they do not understand the matter. So only a few grammar
fixes remain to them, and I
That is very interesting, thanks.
(As you know, I am using your module combinatorics.nim in
[https://github.com/StefanSalewski/nim-gi2](https://github.com/StefanSalewski/nim-gi2).
Would be nice if that module would be put into Nim's standard lib -- it works
fine, but I have never tried to
> I got a Data Structures book
Which book do you have? Do you like it?
> I know how to do it with Java
Can you show us your code? I would like to learn how to do it in Java.
Basically, what you need to build something like Nim's seq is allocating chunks
of memory from the OS. You may inspect
[https://forum.nim-lang.org/t/2924#18358](https://forum.nim-lang.org/t/2924#18358)
[https://github.com/StefanSalewski/nim-chess3](https://github.com/StefanSalewski/nim-chess3)
[https://github.com/fragworks/frag](https://github.com/fragworks/frag)
I think there are already more, some commercial
Should work for Windows 10 also now.
As Araq recommended, I removed the single quotes in the wget and nimgrab
command strings.
You just have to ensure that all needed GTK3 libs are installed on your Windows
box before gintro install.
You may follow user zetashift's advise, but don't forget to
Thanks for the link, sounds interesting, will read soon...
For your test code, I am not really sure what the purpose is. Nim's realtime GC
is tunable, so you can get very short pause time with a tradeoff in throughput.
See
> I managed to reduce the crash to this
Great. Maybe test if it only occurs for Natural or also for int, and create an
issue for github issue tracker. Should be a task for Zachary.
proc main =
var s = 0
for i in 0 .. 10:
if i * i == 49:
#if i == 7:
s += 1
echo s
main()
For this test, using "if i == 7" instead of "if i * i == 49" gives half runtime
on my box. This is a bit surprising as multiply is
Have you tried something like
when AVX2_Available():
Of course that can only work when your AVX2_Available() is known at compile
time...
Calling getType() multiple times may give you the parents, I did that here:
[https://github.com/StefanSalewski/gintro/blob/master/gintro/gimpl.nim#L12](https://github.com/StefanSalewski/gintro/blob/master/gintro/gimpl.nim#L12)
I got it from a hint of Araq, I have no idea what really is
> Why not calling Nimsuggest on space hits and carriage returns only ?
Yes this is one solution, but I was not really happy with it. In the general
case one single keystroke can change highlight of the whole file. For example
when we modify a var or type definition all occurrences of that var
Yes, nimsuggest works really not bad now. For example I can investigate
tables.nim fine, jumping to impl works also. One problem are still the generic
procs, that symbols seems to be inactive, I guess there is already an hard
issue in bug tracker.
Now I consider supporting the outline and
> I'm confused in all that pointer-reference-object_itself stuff
I have already downloaded the source code of librsvg-2.40.16. Seems to be
really a tiny lib, and the c headers contains not many strange macros, so
building the wrapper should be easy. (There are bitfields used, but fortunately
OK, I think I see your problem.
In Nim an empty subscript [] notation can be used to derefer a reference or
ptr. So if p is a pointer to string, in C++ you would write '*'p to dereference
it, but in Nim you write p[]. And in Nim you can write p[n] to access the n'th
character in that string. I
import strutils
type
App = ref object of RootObj
i: int
proc isDigit(app: App) =
discard
macro xconnect(widget: RootRef; signal: string; p: typed; arg: typed;
ignoreArg: bool): untyped =
discard
proc main =
let app: App =
> Can you show me how to do that?
When you are using the Nim compiler from the command line, then in the current
working directory a subdirectory with name nimcache is created. For example
"nim c test.nim" creates "nimcache/test.c". You can inspect that intermediate C
code. When you have clang
jzakiya, you may wonder why your program eats that much memory.
I had just looked at you code, and tried this:
#for byt in seg[0..Kn-1]: # count the twin primes in the segment
# primecnt += uint(pbits[byt]) # count the '0' bit pairs as twin
primes
for jj
> So soemthing like Python's setattr() doesn't exist then?
I think when you want support for dynamic runtime attributes, you have to
prepare for it in a compiled language. For example you can add a field of type
seq or table to your object and a proc for adding data to this field. Of course
in
Yes sure, Nim's strings are garbage collected, so GC_ref is available. But the
user can pass really arbitrary data, maybe plain ints. Maybe I should just use
"when compiles(GC_ref(data))". Maybe not the smartest solution, but should
work. Then I only still have to learn how I copy data, I guess
Hashing floats is not that trivial. A common problem are rounding errors. Do
you want/need identical hash for i.e. (3.0 + 4.0) and (7.0)? If yes, then it
may be necessary to mask the less significant bits before applying the hash
function. So, before choosing a concrete optimal hash function,
I heard about Rust OS some months ago (Is there one more than Redox). I think
that is very interesting, indeed that would be my main motivation to learn Rust
language deeply.
But it is very hard for new operating systems to become popular. For Linux it
was a bit different, because it was only
And can you please try to avoid the ugly cast:
#var u:array[4,int64] = cast[array[4,int64]]([60,1,342,0])
var u: array[4, int64] = [60.int64, 1, 342, 0] # should work -- if not tell
Araq
Thanks.
Should I add that example to Nim's github issue tracker?
If speed is really important for you, you may consider SIMD instructions.
D. Lemire gave an example for this in his nice blog:
[https://lemire.me/blog/2017/02/14/how-fast-can-you-count-lines](https://lemire.me/blog/2017/02/14/how-fast-can-you-count-lines)/
:
import macros
type
S = string
I = int
O = object
i: int
P = ref O
var i: I
var s: S
var p: P
var o: O
macro mconnect(arg: typed): typed =
let at = getType(arg)
echo $(at.toStrLit)
if at.len > 1:
Indeed Jack, I think sync() is nonsense when parallel statement is used.
> IMO your rewording of the explanation of forward declaration also leaves
> something to be desired.
Yes, it is difficult to explain, for me, in english. I just tried, as only
complaining is sometime too easy.
For the forward declaration, I think there is already a secret pragma to make
it
@OderWat
Sorry, can not really understand... Somethink like memCopy or memMove? That was
my first idea, but I was very unsure what would happen when array elements are
not somethink like plain ints, but objects with refs. Would that confuse the GC?
And of course one may ask if array shifting
It is generally a bad idea to send the whole seq to C function because there
may reside additional data like seq length at start of memory chunk. Try to use
address of first element of the sequence instead.
stefan@nuc ~/gintro $ ls -lt
total 40
drwxr-xr-x 1 stefan stefan 210 Jul 7 00:31 gintro
-rw-r--r-- 1 stefan stefan 2288 Jul 7 00:30 gintro.nimble
drwxr-xr-x 1 stefan stefan48 Jul 6 17:32 tests
drwxr-xr-x 1 stefan stefan94 Jul 6 15:27 examples
-rw-r--r--
Kerp, you are working on the Vulkan bindings? Great!
For C flags you should strongly consider using Nim's sets! I did that for the
high level GTK bindings recently. Have code like
type
RegionFlag* {.size: sizeof(cint), pure.} = enum
even = 1
odd = 2
> The big problem I've had with tabs was in team programming,
But there is no problem, as long as tabs and spaces are not mixed for
indentation purpose in a single file. And no one wants to allow mixing.
There is one big advantage of tabs: Indent width can be freely configured,
without the
import random, algorithm
# a < b ==> cmp(a, b) < 0
proc cmp(a, b: int): int =
(a > b).int - (a < b).int
proc quicksort(a: var openarray[int]; left, right: int; cp: proc (a, b:
int): int) =
proc qsort(left, right: int) =
var l, r, p: int
let
I think I have still not really learned that. I think I may write something like
type
ExtSeq = object
s: seq[int]
timestamp: string
var
es: ExtSeq
# init
es.s.add(7)
echo es.s[0]
echo es.timestamp
But I would
> If you really need to know the number of processors on a system, you could
> always compile a sub-program during compile-time and invoke it.
Indeed I assumed that. But I have no idea how to do it in detail in a user
friendly way -- so that user can still do a plain "nimble install myTool".
I would have expected that the compiler sees that the proc parameter does not
match and so ignores that proc and assumes that a type conversion is intended.
> @Stefan_Salewski, seems that RsvgHandle has not svg data it's nil instead
Of course making such a gtk related wrapper is not fully trivial.
I think I once said that RSVG is not a very big library, so it should not be
too much work to make the wrapper. Unfortunately I have never used R
Of course for plain compilers var parameters can be faster, because without
smart optimizations result objects can be first allocated on the proc stack and
then copied back to the caller variable. But I had the strong feeling that this
optimization is generally done, so I never tried to
Nice -- I already saw it some days ago. Will read it carefully soon...
Indeed -- putting all that test code in a proc make differences disappear!
I am aware of performance problems of code outside of procs, but I really had
not thought that that was the problem in this case. And I had not assumed that
it makes 30 ns difference for a proc call.
I think in future I
Well, this is the cleaned up version. We do check for dev packages on ubuntu,
check if tmp dir already exists and delete tmp dir when done. Problem with mode
= Whatif was that Whatif is a pure enum, issue is posted. The modules still
import each other directly, without the gintro prefix. Seems
Reading this blog post
[http://nibblestew.blogspot.de/2017/11/aiming-for-c-sorting-speed-with-plain-c.html](http://nibblestew.blogspot.de/2017/11/aiming-for-c-sorting-speed-with-plain-c.html)
> I just remembered a discussion some time ago:
S. Salewski wrote:
> A consequence may be, that for
Hlaaftana, thanks for confirming. I was really tired yesterday and though I was
doing something wrong.
cdome, your message makes not too much sense for me currently.
Indeed I tried using unlikely() for this test, which made no difference, as
expected, as automatic branch prediction should work
What do you think where the problem is? Are you following a C example or the
Krause book?
As you know I am using only GTK3 -- but from my memory of examples and the
Krause book I think that the second parameter of gtk_image_new_from_stock is
generally a C enum of type GtkIconSize. So allowed
Have you tried something like
var mycounter {.register.} = 0
You can check the C sources if it is applied, but as the manual says, in nearly
all cases the (C) compiler knows better.
Version 3 is now available!
[https://github.com/StefanSalewski/nim-chess3](https://github.com/StefanSalewski/nim-chess3)
Ram usage is reduced to about 340 MB, and I tried some other improvements.
Not much tested yet.
Nimble install is still not possible, but for Linux a copy and past of the
Why not use echo to see the content of the string you pass to parseInt?
Note: for bash command expr / indicates integer division. For Nim / is floating
point division, you may use div for integer division, or you may round the
floating point result. So may guess is that you pass a floating
No not as a library. But I have not investigated the remaining crashes.
I worked on it two months ago for the last time and used the editor then while
working on the chess game. For me some crashes are no problem, I saved every
ten minutes. And I think there are no other users beside me.
One
> but allocCstringArray wants a openarray of string.
So you should give it one. You should know how you can create an array or a seq
of strings. When you know that 256 chars are desired for each string, then you
fill the array with strings with at least this size. And finally you pass that
[http://stackoverflow.com/questions/14579920/fast-sign-of-integer-in-c](http://forum.nim-lang.org///stackoverflow.com/questions/14579920/fast-sign-of-integer-in-c)
I would like to have a sign function in std lib.
I was really surprised that the brachless variant makes such a difference -- I
had
The plain Nim GTK3 editor is now available in version 0.2
[https://github.com/ngtk3/NEd](https://github.com/ngtk3/NEd)
I have added multiview support, fixed the GTK related modules and added a short
Asciidoc Readme. Not really tested yet. You should be able to compile it at
least on 64 bit
Araq, the deepCopy() part works fine with string and int parameters, but
unfortunately not with objects. I got it working, when I substitute at by
"ParObj" literal everywhere: (Of course that makes no sense for general use
case)
type
ParObj = object
x: float
@lscrd
Nim 0.18 is correct indeed -- see language manual:
Pre-defined integer types
These integer types are pre-defined:
int
the generic signed integer type; its size is platform dependent and has the
same size as a pointer. This type should be used in
template bar() =
echo a
template foo() {.dirty.} =
let a = 5
bar()
foo()
echo a
I would expect exactly that behaviour. As templates a hygienic by default, we
need dirty pragma for foo() to make variable visible outside.
> Without main function: 5.004 s With main function: 3.126 s
That is really some magic which we should investigate, document and remember.
> Yes, a couple of fixes and it worked. If you want I'll write more detailed.
Yes, would be fine.
Araq just told me that he regards proc names like int32 invalid -- they shadow
type conversions. So I have to filter all the GTK3 related modules for proc
names which may conflict with type names.
The paper version was announced as "printed in black & white".
[https://manning.com/books/nim-in-action?a_aid=niminaction_bid=78a27e81](https://manning.com/books/nim-in-action?a_aid=niminaction_bid=78a27e81)
But the ebub and PDF version has color and looks nice. There is no reason to
buy paper
Of course not, there is much allocation work involved. But about 500 ns (a few
thousand CPU cycles) is indeed more as my expectations. I discovered that when
tuning my chess engine -- using one more tiny seq noticeable reduced
performance. Of course seq's are convenient, because of existing
> running Nim code on a medium size MSP430 32K Flash, 4K RAM. The
> MSP430F5510-STK board from Olimex.
Interesting. Can you access all the registers already? Do you use GC? Your
project based on
[https://github.com/lonetech/nim-msp430](https://github.com/lonetech/nim-msp430)
?
Circular
> Coming from Ruby/Elixir,
Maybe some C exercises would help
Note that modpg.unit and rescnt.uint are not plain casts (reinterpretation of
bit pattern) but type conversions. Type conversions may ensure that the values
are not negative before conversion and raise exceptions otherwise. I don't
Well, more meaningful and even more funny is this code with random numbers,
where the compilers really can not remove the proc calls:
import random
proc rdtsc(): int64 =
var hi, lo: uint32
asm """
rdtsc
:"=a"(`lo`), "=d"(`hi`)
"""
result =
@Varriount
Is your conclusion really fair?
The Go benchmark seems to include no special tweaking. Araqs version switched
of cycle detection. That may be fine for this small example. But when I have a
real word complex program, can I be sure that I can switch of cycle detection?
For all my
That is an interesting topic. When you try
var x: int = 10 * 1_000_000_000
it seems to compile fine on a 64 bit Linux box. So problem is the constant
itself.
But what I really ask myself: How does
var x = 10 * 1_000_000_000
behave on 32 and 64 bit OS. Is x
I tried to create a generic RTree. Beginning was easy, tests of union() and
intersect() was working fine. But I did not got search() working -- it gets a
rtree parameter and a box, which both are generic. I tried with proc p() which
compiles when one of the parameters is used, but not when both
Do you want to search for regular expressions or for plain strings?
Plain strings should be faster of course.
Now in your code there is no spawn at all!
For parallel processing, you have to ensure that there are no conflicts when
parallel tasks are accessing your data, otherwise the compiler may make copies
of the data before, which may make it slow. And for parallel processing a good
use of the CPU
> still be Greek for me.
Well, the when statement is really easy to understand and well explained in the
manual, so maybe you should read it again. It is good to understand it.
What you may be looking for is a converter, see manual. A converter allows
automatic conversion of proc parameter
Well, I have a working solution. I can pass a string, an int, and object from
the stack to the callback and it works. (Removing a button and reinserting does
not work currently, but that is a different problem.) But I still wonder why I
have to use the strange name(type(arg)) way to get the
> would like to have a new "alias" functionality
Was thinking about it a few times...
For example, I have a longer proc with return type View. Can use predefined
result variable in the proc, but then I have to remember that result is view.
Or I use "var view: View ... return view". alias view
Currently I favour to let the shape of the code as it is.
One question arise: Would it make sense to rewrite code like this
[https://github.com/StefanSalewski/RTree/blob/master/rtree.nim#L305](https://github.com/StefanSalewski/RTree/blob/master/rtree.nim#L305)
for j in 1 ..<
We had a very similar thread recently:
[https://forum.nim-lang.org/t/3054](https://forum.nim-lang.org/t/3054)
> Which directory are your GNOME development libraries themselves installed,
I am not using Windows. For gentoo linux, command is just "emerge -av gnome". I
can search for directory paths, but I guess that will not really help you for
Windows.
Personally I would be very interested how well
> I tested it, but I did not have any syntax highlighting.
I assume on Linux. Do you have syntax highlighting at all, for example in
gedit? Do you have syntax highlighting for other files, maybe xml?
You may try with another file extension, like
./ned nimdark1.xml
but I just
One more explanation for a factor of 3 - 4 in performance can be of course SIMD
instructions. Maybe latest Julia is very good in using SIMD? Maybe you can try
clang instead of gcc to see if clang can better apply SIMD and related parallel
instructions to your code. (Or Julia may pre-compute
You may try first
[https://github.com/ngtk3/nim-chess2](https://github.com/ngtk3/nim-chess2)
The readme contains the instructions, which I tested recently with Nim v 0.15.2
on Linux.
For Linux you can copy the commands to a file and run the script, bash
script.sh.
I know that it does not
And of course nimx and QML.
And note that latest GTK 3.20 wrapper is at
[https://github.com/ngtk3](https://github.com/ngtk3), I will delete the old
3.15 wrapper in the next days...
> I'm trying to create a Ruby extension in Nim,
Interesting, maybe you can collect your insights in a blog or forum post.
I have used Ruby too in the past, and I wrote some C extensions for using CGAL
and Boost library. While I was told that extending Ruby with C was easier than
extending
nim check mycode.nim
But it is true, if errors are in code with generics, templates or macros it can
occur that there is absolutely no useful hint to the real error location. For
example as error position code in system.nim is showed. And some hours ago I
had a case with generics
OK, that is what I guessed more or less...
I think I will try to put all the relevant code into another proc and then call
GC_fullCollect() when that proc is finished, then all stack of that proc should
be released and finalizer should be called for that objects. Will continue
testing GTK3 GC
> Do i have to learn a new GUI language for that programming ?
When you have experience in GTK3 programming in C already, you can just start
with GTK3 and Nim, it is very similar. You can even convert C GTK3 code to Nim
with the tool c2nim, do some modifications, and are done.
But to be
>From the manual:
[https://nim-lang.org/docs/manual.html](https://nim-lang.org/docs/manual.html)
The implicit initialization can be avoided for optimization reasons with the
noinit pragma:
var
a {.noInit.}: array [0..1023, char]
Well, writing books in a foreign language is not easy...
You may have noted that this remark from chapter 2 is still not very nice
Order of procedures
It is important to note that the order of procedures and procedure calls
matters.
When calling a procedure, it must be
There is a fine tutorial by Dennis:
[https://hookrace.net/blog/writing-a-2d-platform-game-in-nim-with-sdl2](https://hookrace.net/blog/writing-a-2d-platform-game-in-nim-with-sdl2)/
var
i: uint32
s: seq[byte]
p: int
s = newSeq[byte]()
s.add(0)
s.add(1)
s.add(0)
s.add(0)
i = (cast[ptr uint32](addr s[p]))[]
echo i
output is 256, maybe not that wrong. But I am still confused, maybe Dom can add
a few more pages
Yes, I have seen that in the Nim manual.
Unfortunately such a concept construction is a bit difficult because all the
code is automatically generated by use of gobject-introspection. Maybe I will
make one manual test case to see if it would work. For now I have broken down
the procs into
In the last days I was going to spent some time debugging the random NEd Nim
editor crashes. Unfortunately, while I got some crashes some weeks ago when
working on the chess game, I was not able to generate crashes when testing. So
I think I have to wait until a real crash occurs again, and
Sorry Araq, IRC just banned my IP again, so I can not answer there...
No, I don't used -d:release explicitely. But nimble install should have done
that I guess?
Will try now with -d:release without nimble.
> that it is really the const seq which is causing most of the slowdown
That is very interesting! I strongly assume that const seg is identical to
const array?
Have you tested? So this may indicate that we should avoid const arrays when
speed is important.
type
E = enum
a = 0
b = 1
c = 2
d = 8
EventFlag* {.size: sizeof(cint), pure.} = enum
exposure = 1
pointerMotion = 2
pointerMotionHint = 3
buttonMotion = 4
button1Motion = 5
button2Motion = 6
r3, regarding microcontrollers without operating system you may follow this
thread carefully:
[https://forum.nim-lang.org/t/3803](https://forum.nim-lang.org/t/3803)
As you may know, when we program tiny controllers like 8 bit AVR in C or C++ we
generally avoid library stuff like printf,
1 - 100 of 880 matches
Mail list logo