Re: Nested list comprehension

2020-03-06 Thread whospal
Expected results... # Python output: unitlist = [['A1', 'B1', 'C1', 'D1', 'E1', 'F1', 'G1', 'H1', 'I1'], ['A2', 'B2', 'C2', 'D2', 'E2', 'F2', 'G2', 'H2', 'I2'], ['A3', 'B3', 'C3', 'D3', 'E3', 'F3', 'G3', 'H3', 'I3'], ['A4', 'B4', 'C4', 'D4', 'E4', 'F4',

Re: Nested list comprehension

2020-03-06 Thread whospal
Expected results... # Python output: unitlist = [['A1', 'B1', 'C1', 'D1', 'E1', 'F1', 'G1', 'H1', 'I1'], ['A2', 'B2', 'C2', 'D2', 'E2', 'F2', 'G2', 'H2', 'I2'], ['A3', 'B3', 'C3', 'D3', 'E3', 'F3', 'G3', 'H3', 'I3'], ['A4', 'B4', 'C4', 'D4', 'E4', 'F4',

Re: How does one get a `var` from a `ref` object?

2020-03-06 Thread leorize
You de-reference the `ref`, like this: proc foo(i: var int) = discard let a = new int foo(a[]) #^~ dereference operator Run

How does one get a `var` from a `ref` object?

2020-03-06 Thread adnan
I think the code and the error message explains it better: import options, sequtils type Person = object id: int name: string Spouse = object base: ref Person engagedTo: Option[ref Person]

Re: HELP: async httpclient running out of response

2020-03-06 Thread slime496
Thank you again . I will try to approve my code with your suggestions

Re: Nested list comprehension

2020-03-06 Thread whospal
Thanks for the info. Yes, I'd tried the sugar package but failed. Will checkout the comprehension package.

Re: Nested list comprehension

2020-03-06 Thread whospal
Thanks! Just a clarification, why your codes have the brackets around the y loop, and not around the result.add? cross(xs, ys: string): seq[string] = for x in xs: (for y in ys: result.add x & y) Run While @trtt has it around the result.add? cross(a,

Re: How can I simulate "name[id]" behaviour?

2020-03-06 Thread mratsim
`proc `[]`(a:ptr VSMap, idx:int):string = discard "implementation here" ` Run

Re: Performance test agains Python

2020-03-06 Thread mratsim
I'm always saying that but `strutils` is the biggest performance trap of Nim. The operations always return a new string which makes it easy to compose and very very heavy on the memory management. Python and Javascript have heavy optimizations done from string and fast string manipulation in

Re: Nim 1.1.1/devel: programs silently crashing with --gc:arc

2020-03-06 Thread mratsim
Not sure if they work with arc but compiling with the following flags might give you an actual stacktrace: `-d:useSysAssert -d:useGcAssert`

How can I simulate "name[id]" behaviour?

2020-03-06 Thread mantielero
I have a function, and I'd like to make it look like a Seq. How can I do that? The original funcion looks like: theFunction(a:ptr VSMap, idx:int):string = Run and I would like to be able to use it like this: a[idx] Run

Re: Karax: Adding elements

2020-03-06 Thread jyapayne
You need to use the `VNode` data type in the seq. This is a working example: include karax / prelude var elements: seq[VNode] = @[] proc createDom(): VNode = result = buildHtml(tdiv): button: text "Say hello!" proc onclick(ev:

Karax: Adding elements

2020-03-06 Thread herdingSheep
How do I add HTML elements at runtime? I am aware of the following example [https://github.com/pragmagic/karax#event-model ](https://github.com/pragmagic/karax#event-model) but I can not convert the example to anything else but a kstring. Manipulating the code ends in failure. What if I wanted

Re: Nested list comprehension

2020-03-06 Thread kaushalmodi
> how about you first get familiar with the correct Nim syntax for them? link Wait, you are linking against the deprecated lc syntax. I believe the closest non-deprecated solution is [https://github.com/alehander92/comprehension](https://github.com/alehander92/comprehension) ?

Re: Nim 1.1.1/devel: programs silently crashing with --gc:arc

2020-03-06 Thread Stefan_Salewski
Have you tested with valgrind when your code has been compiled with \--gc:arc -d:useMalloc ? Note that the default refc GC may hide bugs, as memory is freed with delay. While ARC does deterministic memory release at end of proc. Maybe we should try address sanitizer of gcc or clang -- I have

Re: Performance test agains Python

2020-03-06 Thread Stefan_Salewski
> Ok, I guess the string manipulations in Python are implemented with C as well, Yes, most basic operations in Python are generally coded in C and are optimized well. But what you can try: Put all your code in a main() proc. Whenever you do benchmarking, you should do that, in some cases it

Re: Nested list comprehension

2020-03-06 Thread miran
> The documentation of Seq & Tables are very poor in Nim. Not many examples to > learn from. If something has a solid documentation and lots of examples, then it is `tables` module. :rolleyes:

Re: Nested list comprehension

2020-03-06 Thread miran
> I tried with... > > [invalid syntax] If you really want to force list comprehensions, how about you first get familiar with the correct Nim syntax for them? [link](https://nim-lang.org/docs/sugar.html#\[\].m%2CListComprehension%2Cuntyped%2Cuntyped) But my advice would be: don't use list

Re: Why does `setCommand` exist?

2020-03-06 Thread dawkot
I still don't get it. Setting -d:js in my config file makes nimble build output js code instead of a binary just as much as setCommand js.

Re: Nested list comprehension

2020-03-06 Thread dawkot
This should work: import tables, strutils proc cross(xs, ys: string): seq[string] = for x in xs: (for y in ys: result.add x & y) let rows = "ABCDEFGHI" cols = "123456789" squares = cross(rows, cols) var unitSeq: seq[string] for

Nim appears for the first time listed in the TIOBE Index!

2020-03-06 Thread mrhdias
[https://www.tiobe.com/tiobe-index](https://www.tiobe.com/tiobe-index) The Next 50 Programming Languages The following list of languages denotes #51 to #100. Since the differences are relatively small, the programming languages are only listed (in alphabetical order). (Visual) FoxPro, ABC,

Re: Nested list comprehension

2020-03-06 Thread whospal
Some more codes... # Python codes: unitlist = ([cross(rows, c) for c in cols] + [cross(r, cols) for r in rows] + [cross(rs, cs) for rs in ('ABC','DEF','GHI') for cs in ('123','456','789')]) units = dict((s, [u for u in unitlist if s in u]) for s

Re: Nim 1.1.1/devel: programs silently crashing with --gc:arc

2020-03-06 Thread trtt
Sorry, can't reproduce with simple code.

Re: sublimetext nim plugin (NimLime) hasn't worked since july

2020-03-06 Thread Lomar
Sorry to revoke this old thread, but I'm trying to install "NimLime" on Sublime Text 3.2.2 (Build 3211) and it's not listed at the available packages. I've added the github repository following the instructions: i) Package Control: Add Repository ->

Re: Performance test agains Python

2020-03-06 Thread NimFI
Ok, I guess the string manipulations in Python are implemented with C as well, and there is not much of lack from dynamic nature of Python in this case. I checked once more after all the modifications to both codes, with 100% same replaced lines, here's the results: Nim: 0.085 s Python: 70.0

Re: Performance test agains Python

2020-03-06 Thread Vindaar
As far as I know such simple string manipulations are actually pretty fast in python. So don't expect an amazing speed improvement over python if your code is this simple. In more "real world" examples you'll see Nim outperforming Python.

Re: Performance test agains Python

2020-03-06 Thread NimFI
still at 0.09 s with: var flDurat: float = 0.0 sFind: string = seqParams[1].replace("\"", "") sLine: string = "" let sFile: string = seqParams[0] sReplaced: string = seqParams[2].replace("\"", "") flTime= cpuTime()

Re: Performance test agains Python

2020-03-06 Thread NimFI
Thanks, I actually removed the unnecessary find already, but I didn't notice I do the replace for the sReplaced variable every time, which is silly. Will test again!

Re: Performance test agains Python

2020-03-06 Thread Vindaar
You have to be aware that using strings this way is always going to be somewhat inefficient, since each replace call will make a copy! Of those especially in the following: f2.writeLine(sLine.replace(sFind, sReplaced.replace("\"", ""))) Run the sReplaced.replace("",

Re: Performance test agains Python

2020-03-06 Thread NimFI
Oh! Sorry, I added the -d:release, but when compiling with _only_ that flag, I got: 0.085 s So pretty much as fast as python, although I assumed would be still faster?

Re: Nim 1.1.1/devel: programs silently crashing with --gc:arc

2020-03-06 Thread enthus1ast
please share example code

Nim 1.1.1/devel: programs silently crashing with --gc:arc

2020-03-06 Thread trtt
Using this version, my programs sometime quit prematurely with error code: 0. It happened two times: once I queried a Table with an undefined key, and another time the json module's parseFile failed because of an invalid json file. No error was thrown and the programs just stopped. Using

Re: Performance test agains Python

2020-03-06 Thread NimFI
Now it's around 0.2 seconds with the -d:release

Re: How does one use switch for optional types?

2020-03-06 Thread PMunch
I've written a library for options that does exactly this, amongst other useful things with options: [https://nimble.directory/pkg/optionsutils](https://nimble.directory/pkg/optionsutils)

Re: Performance test agains Python

2020-03-06 Thread miran
> `#Compile: nim --passc:-flto --opt:size c test.nim` Use `-d:release` and try again, please.

Re: How does one use switch for optional types?

2020-03-06 Thread trtt
case is a switch statement. import options let x = some(true) if x.isSome(): echo x.get() else: echo "none" Run

Another state of generating Android APK thread...

2020-03-06 Thread GordonBGood
# Another state of generating Android APK thread ## Synopsis The capability of easily compiling Nim to generate an Android installable APK file via the Android Native Development Kit (NDK) as per the title of the thread seems to be a subject of on-going interest, including by me. ## Past

How does one use switch for optional types?

2020-03-06 Thread adnan
I think the code should explain it better: import options let maybe = some[bool](true) case maybe: of true: echo "true" of false: echo "false" of none[bool](): echo "none" Run The compiler complains that

I have some problem about linux

2020-03-06 Thread htwatch
I cannot install applications on linux like they do on other operating systems.

Performance test agains Python

2020-03-06 Thread NimFI
Hello Nim users! Just discovered Nim and have been playing with it. Can you tell me what I am doing wrong here? Because Python seems to be much _faster_ than Nim with this code? This python code is executed to a text file with 3.6MB in size, some 43000 lines. (sorry, can not publish the file)

Re: Why does `setCommand` exist?

2020-03-06 Thread moigagoo
No, these are completely different. The first one runs `nim js`, the second one `nim c -d:js`.