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', '
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', '
You de-reference the `ref`, like this:
proc foo(i: var int) = discard
let a = new int
foo(a[])
#^~ dereference operator
Run
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]
preferences
Thank you again . I will try to approve my code with your suggestions
Thanks for the info. Yes, I'd tried the sugar package but failed. Will checkout
the comprehension package.
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, b
`proc `[]`(a:ptr VSMap, idx:int):string = discard "implementation here" `
Run
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 Ni
Not sure if they work with arc but compiling with the following flags might
give you an actual stacktrace: `-d:useSysAssert -d:useGcAssert`
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
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: Event;
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
> 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)
?
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 ne
> 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 can
> 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:
> 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 comp
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.
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 c
[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, Act
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 i
Sorry, can't reproduce with simple code.
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 ->
[https://github.com/Varriount/NimLime](https:
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 m
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.
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()
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!
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("", "
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?
please share example code
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 -d:rele
Now it's around 0.2 seconds with the -d:release
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)
> `#Compile: nim --passc:-flto --opt:size c test.nim`
Use `-d:release` and try again, please.
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
## 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 refer
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 m
I cannot install applications on linux like they do on other operating systems.
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)
No, these are completely different. The first one runs `nim js`, the second one
`nim c -d:js`.
41 matches
Mail list logo