seq vs array vs open array

2022-11-06 Thread ynfle
You can also do echo &"{typeof(a) = }" Run

let variable is not gc safe

2022-07-28 Thread ynfle
let is immutable, as the address of the variable can be taken. Once an address is received, it can outlive its lifetime

how to create structures based on user types/fields?

2022-07-17 Thread ynfle
If you share some code, we could weight in. You can try discord/irc/matrix for real time help

New floating type problem

2022-07-13 Thread ynfle
Why should it be?

If imported name conflicts with Nim keyword, what would you call it?

2022-06-27 Thread ynfle
Why not use `methodName` and `typeName`?

Have a nim tool in nimble installation error

2022-06-16 Thread ynfle
In future, you could also try pass `-f` to the compiler which ignores that cache and forces a rebuild

"nimble init" creates Unittest-Example-Files that do not work

2022-06-01 Thread ynfle
Testament is harder to use

"nimble init" creates Unittest-Example-Files that do not work

2022-06-01 Thread ynfle
This works for me on macOS

Any expert help to transpile and convert Python

2022-06-01 Thread ynfle
You could get ideas from this thread

How to build a static library after nimble install?

2022-05-20 Thread ynfle
(Great article, by the way)

Nim v2: what would you change?

2022-05-17 Thread ynfle
Tuples are dangerous. 2 tuples which the same number and type of fields are equivalent

to enum type and back

2022-05-17 Thread ynfle
`Message.msg` is the enum `MsgKind`, but `msg` for the proc is string, int or float. Those types aren't compatible. You want something like this type MsgKind = enum mkString, mkInt, mkFloat Message* = object topic*: string

to enum type and back

2022-05-17 Thread ynfle
If you want to have better control over when the id is there, you can do something like this MsgKinds = string | int | float MsgType = enum mtPS, mtRR, mtR Message*[T: MsgKinds] = object topic*: string msg*: T

Hello Javascript!

2022-05-08 Thread ynfle
import std/jsconsole console.log "Helo, World" Run compiled with `nim js -d:release -d:nodejs jstest.nim` results in /* Generated by the Nim Compiler v1.6.6 */ var framePtr = null; var excHandler = 0; var lastJSError = null;

Best practices for porting huge C projects to Nim

2022-05-03 Thread ynfle
You can Futhark, c2nim, nimterop as tools. I'd assume futhark is the best (without experience)

Introspection over a proc type

2022-04-27 Thread ynfle
This should work import std/[macros] func f(x: int, y: seq[string], z: cint): seq[string] = discard proc expectSymKind*(n: NimNode, k: set[NimSymKind]) = if n.symkind notin k: error("Expected one of " & $k & ", got " & $n.kind, n) macro

Introspection over a proc type

2022-04-26 Thread ynfle
I know that this is just an example, but what are you trying to do? The reason this doesn't work, is because the parameter passed in to the macro is a proc type, but because macros operate on ASTs it is converted to a `NimNode`. If you just want to get the return type, you wouldn't use a macro

Introspection over a proc type

2022-04-26 Thread ynfle
If you post more information, I'd be happy to help you out

Introspection over a proc type

2022-04-26 Thread ynfle
A macro is code manipulation tool, you can't return a variable initialized inside the macro. What you can do is generate the AST that will initialize a variable. Is this what you wanted? import std/[macros, strformat, strutils] func f(x: int): seq[string] = discard

Introspection over a proc type

2022-04-26 Thread ynfle
I'm not sure what are you trying to do. What is the seq with a string in is supposed to be? A type? You also redeclared x. What are you trying to accomplish?

Introspection over a proc type

2022-04-26 Thread ynfle
It doesn't return a NimNode, it does a code replacement (that's what macros do) of the return type of the proc. That can be demonstrated with the following code import std/macros func f(x: int): seq[string] = discard macro getReturnType(x: proc): untyped =

Introspection over a proc type

2022-04-25 Thread ynfle
import std/macros func f(x: int): seq[string] = discard macro getReturnType(x: proc): untyped = x.getimpl.params[0] echo getReturnType(f) echo default(getReturnType(f)) & "monkeys" Run

Compiler ignores my `if` a throws an error

2022-04-17 Thread ynfle
Use `when` to test the type, not `if`

Hopefully simple Nim syntax question

2022-04-14 Thread ynfle
The reason is because `var` means it will be modified. If it's passed in like that how are you supposed to "retrieve" the modification

Hopefully simple Nim syntax question

2022-04-14 Thread ynfle
See `sugar.dup`

Creation of Variant Types with Table Members

2022-04-10 Thread ynfle
You shouldn't need `new result` if you are using an object constructor `Atom(kind: FUNC)`

System.sink & System.lent

2022-04-07 Thread ynfle
Because you may not want to force it to be inlined

System.sink & System.lent

2022-04-06 Thread ynfle
The different between inheriting from `RootObj` or `RefRoot` and from a base object, is the 2 object hierarchies that both inherit from one of the system define roots can interfere with each other. . In this example `A` and it's "siblings" may be the

Threading SIGSEGV in HttpClient with SSL

2022-04-05 Thread ynfle
This compiles and runs for me. Which OS are you and what is your nim version?

[Karax] "include" statement doesn't work correctly inside karax DSL

2022-04-03 Thread ynfle
How a DSL be done then? Wouldn't everything be expanded?

How setBlocking to false on newSocket?

2022-04-02 Thread ynfle
Do you have `std/nativesockets` imported?

[Karax] "include" statement doesn't work correctly inside karax DSL

2022-04-02 Thread ynfle
This is true for `untyped` macros, but a macro (like the one below) does have the `include` statement expanded to the ast of the included file. import macros macro t(x: typed) = echo repr x t: include tables Run

Newbie questions about Nim, Python, XCB

2022-03-28 Thread ynfle
You could also run nim and call python with nimpy

`$` not working on custom type when imported in other modules

2022-03-27 Thread ynfle
Very true

`$` not working on custom type when imported in other modules

2022-03-27 Thread ynfle
I solution (depending what's in the file) could be to `include` it

Read output only while input is not asked

2022-03-21 Thread ynfle
Your issue is that b is waiting to receive input and you are waiting to read a line until the stream closes. Try

The 'for i in ...' loop inside parsing macro

2022-03-18 Thread ynfle
You don't need to quote anything with a ` in a template

Naylib - yet another raylib wrapper becomes available

2022-03-15 Thread ynfle
I'm pretty sure enum (or rather sets or enums) are compatible with c bitsets,

To have source file has been normalized

2022-03-14 Thread ynfle
Are you looking for `macros.expandMacros`?

Factorial computation in Nim

2022-03-02 Thread ynfle
Here is an implementation using `bignum` and benchmarking with `benchy`. import std/strutils import benchy import bignum template one(): Int = newInt(1) #[ template benchmark(benchmarkName: string, code: untyped) = block: let t0 =

How to correctly augment async future data

2022-02-28 Thread ynfle
That seems to work! # - How can I get access to the completion time (info.finish) when the request # has been fullfilled? # - My guess is that in the callback *info* is being *passed by value* so the timestamp # (info.finish) isn't being updated ( and is returned as

How to correctly augment async future data

2022-02-28 Thread ynfle
How should it work? You didn't give it a mechanism to edit the original `URLInfo` or return it from the proc. It's passed by value. This works though. Note the times are slightly off because the finish time is in slightly different places. # - How can I get access to the

Need variable to be constant on runtime without initialization at declaring

2022-02-28 Thread ynfle
I find it considerably more readable and less error prone to do let n = if u > 7: 3 else: 1 Run

OrderedTable missing Seq methods

2022-02-26 Thread ynfle
A table, the general programming, doesn't have a concept of indexes so accessing by index doesn't make so much sense. I'm not sure if you want to find by key or value. For key you can use `in`. For value you can use @sls1005's answer. It seems your ids are sequential, so you could use a `seq`.

Catch exceptions without crashing app

2022-02-21 Thread ynfle
`error(e.msg)` crashes the program. If you didn't what to exit, you can just `echo e.msg`

variable has incomplete type: struct...

2022-02-21 Thread ynfle
If it's literally just a struct, you `object`

variable has incomplete type: struct...

2022-02-21 Thread ynfle
It's possible using `ref` here is bad because nim will want to control the memory

Stumped! Extending futures with addition context info

2022-02-19 Thread ynfle
>From this code it does: # Background: # - Test harness to check out how to extend a httpclient future to include # additional context information (in this case the source url which could be # usefull in reporting failures) import std/[asyncdispatch,

Nim devroom at FOSDEM this weekend

2022-02-19 Thread ynfle
Try both `webm` and `mp4`, `webm` worked for me.

Templates and generics

2022-02-18 Thread ynfle
I'm not sure what the issue is, but it exists even without using templates as far as I can tell

Stumped! Extending futures with addition context info

2022-02-16 Thread ynfle
This should work. Extending `Future` are more straightforward # Background: # - Test harness to check out how to extend a httpclient future to include # additional context information (in this case the source url which could be # usefull in reporting failures)

Questions about UFCS and generics

2022-02-16 Thread ynfle
The issue here is `$` binds the whole expression nothing to do with UFCS

REPL works for Nim at Replit. Anything like VS or VS Code REPLs?

2022-02-13 Thread ynfle
Check out play.nim-lang.org

Array type to boolean type conversion

2022-02-13 Thread ynfle
What else would `>` be? Unless you come from C

Array type to boolean type conversion

2022-02-12 Thread ynfle
`bool` is unnecessary

Array type to boolean type conversion

2022-02-12 Thread ynfle
`echo [] is bool`

no operation on Nim syntax

2022-02-12 Thread ynfle
I think you're looking for `discard`

Void as a type in a tuple

2022-02-06 Thread ynfle
As far as I know, void can only be used as a return type of a routine and is the return type in some situations as in the following example: import std/macros macro t(x: typed) = echo repr x.gettype func x() = discard t(x) Run

Void as a type in a tuple

2022-02-06 Thread ynfle
A void Value is not the same as a void type

Void as a type in a tuple

2022-02-06 Thread ynfle
Please don't use a pointer here.

Void as a type in a tuple

2022-02-06 Thread ynfle
A type can't be void. That would mean there is not type associated with it.

Void as a type in a tuple

2022-02-06 Thread ynfle
Nil is not void

Void as a type in a tuple

2022-02-06 Thread ynfle
Are you trying for default or optional parameters?

Variable compile-time import paths

2022-01-31 Thread ynfle
`nnkImportStmt` is enum value of `NimNodeKind`. You need to call `nnkImportStmt.newTree`. There are a bunch of convenience procs in the macros module: * `ident` * `infix`

Nim's autoformatter situation

2022-01-30 Thread ynfle
See

How to find bottlenecks?

2022-01-28 Thread ynfle
It works on linux, you need clang and pass additional params

How to find bottlenecks?

2022-01-28 Thread ynfle
Try

What about `or=`, `and=` and `xor=`?

2022-01-25 Thread ynfle
You can do `|=`

What about `or=`, `and=` and `xor=`?

2022-01-25 Thread ynfle
There are a limited set of words that can be infix as @ElegantBeef said

Nim Community Survey 2021

2022-01-17 Thread ynfle
Would it be expanded?

Topfew - a Nim port of Tim Bray's logfile utility

2022-01-16 Thread ynfle
So which do you use for maximum performance? Or you don't use any regex library at all in that case

Topfew - a Nim port of Tim Bray's logfile utility

2022-01-16 Thread ynfle
Which is slower?

Topfew - a Nim port of Tim Bray's logfile utility

2022-01-16 Thread ynfle
Checkout regex which is written in pure nim and doesn't depend on PCRE

Cleanup at program end - open files automatically closed?

2022-01-16 Thread ynfle
Ok. Although I don't usually do manual file handling

Cleanup at program end - open files automatically closed?

2022-01-16 Thread ynfle
They will leak even as the program exits?

Nim Community Survey 2021

2022-01-15 Thread ynfle
Are you asking for yourself or just commenting that Beef's article doesn't address that?

Nim Community Survey 2021

2022-01-15 Thread ynfle
Have you seen @ElegantBeef's ?

Why don't build Nim libraries ecosystem on Rust ecosystem?

2022-01-13 Thread ynfle
> As Rust doesn't have GC Neither does nim > So, I don't know, if write wrapper is easily in Nim. Why it exist still some > pure Nim library with same feature than libraries in C or Rust ecosystem? It's safer than C

How to import all identifiers from module

2022-01-11 Thread ynfle
That's for defining a const through the command line. This is not the same.

What's the proper idiom?

2022-01-10 Thread ynfle
You don't need the parentheses

What's the proper idiom?

2022-01-09 Thread ynfle
This is what I was suggesting

What's the proper idiom?

2022-01-09 Thread ynfle
Can you share your code? I did not get the same result

What's the proper idiom?

2022-01-09 Thread ynfle
What is wrong with a constructor?

What's the proper idiom?

2022-01-09 Thread ynfle
I don't think so

What's the proper idiom?

2022-01-09 Thread ynfle
You can use a proc `first` that could be called as `instanceOfT.first` to access the field. Beware of templates though!

enum in macro

2022-01-03 Thread ynfle
In general, a macro is used for code generation. In nim there are a bunch of constructs for compile time evaluation/execution (`const`, `static`, `.compileTime.`, etc) outside of macros

enum in macro

2022-01-02 Thread ynfle
This should work proc getDefaultFiles(): array[TEMPLATE_FILES, string] {.compileTime.} = for i in TEMPLATE_FILES: result[i] = staticRead $i Run

enum in macro

2021-12-30 Thread ynfle
I'm still not sure what you are trying to do and why you need a macro? Are you trying to get the string value of the enum value?

Nim : Style insensitivity , snake_case , camelCase

2021-12-30 Thread ynfle
I find camelCase easier to type

Ported C++ OpenGL/GLFW code to NimGL, runs, but geometry seems wrong

2021-12-29 Thread ynfle
`doAssert` can be used instead

enum in macro

2021-12-29 Thread ynfle
What are you trying to do?

Ported C++ OpenGL/GLFW code to NimGL, runs, but geometry seems wrong

2021-12-25 Thread ynfle
What version of nim are you using?

high memory usage with large number of HashSets. 3X more memory than Python

2021-12-24 Thread ynfle
Besides for @ElegantBeef's suggestions, you could also try `std/intsets`

What approach can I use to fix a number of parameters in some functions?

2021-12-19 Thread ynfle
Either with default parameters or overloading the function definition. Check the manual () for these. My guess is you come from a dynamic language like python, ruby, javascript

Httpbeast failed to compile on Android arm device

2021-12-14 Thread ynfle
Is there a reason for this? Could you take a look in asyncdispath under `when ioselSupportedPlatform` on line 1375 for 1.6.0

Httpbeast failed to compile on Android arm device

2021-12-13 Thread ynfle
`addTimer` isn't defined for the android platform. Not sure why... it doesn't seem to use any routines that need the `ioselectors` functionality that I guess isn't supported on android

Httpbeast failed to compile on Android arm device

2021-12-13 Thread ynfle
What are you building? It's probably an issue with android

Httpbeast failed to compile on Android arm device

2021-12-13 Thread ynfle
There seems to be an issue with you nim installation, as `addTimer` exists as far back as version 0.8.14

Httpbeast failed to compile on Android arm device

2021-12-13 Thread ynfle
The latest version of httpbeast is 0.3.0

Error: identifier expected, but got: paramStr(1)

2021-12-12 Thread ynfle
Also don't import system, it's imported automatically

  1   2   3   >