Re: Off-subject GTK check-resized signal
Maybe this can help you, should be still for old GTK2: [https://stackoverflow.com/questions/1060039/gtk-detecting-window-resize-from-the-user](https://stackoverflow.com/questions/1060039/gtk-detecting-window-resize-from-the-user) I dont know for GTK2 -- if non of the suggested signals work properly, one solution is to save old window size in your application and do redraw only if new size is really different. I think I did something like that in GTK3, but can not remember if it was related to size or something different.
Re: How to access base class member from derived class ?
Sure, i will read it. >I think your own code on the top is a bit "strange and dangerous" I will check what i can do in that case. Thanks for pointing me the right direction.
Re: Off-subject GTK check-resized signal
My Gtk3 implementation uses the `configure-event` signal; in the handler it calls `gtk_window_get_position()` to get the new window size. [Source](https://github.com/trustable-code/NiGui/blob/master/src/nigui/private/gtk3/platform_impl.nim#L53)
Re: How to check an auto type parameter in a proce
I did not meant that you attacked me. May be you are right. I am asking questions in the wrong way. I think i was little Impatient at that time. I should need to try the trial and error method instead of asking in the forum. > It's not the first time on this forum that somebody has posted a link to help > you after you asked a question, and you instantly dismiss it. Not cool, man. Well, that was not my intention. May be i dont know how to react when i think those links are not really going to help me. I cant express my intention more clearly because, there is language barrier exists since English is not my first language. Sorry if i hurt you with my words. I am not intended to do that.
Re: How to check an auto type parameter in a proce
Thanks. May it was my problem because, i was little frustrated when i cant find what i was looking for. I know, i have asked too many queries in different threads. But actually, the suggestions from others were not satisfied me, but it was my fault, not their fault. I think its better for me to silently watch the forum. So whenever somebody asks a question related to my questions, i can find some answers then. May be i need to learn how to ask questions in right way. So before learning nim, i should learn how to ask questions.
Re: How to check an auto type parameter in a proce
> 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 article might be beneficial to you and it was posted to help you. It's not the first time on this forum that somebody has posted a link to help you after you asked a question, and you instantly dismiss it. Not cool, man. * * * The reason why I posted that link is because it seems to me that you're asking the wrong questions (as @mratsim correctly recognized). It's not that questions are forbidden, but — if you asked a bit more general question with a detailed "I want to do this and that" maybe we could give you a better answer which more elegantly/idiomatically solves the problem you have. Currently it feels that we're solving problems which are the results of some wrong decisions several steps before.
Off-subject GTK check-resized signal
This is a GTK2 question rather than a nim question. I hope some NIXER will disregard that and lend a hand. I have returned to a cross-platform GUI nim project after 6 months in the Javascript Wilderness. I discovered the GTK2 version of my module was exercising the check-resize callback many more times than necessary. I have been unsuccessful in finding the documentation for the check-resize signal - such as when it is emitted and what is done to its window just prior to that. Eliding lots of detail, the signal is captured with: discard handle.signalConnect("check-resize",SIGNAL_FUNC(resizeReq),nil) where handle is the top level window reference. The call back (placed up-source) is like this: proc resizeReq(widget: gtk2.PWindow, data: Pgpointer) {.cdecl.} = #steps not shown var wid,hgt:gint widget.get_size(wid.addr.Pgint,hgt.addr.Pgint) #steps using wid and hgt to revise children in widget. Run When the user expands the window, how is the new size communicated to the window? Does the expansion do a set_size prior to sending the signal? Are these issues discussed anywhere?
Re: Nim source equivalent to C #define
Many thanks for all the suggestions. Since NEEDEDFLAG can also be set by: nim c -d:NEEDEDFLAG etc.etc. Run I need to use defined(NEEDEDFLAG) instead of declared(NEEDEDFLAG). However the following inside nim.cfg worked for me: @if BGMAP: define:BGDUMP @end Run which is the actual example in use. Where (URL) are the @ commands for nim.cfg documented?? I could not find them in [https://nim-lang.org/docs/nimc.html](https://nim-lang.org/docs/nimc.html)
Re: How to check an auto type parameter in a proce
Asking in the forum is not an issue, but what miran said is that he feels like you might be trying to solve your issue at a low level while we could solve the actual bigger problem. (correct me if I'm wrong @miran). 1\. Auto and Any type for input params are usually not needed, using a generic T is recommended instead. That also makes documentation much more clear. 2\. Proc resolve their type at compile-time, there is no runtime types for proc, you need to use methods for that. Instead you can use what @demotomohiro proposed or : proc foo[T](a: T) = when a is int: doInt() elif float: doFloat() else: doElse() Run 3\. For runtime types and containers of heterogeneous types (which is the bigger problem) we actually covered it in your other thread ["Is there an untyped list"](https://forum.nim-lang.org/t/4233).
Re: How to check an auto type parameter in a proce
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.
Re: How to check an auto type parameter in a proce
I don't want to use python because these reasons. 1. I need to use a third party app to make exe from python code. (I think python is not for windows) 2. Compiled exe is very large. A normal hello world gui app will size around 4-5 MBs. 3. Execution speed. I will sure consider the other opinions about this issue. But before that, i would like to do some experiments. > But how do you do the bookkeeping? For this, i have a work around like this. 1. I have a Control class which had same members of all controls. 2. I will cast the int into a Control class. 3. All of my controls have a unique type id. Which is actually an enum. cType* {. pure .} = enum Button, CheckBox, ComboBox, GroupBox, Label, ListBox, ListView, ProgressBar, RadioButton, TextBox Run 4\. So after casting, i will check the type id of that control and i will get the appropriate control.
Re: How to check an auto type parameter in a proce
> [XY problem](https://en.wikipedia.org/wiki/XY_problem)
Re: setLen without 0-initialization (for efficiency)
+1 on the feature. I also sometimes re-use buffers that would benefit from this.
Re: Nim source equivalent to C #define
One that hasn't been mentioned yet is simply: const NeededFlag = defined(DependentFlag) when NeededFlag: discard # code goes here Run
Re: Nim source equivalent to C #define
Actually Nim has {.define: identifier.} pragma, but then it was deprecated. I'm curious to know what was the reason. Doesn't it behave similarly with '-d:' or '\--define:'?
Nim developer retention data and out-of-date packages
Some people are just waiting for v `1.0`
Re: Nim source equivalent to C #define
I use a [nim.cfg in Arraymancer](https://github.com/mratsim/Arraymancer/blob/7edf23662328c059cd22be4cd08c00556321e4d1/nim.cfg#L43): @if cudnn: define:"cuda" @end Run
Re: Nim source equivalent to C #define
i just want to say, i love how many good options nim has for such a simple thing. Nim -- a buffet for the programmers taste
Re: Nim developers leaving Nim
Don't remember the specifics, but the conversation was around useful third-party libraries no longer maintained.. emacs mode, a few other, that sort of stuff.. and above all, anecdotal. Some hard data on this, ie how often it happens and why, would be interesting to see.
Re: How to check an auto type parameter in a proce
> I just tested it and it worked. Is there any problems using this method ? Of course you can cast refs or ptrs to int and store it in a seq of ints. But how do you do the bookkeeping? When you retrieve a value from your list, then its looks like an int. So how do you decide if it may be a ref to something. (Another problem is the GC, it may not keep objects alive if only ref is a casted int.) Other people already told you (in the other thread) which other possibilities you have in a static typed language like Nim. Or you can use a dynamically typed language like Python.
Re: Nim developers leaving Nim
To be fair, I think the "several prominent Nim developers" is blown out of proportion, it was a single person who left Nim years ago. AFAIK.
Re: Nim source equivalent to C #define
{. emit: """#define SOMEOPTION""" .} Run Literal, For C target.
Re: Nim developers leaving Nim
> Recently in the chat any links?
Nim developers leaving Nim
Recently in the chat, there was a conversation about several prominent Nim developers moving on to different language pastures, which made me curious. When I read about people discovering Nim, they're excited - the first impression is often good - but what causes them to later leave? * Has anyone conducted "exit" interviews or heard from these people? * Why is it hard to retain them? * What in the Nim eco-system (compiler, standard library, documentation, community, third-party lib support, tooling) deserves focus, if developer retention is the key metric? Nim conducts a survey every year - what has been gleaned from it? How do years compare with each other? What are the trends?
Nim source equivalent to C #define
Is there a pragma (or some such) that performs like the C preprocessor command: #define SOMEOPTION Run I would like definition of some debugging flags to automatically define others. For example: when defined(DEPENDENTFLAG): {.define(NEEDEDFLAG).} Run so that NEEDEDFLAG gets automatically defined even when the nim compille command is: nim c -d:DEPENDENTFLAG somesource.nim Run Thanks
Re: Nim source equivalent to C #define
const Thing = 0 when declared(Thing): const otherThing = 0 when declared(otherThing): echo "we are here" Run this works
Re: How to check an auto type parameter in a proce
> Three separate seqs with different data types and same name? Obviously makes > not much sense. Ha ha.. In my sense, it was like ; "Hey compiler, this is > 'one' seq but the data type is one among three. If the input value is int, > then treat this seq as a seq[int]. And when the input value is float, then > treat this seq as a seq[float]" How about casting objects into int ? Please see this pseudo code. 1. Assume that you have some ref object types like ComboBox, ListBos, Button etc. And you have a ref object named GroupBox. 2. You want to create a seq[int] in this GroupBox object. And you wrote an Add proc to add int items to this seq. 3. When ever you need add an object like ComboBox, ListBos, Button etc, you just using this ; var anInt : int = cast[int](ComboBox) YourList.add(anInt) Run And when you want to retrieve the object from this int seq, you just cast back to object like this. var aCombo : ComboBox = cast[ComboBox](anInt) Run I just tested it and it worked. Is there any problems using this method ?
Re: problem compiling to webassembly
Like this I have the same error. Plus I don't see that command when i type nim --help nim c -d:useRealtimeGC -d:release -d:emscripten --os:linux --out=index.html src/cacheim.nim Run of nim c -d:useRealtimeGC -d:release -d:emscripten --os=linux --out=index.html src/cacheim.nim Run
how to integrate existing react components in karax? (and vice versa)
/cc @araq| ---|--- * Can karax integrate arbitrary react components? if not, what are limitations? Are there examples for doing that? The more examples the better. eg: [https://github.com/brillout/awesome-react-components](https://github.com/brillout/awesome-react-components) for example, [https://github.com/MicheleBertoli/react-gmaps](https://github.com/MicheleBertoli/react-gmaps) or [https://github.com/CookPete/react-player](https://github.com/CookPete/react-player) * and vice versa: can react integrate karax components?
Re: setLen without 0-initialization (for efficiency)
PR's accepted?
a small change to macros.getCustomPragmaVal
real quick here is the code for the change macro getCustomPragmaVal*(n: typed, cp: typed{nkSym}): untyped = let pragmaNode = customPragmaNode(n) result = newTree(nnkPar) for p in pragmaNode: if p.kind in nnkPragmaCallKinds and p.len > 0 and p[0].kind == nnkSym and p[0] == cp: if p.len > 1: for arg in 1..(p.len-1): result.add p[arg] return else: return p[1] error(n.repr & " doesn't have a pragma named " & cp.repr()) # returning an empty node results in most cases in a cryptic error, Run and the original for reference macro getCustomPragmaVal*(n: typed, cp: typed{nkSym}): untyped = let pragmaNode = customPragmaNode(n) for p in pragmaNode: if p.kind in nnkPragmaCallKinds and p.len > 0 and p[0].kind == nnkSym and p[0] == cp: return p[1] error(n.repr & " doesn't have a pragma named " & cp.repr()) # returning an empty node results in most cases in a cryptic error, Run now running the original version with this code template test_prag(d:int,b:int) {.pragma.} type test_type {.tprag(10,20).} = int var a:test_type = 0 echo a.getCustomPragmaVal(tprag) # this outputs 10, there is no way to get the second value that I know of Run but with the change it would output (Field0: 10, Field1: 20) Run ill be using this myself, but I wanted to get others opinions
Re: A fast float to string conversion library
The underlying algorithm is nothing more than `grisu2` that's going to give you roundtrip-able values in the shortest amount of time, the tradeoff is in the 0.05% of numbers that cannot be "encoded" in the shortest possible way. For a stdlib implementation you may want to use something like `errol4` or `grisu3` plus some other fallback but, as expected, the implementation is slightly more complicated (see [Swift](https://github.com/apple/swift/blob/master/stdlib/public/runtime/SwiftDtoa.cpp) implementation to get a taste).
Re: Confusion about macros.
Thanks for the help. I didn't quite get what the not unused error was because it was so short and I was hung up on the other error.
Re: Is there any untyped list data type in Nim ?, like in python.
@kcvinu @miran, yes I'm using devel. I also prefer tagged union (also called sum types) in general to avoid the pointer indirection. Just be aware that with the second solution (inheritance/polymorphism) any user of your library can extend your base type with its own and reuse the methods you define while with the first solution (object variant/tagged union/sum type) adding a new subtype means modifying all proc using this type. The following blog post "[Sum Types Are Coming](https://chadaustin.me/2015/07/sum-types/)" summarizes that very well: > With sum types, it’s easy to add uses but hard to add cases. > With > interfaces, it’s easy to add cases but hard to add uses. Uses are new procs: it's easy to add new ones with sum types "proc foo = case ...", while with interfaces you need to update the base interface and add methods for each derived classes. Cases are new subtypes: just derive from the base type in interfaces, but with sum types you need to update your case statement in all the procs.
Re: Gara: pattern matching DSL
I am really happy to see a complete pattern matching library for Nim! Congratulations for your efforts!
Re: Confusion about macros.
This works: macro t2(): untyped = result = getAst(t1()) #t2() Run A macro produces an abstract syntax tree (AST) of nodes, that's what is assigned to its `result` variable. A macro call like `t1()` is replaced with the code representation of this AST, not with the AST itself. If you need the AST, and you do in `result = t1()` because `t2` is supposed to return an AST, wrap it with `getAST`. Alternatively, `t1` could become a `proc`. > Even stranger if I comment out t1 and add discard... The compiler just warns about `t2` not being used because the call to it is commented out, not sure what you mean.
Re: How to check an auto type parameter in a proce
miran I think your explanation is still too short for beginners... One should know that proc foo(a: seq[int|float|char]) Run is basically a short form for definition of three separate procs: proc foo(a: seq[int) proc foo(a: seq[float) proc foo(a: seq[char]) Run What would var mySeq : seq[ int | float | string] Run intent? Three separate seqs with different data types and same name? Obviously makes not much sense. Nim is indeed a bit too powerful for people with no basic Computer Science experience.
Re: How to check an auto type parameter in a proce
> 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]) echo foo(@['a', 'b', 'c']) Run