Re: New here. can't seem to get the installer to work.

2017-04-24 Thread flyx
You have to give us some information to work with. For example, what C compiler are you using? And what's the output of the `sh build.sh` command when building from source? Since `bin/nim` doesn't exist afterwards, this is probably the problem, and the output most probably gives you the reason

Re: How check if expression has a type without triggering compilation failure

2017-04-05 Thread flyx
… because it is mentioned in the [system module's documentation](https://nim-lang.org/docs/system.html#compiles,expr).

Re: Procedure which returns procedure

2017-04-04 Thread flyx
Your code does not work because you are using `func` as identifier, which is a reserved keyword. I demangled it a bit and renamed `func` to `fun`: type MyProc1 = proc() MyProc2 = proc(p: MyProc1) MyProc3 = proc(p: MyProc1): MyProc1 proc applyAllSync(funcs:

Re: Procedure which returns procedure

2017-04-04 Thread flyx
Your JS is horrible to read as it lacks type information (what is funcs, what is onAllDone, what is doBefore etc). I tried to interpret it but gave up. You should rather explain what you want to do than giving us this piece of code.

Re: Procedure which returns procedure

2017-03-31 Thread flyx
Try: proc pprint[T1](ann: string): (proc(t0: T1): T1) = return proc(val: T1): T1 = return val echo pprint[int]("test")(42)

Re: Alternative comment syntax

2017-03-31 Thread flyx
@hcorion This is Neo2 (it states that itself) and it is an image for printing and gluing on the keys. Therefore, there are multiple meta-key images to choose from.

Re: Alternative comment syntax

2017-03-30 Thread flyx
> One key # is found only in UK and Ireland a far as I know. Germany… > Any keyboard, any standard, with numeric keypad, has + - * and /. So moving your hand over to the numpad and back is faster than pressing two keys? > Just need people to think more open minded and understand that "this

Re: Alternative comment syntax

2017-03-30 Thread flyx
> No attacks against anyone You called people > pythonic purists which is obviously referring to people rather than the issue itself. > I have no problems. Your previous posts sounded differently. > I want to help. Accept or deny. Lacking commitment to discuss does not make your proposal

Re: Alternative comment syntax

2017-03-30 Thread flyx
> 1\. Many keyboards does not have an one key access to "#", > as the "/" key, > mine for instance, I usually need to look at alt-3 > or shift-3 combination. Same is true for almost all other special characters which are used often in Nim, e.g.: `(`, `)`, `:`, `=`. I do not see how `#` is

Re: Macro with runtime arguments

2017-03-22 Thread flyx
The macro will slurp `if debug: true else: false` as expression. It will not be resolved; instead, inside the macro, you will have this whole expression in your variable `debug`. > Is there a way to 'extract' the boolean value of (the identifier) debug in > the macro It does not have a value

Re: I compiled libui.dll file is not successful

2017-03-21 Thread flyx
By the way, you can check dependencies of your DLL with dumpbin.exe /dependents libui.dll (given that you have Visual Studio installed; it's in the VC bin folder)

Re: I compiled libui.dll file is not successful

2017-03-21 Thread flyx
Well there are a lot of programs which just bundle MSVCP140.dll with their executable, like you do with libui.dll. So why not just place MSVCP140.dll next to it? > It's also possible to directly install redistributable Visual C++ DLLs in the > application local folder, which is the folder that

Re: I compiled libui.dll file is not successful

2017-03-21 Thread flyx
> But I have a version of libui.dll (linked above), which does not have this > dependency and runs fine I highly doubt it. The MSVCP140.dll is the C/C++ standard library on Windows, and almost every C/C++ program depends on it. Typically, Windows has some version(s) of this dll already

Re: Macro with runtime arguments

2017-03-21 Thread flyx
`debug` is an identifier and does not have a `boolVal`. You want to have `dumbMacro true` instead of `dumbMacro debug`.

Re: I compiled libui.dll file is not successful

2017-03-21 Thread flyx
> complaining about a missing MSVCP140.dll So why don't you just [download](https://www.microsoft.com/en-gb/download/details.aspx?id=48145) and install it?

Re: How to be more concise in code [NEWBIE]

2017-02-16 Thread flyx
> but did not want to use inheritance and methods because it needs heap > allocation You are using strings so your objects are doing heap allocations anyway. You should replace the strings with IDs of the target which got hit / died if you don't want any heap allocation. You can of course do

Re: Chocolatey Package for Nim?

2017-01-28 Thread flyx
With the same argument, it would also be necessary for Nim to have an official package for debian, Fedora, Arch, Nix, Homebrew… I think maintaining packages is in better hands with those people who use the package managers.

Re: Forum rules

2017-01-26 Thread flyx
There are no official rules. There have been threads about having a CoC and the majority was against it. General opinion usually is _„instead of thinking about rules, just write some Nim code“_. There also isn't some big sign on your front door which tells you how to behave while out on the

Re: Return SUM types from proc

2017-01-25 Thread flyx
Generally speaking, whenever you are using `if v of SomeType`, you are holding it wrong. Polymorphism gives you the power of defining dispatching methods for operations whose implementation differs based on which subtype your variable holds. If implementing your code with dispatching methods

Re: Return SUM types from proc

2017-01-25 Thread flyx
References (or pointers) are a prerequisite for runtime polymorphism since they are the only way to have differently typed values fit into the same memory location, since all pointers have the same size. Might not be true for all languages.

Re: Return SUM types from proc

2017-01-25 Thread flyx
`A or B` needs to be collapsed to one definite type at compile time. It is typically used for parameter types where the compiler sees which type is given at the calling site. This is not applicable if you want your return values to have different types at runtime. There are multiple solutions.

Re: var param vs tuple as return value

2017-01-25 Thread flyx
Well there's a [nim](http://stackoverflow.com/questions/tagged/nim) tag on StackOverflow. It certainly wouldn't harm if Nim had more exposure there. I think this forum should be more for discussions which do not fit into SO's Q format.

Re: How to understand pragmas in Nim?

2017-01-24 Thread flyx
proc compile(code: string): {.compileTime.} NimNode = This is a syntax error because the proper syntax would be: proc compile(code: string): NimNode {.compileTime.} = Partly related: Ada is in a similar state. In the rationale of Ada 83, pragmas were described as

Re: No way to run my code, idk how to force a float as an Int

2017-01-23 Thread flyx
This happens because `/` on ints returns a float. You want to use `div` instead, which is integer division. var maxLignes = ((nombreDePyramides + 2) * (nombreDePyramides + 3)) div 2 - 4 Or, alternatively, convert it – this is clearly the inferior solution, but given here for

Re: Nim VFS (virtual file system)

2017-01-16 Thread flyx
Some thoughts: The idea seems to be basically what Java does with `*.jar` files. And you say Tcl also does it. So why can they do this? They can because running both a Java application and a Tcl script requires a runtime environment (Tcl interpreter / JRE) on the target machine. So if the user

Re: Please , can we stop spams?

2016-12-23 Thread flyx
Having a GitHub account should not be required to participate in the community and I think it's harmful to make people with few original Nim code second-class citizens.

Re: Return values question

2016-12-13 Thread flyx
Interesting. I only remember that Araq once explained that strings and seqs are heap objects managed by the garbage collector, but I may have misunderstood it. In any case, there should be some official documentation about this.

Re: Return values question

2016-12-13 Thread flyx
> When a shallow sequence is resized, only the variable currently being > modified has its reference updated; the other variables will still have > references to the old data. proc foo() = var a = newSeqOfCap[int](2) a.add(1) var b: seq[int] shallowCopy(b,

Re: Newyear is coming , is 2017 the year for nim?

2016-12-10 Thread flyx
I have heard that 2017 will already be the year of Linux on the desktop, so Nim might have to wait one more year.

Re: Using Nimscript as an embedded scripting language?

2016-12-05 Thread flyx
> Is it possible to use Nimscript as an embedded scripting language In theory: Yes, of course. Why shouldn't it? In practice: Since the compiler and the standard library are rather modular, you can include parts of it in your project. However, there is no API dedicated to what you want to do,

Re: Same line versus single-line block in the AST

2016-11-28 Thread flyx
> And usually there are no parts in the AST that are "always" there to always > ignore Well that's good to know :). I wrongly assumed by testing that the `RecList` will always be there.

Same line versus single-line block in the AST

2016-11-28 Thread flyx
Consider this code: import macros dumpTree: type ObjectKind = enum oA, oB ObjectType = object case kind: ObjectKind of oA: a: string of oB: b: string ObjectType2 =

Re: NimYAML 0.7.0 released

2016-11-28 Thread flyx
`loadToJson` ignores tags because the JSON structures do not know anything about tags. You have several options: **Using the serialization API with an implicit variant object** First, you need to define the type for the tag `!remote`. You need to tell NimYAML how to load that type. Then, you

Re: noob: json to object conversion

2016-11-26 Thread flyx
Since YAML is a superset of JSON, you can use [NimYAML](http://forum.nim-lang.org///nimyaml.org) to deserialize the JSON file. It is able to automatically map a JSON object to a Nim object: import yaml.serialization, streams type Config = object rootDev: string

Re: nim4Android

2016-11-10 Thread flyx
Wouldn't it make more sense to bind Nim to Android NDK? I think you would have a hard time to call Android UI libs through jnim, unless you provide a thick layer. There is also [NativeActivity](https://developer.android.com/reference/android/app/NativeActivity.html) which enables you to write

Re: NimYAML 0.7.0 released

2016-11-08 Thread flyx
NimYAML 0.8.0 is now available. Its focus was on making it more capable of being used for configuration files: * You can now set default values of object fields with `setDefaultValue`. * You can now mark object fields as transient with `markAsTransient` so that they are not serialized or

Re: Generic openarray param

2016-10-28 Thread flyx
I wonder why this fails: type Iterable = concept c for i in c: discard proc test[T](x: T) = echo x proc test(x: Iterable) = for i in x: echo i test(1) test([1, 2, 3]) Shouldn't `Iterable` be a better match?

Re: What is "Metaprogramming" paradigm is used for?

2016-10-23 Thread flyx
I explained some basic metaprogramming stuff in my [article on NimYAML](https://flyx.org/2016/09/22/nimyaml/). Actually, [NimYAML](http://forum.nim-lang.org///nimyaml.org) as a whole is a good example of metaprogramming usage, because what is does is not doable in most other languages (though

Re: Macro: enumerate exported functions from a module

2016-10-21 Thread flyx
Wow, I never thought of that. With this, we can write [fuckit.nim](https://github.com/ajalt/fuckitpy)!

Re: Macro: enumerate exported functions from a module

2016-10-21 Thread flyx
If you write the module yourself, the simplest way would be: macro myMacro(body: typed): typed = # do things here # # do not forget to add the original procs to the output! myMacro: proc proc1*() = discard proc proc2*() = discard #

Re: Markdown parser

2016-10-20 Thread flyx
The Nim compiler has the `rst2html` action which transforms a reStructuredText file to HTML. It can do everything Markdown can, plus some extras (e.g. Nim syntax highlighting). By default, it uses the same HTML template which is being used for generating API documentation (with `nim doc` / `nim

Re: Is there anyway to change the NimNode(stmt) to string?not the ast format

2016-10-13 Thread flyx
node.repr

Re: problem when use lua bind

2016-10-13 Thread flyx
var p = cast[ptr fuck](L.newuserdata(sizeof(fuck).cint)) You allocate memory which is **not zeroed**. So its content may change depending on what it was used for beforehand. echo repr(p) Now you want a representation of that memory. `p.ud` may have any value here.

Re: Performance of fastRows at module db_sqlite

2016-10-09 Thread flyx
Yes, Stefan's solution is somewhat nicer, didn't think about that. If there is more data involved, split may be further accelerated by setting `maxsplit`: let (lookup_id, lookup_name_source) = p.rowEntry(col).split('|', 2)[0..1]

Re: Performance of fastRows at module db_sqlite

2016-10-09 Thread flyx
I cannot really answer the question whether there are missed optimization opportunities in Nim's SQLite wrapper, but being a wrapper, it sounds unlikely. There are some things about your code I can comment on: lookup_id = p.rowEntry(col).split('|')[0] lookup_name_source =

Re: Nim code to Remove Accented Letters

2016-10-03 Thread flyx
Here is how you can do it with premature optimization: import unicode, strutils proc translationTable(src, dest: string): array[0x1f00, char] {.compileTime.} = for i in 0..<0x1f00: result[i] = '\0' var srcIndex = 0 destIndex = 0 while

Re: Nim Chess 2 with transposition table support is available

2016-10-03 Thread flyx
Your compilation instructions would probably be nicer if, instead of depending on absolute paths and symlinks, there would be a Makefile like this: board: board.nim engine.nim nim c -p:../nim-gio/src -p:../nim-atk/src -p:../nim-glib/src -p:../nim-gdk3/src -p:../nim-gtk3/src

NimYAML 0.7.0 released

2016-10-01 Thread flyx
://github.com/flyx/NimYAML/issues/24). * YAML compliance has been improved. A complete list of changes is available [here](https://github.com/flyx/NimYAML/blob/devel/CHANGELOG.md). NimYAML 0.7.0 requires Nim 0.15.0.

Re: about nimscript

2016-09-21 Thread flyx
What is _code_? An INI file also contains _code_, i.e. some text structure that complies with a grammar. You also need a parser to read it programmatically. You may want to post some references about what's the problem with Python's setup.py, because from what you write, it doesn't seem

Re: Unable to parse JSON Payload

2016-09-15 Thread flyx
`application/json` is not a supported enctype in HTML. See [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/API/HTMLFormElement/enctype). There was a [proposal](https://www.w3.org/TR/html-json-forms/) for it - note the giant yellow-dotted banner there. It is not actively

Re: Getting captures from PEGS match

2016-09-12 Thread flyx
> This will work if I use @["", ""] instead, but I don't see why I have to? Because `match` takes an `openarray[string]` for `matches`. It means that the proc works with both an array and a seq. And an array cannot be extended. Since the number of matches in your PEG is statically known, it

Re: Is this a compiler bug?

2016-09-09 Thread flyx
I agree that it would be able to determine wether this is a proc call or a type conversion from the parameter type. This can be a feature request. It is probably not so simple to issue a warning with such conflicts, because the type may be defined in one module, the proc in another module, and

Re: Is this a compiler bug?

2016-09-09 Thread flyx
Where would the compiler bug be? You define a proc named `int`, so when encountering `int(k)`, the compiler tries to call this proc instead of doing a type conversion. I'd say, it behaves as expected. Since types are not keywords in Nim, it is not per se illegal to name a proc `int`.

Re: International Keyboard Setting not mapping correctly in Aporia under Windows

2016-09-08 Thread flyx
Partly related: I know that GTK's support for Keyboard layouts on Windows is rather broken, because they do not use the API as they should. This has forever been a problem with the Neo layout I use for typing. It is no problem on OSX or Linux. GTK devs marked this issue as _wontfix_. But I am

Re: The cstring type and interfacing with the backend.

2016-09-01 Thread flyx
> Everything is split more explicitly, and there is no system wide hybrid type > that has to be compatible with whatever the backend is. So, one cstring for `char*`, one for `std::string`, one for `NSString` and one for JS' `string`? That looks like an awful lot of string types.

Re: Nim doc page broken

2016-08-31 Thread flyx
I created a pull request that fixes this: [https://github.com/nim-lang/packages/pull/408](https://github.com/nim-lang/packages/pull/408)

Re: Where do I learn how to program Nim without a GC?

2016-08-25 Thread flyx
> I mean somehow I have to tell Nim when to free memory right? Yeah sure, you just use these: [alloc](http://forum.nim-lang.org///nim-lang.org/docs/system.html#alloc,Natural), [dealloc](http://forum.nim-lang.org///nim-lang.org/docs/system.html#dealloc,pointer),

Re: Strange GC problem ?

2016-08-23 Thread flyx
Yeah, if `ref array` does not work properly, it should indeed produce a compiler error. You should file a GitHub issue.

Re: dynamically creating a tuple

2016-08-22 Thread flyx
As I said, you cannot create a _dynamic_ tuple. The tuple type must be fixed at compile time. I believe you will get better answers if you show example code with an input sequence, and expected output. For me, it is still rather unclear what you are trying to achieve, because when you have a

Re: dynamically creating a tuple

2016-08-22 Thread flyx
You cannot have `10` and `'a'` in the same sequence. `10` is an `int`, `'a'` is a `char`.

Re: dynamically creating a tuple

2016-08-22 Thread flyx
It is not clear what exactly you are trying to accomplish. d = (b: 10, c: "cd") This already creates a tuple and is not a sequence. How does the sequence you talk about look? Since the tuple needs one `int` and one `string`, you would not only need to map the sequence items

Re: Documentation colour theme

2016-08-21 Thread flyx
The text I quoted said _consider_. Not _do not use black_. The author considered it and decided to use both black and dark gray text (see the text in the margin and the footer?).

Re: Documentation colour theme

2016-08-21 Thread flyx
Another opinion on text color from [here](http://forum.nim-lang.org///practicaltypography.com/color.html): > But con­sider mak­ing body text on screen dark gray rather than black. > Screens have more se­vere con­trast than pa­per, and thus are more tir­ing to > read at full con­trast. This is

Re: Going to Haxe. Nim In Action book available.

2016-08-15 Thread flyx
> I have yet to seen a single example of anybody using namespacing in > functional programming. Then again, its relative "new" in PHP. rofl PHP is all but a functional programming language. I think you are confusing terms here, _functional_ programming languages are things like Haskell, Scheme

Re: Going to Haxe. Nim In Action book available.

2016-08-14 Thread flyx
> Is this implying that sufficiently large codebase of any other (or of a > specific programming language) would look any better? I don't think so, but > i'd like to hear about that. Almost all codebases of large applications look awful. There are a lot of reasons for that other than

Re: Going to Haxe. Nim In Action book available.

2016-08-14 Thread flyx
> In general object oriented programming results in a more clean code base ( > example ). Have you ever seen any codebase of a sufficiently large Java library/application? I have yet to see _one_ example where OOP lead to a cleaner code base. [This image is usually a pretty accurate

Re: Execution speed Nim vs. Python

2016-08-11 Thread flyx
cblake: C11 made VLAs an optional feature though. I consider C VLAs a very poor solution; as you say, it's mostly syntactic sugar for alloca. And yes, something between array and seq would be nice. But currently, Nim's type system does not allow a type with a runtime-calculated length

Re: Execution speed Nim vs. Python

2016-08-10 Thread flyx
Stefan_Salewski: > May it be possible to have one single Seq in each proc on the stack? Of > course it has to be the last element, and can only work when that proc do not > call other procs. That may be possible, but far too complicated with far too few impact on performance. The compiler

Re: Execution speed Nim vs. Python

2016-08-10 Thread flyx
> I do not understand the use of the openarray parameter in relation to > performance. `openarray` has nothing to do with performance. It is just a feature to allow implementing procs that take both an `array` and a `seq` as parameter. The actual performance gain stems from using arrays

Re: spawninig of more than 8 threads problem

2016-08-09 Thread flyx
Well, I'm done with ideas. If you want to investigate further, I guess gdb or lldb would be able to help you see what's happening.

Re: spawninig of more than 8 threads problem

2016-08-09 Thread flyx
On second thought, the scheduler may be intelligent enough not to start more than one thread if it knows that they all wait for the same resource. But I wouldn't assume it.

Re: spawninig of more than 8 threads problem

2016-08-09 Thread flyx
Well it works for me with 32 characters in the string (Linux, 4 CPUs). So it seems to depend a bit on the OS - and therefore, the scheduler. > I think this shouldn't be the case. I'll try to explain what might happen. I do not know all internals involved, so it may or may not be accurate.

Re: spawninig of more than 8 threads problem

2016-08-09 Thread flyx
The problem is that threads _go to sleep while still holding a lock_. Well, the real problem is that afaik there is no guarantee that this code will ever finish, because the scheduler is not required to ever wake the right thread when a bunch of other threads are still waiting. But anyway,

Re: TaintedString.parseInt problem

2016-08-07 Thread flyx
@luntik2012: From documentation of `execProcess`: > WARNING: this function uses poEvalCommand by default for backward > compatibility. This means that it executes the command within a shell, which is probably responsible for the trailing newline. @Stefan_Salewski: Well, it's easy enough to

Re: TaintedString.parseInt problem

2016-08-07 Thread flyx
The problem is that the result of `execProcess` contains trailing whitespace (a newline in this case). Try: return execProcess(command & "" & filepath & ) / 1000""").strip.parseInt

Re: Inline ASM

2016-08-05 Thread flyx
Look [here](http://forum.nim-lang.org///nim-lang.org/docs/manual.html#statements-and-expressions-assembler-statement).

Re: Nim how to write plug-ins to achieve dynamic loading?

2016-08-05 Thread flyx
Compile your plugins with `--app:lib`, then use the `dynlib` module in the main program to load them at runtime.

Re: How do I pass an operator as proc parameter?

2016-08-03 Thread flyx
Usually, you would define `action` as `proc(l,r: T): T`. But this does not work for `xor` because of this paragraph in the manual ([see also](https://github.com/nim-lang/Nim/issues/2172)): > Assigning/passing a procedure to a procedural variable is only allowed if one > of the following

Re: Dynamic Object Type Fields

2016-07-30 Thread flyx
This is not possible by design. type test* = object Here, you declare an object that has no fields. var t = test() Here, you instantiate this object. `t` has the type `test`. var t.name = "kek" The compiler now looks at `t`'s type

Re: Convert seq into tuple

2016-07-28 Thread flyx
> I hope I'm wrong and there is an elegant way to define a large tuple. What do you need a tuple this size for? Your problem is likely that you use the wrong tool for the job. The need to write var myTuple: tuple[a00,a01,a02,a03,a05 ... a98,a99: int] roots from the nature of

Re: gensym pragma with names of entity passed as template parameter not working as expected

2016-07-27 Thread flyx
You cannot `gensym` the pragma since it is injected as parameter. But you can simply enclose the template body in a block: template foo(txn, body: untyped): untyped = block: let txn = 1 body foo hello: echo hello foo hello: echo

Re: Convert seq into tuple

2016-07-27 Thread flyx
proc fillTuple[T: tuple, V](target: var T, input: openarray[V]) = var index = 0 for field in target.fields: assert input.len > index field = input[index] inc(index) var myTuple: tuple[a,b,c: int] fillTuple(myTuple, @[1, 2, 3]) Or, if

Re: macro changing type of const literals not working

2016-07-19 Thread flyx
Works for me on devel. However, the bit with the `include` does not.

Re: [macro] Adding echo to a function

2016-07-06 Thread flyx
import macros macro addEcho(s: untyped): stmt = s.body.add(newCall("echo", newStrLitNode("OK"))) result = s proc f1() {.addEcho.} = let i = 1+2 echo i You have to use untyped because with stmt, Nim seems to create a symbol f1 beforehand and