Can iterators not be variables?

2022-08-26 Thread emre
Thanks! I think the error message is misleading. Could it be improved so that a user can identify the problem alone?

Json serialization and polymorphism

2022-08-26 Thread ElegantBeef
Since Nim is statically typed you have to be able to branch the code at the deserialise stage, so ideally you'd store the type information as a string in serialise. Then just generate a case statement of all types that inherit from and call their deserialiser. The issue with that is there is no

Json serialization and polymorphism

2022-08-26 Thread Aquachain
Thank you for your reply. Yes, thats what i currently do. Every type has its own list. But it feels wrong with so many different types. I'am not that experienced in Nim. Is it possible to save the typedescription as property and use it to generate the specific type? This would be useful. For e

Json serialization and polymorphism

2022-08-26 Thread ElegantBeef
As far as i know there are no good ways to automatically serialise polymorphic types with Nim. So one would have to manually handle each type and serialise/deserialise it. may be of some help in that regard.

Can iterators not be variables?

2022-08-26 Thread ElegantBeef
If you want to easily convert to a closure my package [slicerator](https://github.com/beef331/slicerator) contains a `asClosure` macro which would turn the above into: var input = asClosure "ABCDEFGABF".items for c in input: echo c Run

Can iterators not be variables?

2022-08-26 Thread Yardanico
Default Nim iterators are always inlined, so they're not first-class. What you want are closure iterators, they are first-class and can be passed around. For example: iterator myitems(x: string): char {.closure.} = for elem in x: yield x var input = "ABCDEFGAB

Can iterators not be variables?

2022-08-26 Thread emre
Why does this fail? var input = "ABCDEFGABF".items for c in input: echo c Run > Error: undeclared field: 'items' for type system.string whereas this passes? var input = "ABCDEFGABF" for c in input.items: echo c Run

Convert Python codes to Nim codes

2022-08-26 Thread whospal
Looks like it's not easy to convert from Python to Nim. :(

Json serialization and polymorphism

2022-08-26 Thread Aquachain
Hello, can someone tell me how to use Json serialization while preserving types. I use polymorphism and want to save and load data from an application. Here is a small example: import json, marshal, os type Node* = ref object of RootObj InputN

Using return in templates returns nil

2022-08-26 Thread mashingan
I usually define template without returning when I want it as statement executions: template doStmt = echo "do this" template doubleInt(x: int): untyped = x * 2 doStmt() echo doubleInt(3) Run Especially when I want the template to ch

Using return in templates returns nil

2022-08-26 Thread NameUndefined
I though of the template expanding order, but I ended up thinking that it shouldn't cause any issues. For the `a validate proc is expecter to return a bool`. That's what Im doing as a "temporary fix". I still wanted to experiments with templates. Thanks for the answer.

Using return in templates returns nil

2022-08-26 Thread mratsim
I'm not sure what `srv.pages` is doing but it's possible that its transformation is applied **before** your template is expanded. The issue is that async transformation then checks the `return` statement to transform them into async `yield` (suspension) point. But the one within your template h

Using return in templates returns nil

2022-08-26 Thread NameUndefined
Hi, im writting a small API using the [Akane](https://github.com/Ethosa/akane) package, on all my routes I use the exact same 2 lines wich basically returns from the main function if condition is met. To avoid manually copy pasting them I converted them to untyped templates. When the return is t

The Salewski Chess Engine is finally available

2022-08-26 Thread Pyautogui
Wonderful! Thanks so much !