[https://www.python.org/dev/peps/pep-0572/](https://forum.nim-lang.org/postActivity.xml#https-www-python-org-dev-peps-pep-0572)
# Python basic example
def test():
return 1
x = test()
if x == 1:
print(x)
# With python 3.8 Walrus operator:
d
Thank you :-) Nim is a great programming language
If you change the "yes" procedure to return a integer as a example not work
template `:=`(a, b): untyped {.dirty.} =
let a = b
a
proc yes: int = 1
if x := yes():
echo x
test.nim(7, 6) Error: type mismatch: got but expected 'bool'
I'm trying to read a text file asynchronous line by line but the following code
fails to compile
import asyncdispatch, asyncfile, os
proc main() {.async.} =
var filename = getTempDir() / "test.txt"
var file = openAsync(filename, fmWrite)
await file.w
Sorry the second the redefinition of file in invocation of openAsync it's my
mistake.
This compile but I get the same error:
import asyncdispatch, asyncfile, os
proc main() {.async.} =
var filename = "test.txt"
var file = openAsync(filename, fmRead)
while
I have created an issue [10641](https://github.com/nim-lang/Nim/issues/10641)
When test if a large number is prime I get the following error:
prime.nim(12, 14) Error: number out of range: '12548798547123658478'
Nim is fast for scientific computing and I enjoy writing code in Nim, but I am
a Nim newbie!
How to make this work for big numbers?
import math
Thanks for the hint!
This code is pretty simple and is a example, but is painfully slow for big
files (10Mb)!
How to read data chunks of request body to a temp file instead of reading
everything at once to memory?
import asynchttpserver, asyncdispatch
proc handler(req: Request) {.async.} =
Hi @dom96, I did an experiment (see
[https://github.com/mrhdias/EnigmaHTTPServer](https://github.com/mrhdias/EnigmaHTTPServer))
to decode the multipart/data request body by doing the cache of the body. I do
not know if it's the best approach, but it works and it's fast for large files
I modified Dominik Picheta asynchttpserver library to try decode the post
multipart request's. I'm a newbie in Nim programming, but the result can be
seen here:
[https://github.com/mrhdias/EnigmaHTTPServer](https://github.com/mrhdias/EnigmaHTTPServer)
At this point it is possible
This work:
$ ./server -p 8080 &> ./logs/server.log & echo $! > ./server.pid;
But is this the correct approach?
Thank you all for the suggestions. Just one more question: How do I catch a
"KILL" or "HUP" or user abort signal (CTRL-C)?
This code works as expected. But I wanted to replace the "block routes:" with
"routes:" only. Any idea how to do this?
import asynchttpserver, asyncdispatch
template via*(rule_path: string, reqMethods: seq[string], code_to_execute:
untyped): untyped =
if $req.reqMetho
Thank you, it works :-) I tried the same thing, but without the pragma
"{.dirty.}".
I'm trying binding libgd library with Nim, but I'm facing a problem with
pointers.
My interface:
# https://libgd.github.io/manuals/2.2.5/files/gd-h.html#gdPoint
type
gdImagePtr* = ref object
type
gdPoint* = object
x*: int
y*: int
Bingo Work!!! Tanks @yglukhov the solution is replace int with cint ;-)
type
gdPoint* = object
x*: cint
y*: cint
Run
c2nim not work very well :-(
$ c2nim --dynlib:libgd --cdecl ./gd.h --out:gdtest.nim
/home/hdias/development/tmp/gd.h(14, 62) Warning: comment
'version605b5d1778' ignored [CommentXIgnored]
/home/hdias/development/tmp/gd.h(15, 62) Warning: comment
'version605b5d1778' ignored [
Ok, you're right. But conversion is not trivial!
[https://github.com/nim-lang/c2nim/blob/master/doc/c2nim.rst](https://github.com/nim-lang/c2nim/blob/master/doc/c2nim.rst)
Thank you. It's a good starting point.
You are right @moerm. The solution I found was to copy and paste a group of
functions from the c file to another file and then run c2nim. Then copy and
paste another group of functions and run the c2nim again. And repeat this
procedure until the end of the c code.
I tried to compile a test program following the steps indicated in this
[post](https://forum.nim-lang.org/t/1866#11698), but it does not work.
$ nim c --cpu:arm64 --passC:-fPIE --passL:"-fPIE -pie" test.nim
$ adb devices
List of devices attached
42044158c4bc8100devic
Not work :-(
$ adb push test /storage/sdcard0/Download/test
$ adb shell chmod a+x /storage/sdcard0/Download/test
Bad mode
$ adb shell
10|shell@android:/ $ chmod 0755 /storage/sdcard0/Download/test
Unable to chmod /storage/sdcard0/Download/test: Operation not permi
Another alternative: [https://kivy.org](https://kivy.org)
Nim can speed up up this framework.
The rapid adoption of Nim can pass through the mobile apps.
Yes I enable developer options and software from untrusted sources.
I discovered that the problem is to write on the sdcard0. If I change the
location and try to run it gives another error: not executable: magic 7F45
$ adb push test /data/local/tmp/test
$ adb shell /data/local/
I tried to follow the recipe of this
[post](https://forum.nim-lang.org/t/1866#11698) but without success :-(
$ wget
https://dl.google.com/android/repository/android-ndk-r19c-linux-x86_64.zip
$ unzip android-ndk-r19c-linux-x86_64.zip
S
YSROOT=/home/hdias/Downloads/android-n
With latest android-ndk and the information from this
[post](https://forum.nim-lang.org/t/3575#22318)
#!/bin/sh
mkdir tmp
cd tmp
cp ../test.nim ./
git clone https://github.com/nim-lang/nim
wget
https://dl.google.com/android/repository/android-ndk-r19c-linux-
I know, but for testing I downloaded "android-sdk-ndk" directly from the
source. Yes works for x86 architecture, but my phone is arm and many brands of
mobile phones use arm.
I think it's not a root problem because it compiles on Android x86_64.
I finally succeeded :-) My android test phone is old. I found the solution
[here](https://stackoverflow.com/questions/27338318/cannot-load-library-reloc-library1285-cannot-locate-rand)
Work with API level 19!
test.bin: 1 file pushed. 1.2 MB/s (142260 bytes in 0.109s)
Hello Worl
I saw this [page](https://github.com/VPashkov/awesome-nim) and tested the
packages that are mentioned there (Game Development and GUI). Unfortunately
none of them work on android (I just tested on arm64 Nougat API 24):-(
For [SDL2](https://nimble.directory/search?query=sdl) there are many
imple
I think the problem is not the cross compiler, I can compile and run a "Hello
Wold" simple test. I use the NDK as shown below:
/home/hdias/tmp/android-ndk-r19c/toolchains/llvm/prebuilt/linux-x86_64/bin/aarch64-linux-android24-clang
\
-I/home/hdias/tmp/android-ndk-r19c/toolcha
I tried to compile some
[Examples](https://github.com/nim-lang/sdl2/tree/master/examples) from SDL Nim
official package for android, but without success!
Anyone have any ideas how to do it?
$
/home/hdias/tmp/android-ndk-r19c/toolchains/llvm/prebuilt/linux-x86_64/bin/aarch64-linux
Yes is possible create a app in Nim for android and iOS the solution is
[here](https://github.com/iffy/wiish) and works :-) After install the wiish
package, sdk and ndk for android setup an app is easy:
$ wiish init testapp
$ nano -w
testapp/dist/android/project/org.wiish.webvi
I've tried your solution, but it does not work. When I execute the command it
gives the following result:
$ nim --cc:clang
--clang.exe:/home/hdias/tmp/android-ndk-r19c/toolchains/llvm/prebuilt/linux-x86_64/bin/aarch64-linux-android24-clang
--clang.linkerexe:/home/hdias/tmp/androi
Fantastic work for a "hobby" project! I'm impressed!
I am trying to compress the responses that are sent by http:
import asynchttpserver, asyncdispatch
import zip/zlib
proc handle(req: Request) {.async.} =
if req.headers.hasKey("Accept-Encoding") and
req.headers["Accept-Encoding"] == "gzip":
let headers = new
Not work with miniz package. The browser show the following message:
This site can’t be reached The webpage at http://127.0.0.1:8080/ might be
temporarily
down or it may have moved permanently to a new web address.
ERR_CONTENT_DECODING_FAILED
I have tried with the [Nim freetype](https://github.com/jangko/freetype)
library, but it does not work and there is no documentation.
I found this page with an minimal example:
[https://ralsina.me/weblog/posts/playing-with-nim.html](https://ralsina.me/weblog/posts/playing-with-nim.html)
But it
Why not Flutter in Nim? This post ([Thought Experiment: Flutter in
Go](https://divan.dev/posts/flutter_go/)) show some directions to implement
this idea! With DSL (Domain-specific Language) is possible build a Flutter
widget tree in Nim?
Is it possible to create a dictionary like python by typing only:
var a = {"key_1": "value_1", "key_2": "value_2"}
Run
Instead of?
var a = {"key_1": "value_1", "key_2": "value_2"}.toTable
Run
or something similar to what is used by sequenc
Great. Works. Thank you.
What prevents it from being used only like this without "%", "@" or "toTable"?
var a = {"key_1": "value_1", "key_2": "value_2"}
Run
It's simple and everyone understands!
I did this small test and I don't see any problems or incompatibility. Can
someone show me where the use of the "%" can fail? Can someone show me an
example where the "%" is used in JSON as in tables "%{}"?
import tables
from strutils import `%`
import json
proc `%
It is complicated at this time to use the asyncdispatch as it has several
issues that have not been solved over time. At this time the Chronos is better
maintained and doesn't have the same issues.
The Perl 6 language has a symbol to represent infinity (∞). Anyone have any
ideas on how I can implement it in nim? Just for fun!
Use cases:
import math
import strformat
proc is_prime(n: int64): bool =
for i in 2 .. n-1:
if (n mod i) == 0:
Thanks @leorize it's so easy! and work :-)
const ∞ = high(BiggestInt)
echo ∞
for number in -∞ .. ∞:
echo number
Run
Thank you @LeuGim for your effort in dealing with infinity... even if not
really.
I remembered another symbol with infinite decimal places (π), but there are
many more.
import math
# const π = 3.141592653589793...
const π = PI
echo π
Run
These symbo
It's a matter of code readability and beauty :-) For example, modern code
editors may replace the keyword "sqrt" with the symbol " **√** " when checking
the syntax, but it would always be optional.
Typing these unicode symbols from the keyboard is not a big problem
>From the [wikipedia](https://en.wikipedia.org/wiki/Unicode_input): "For
>example, GTK+ is an ISO/IEC 14755-conformant system[citation needed]. The
>beginning sequence is Ctrl+⇧ Shift+U and the ending sequence is ↵ Enter or
>Sp
Example: several tables containing the details of books where each entry
corresponds to a different book.
Thanks :-)
I'm trying to create a session manager for a asyncrounous http server. I have a
table with all created sessions. Each session should be deleted after a certain
time if there are no user requests. The following prototype code (I don't know
if it's correct) creates the sessions, but then when the
Thanks, now it works. This is a prototype. I need to store the session in a
cookie and check if it already exists.
import asynchttpserver, asyncdispatch
import tables
import times
import oids
type
Session = object
map: TableRef[string, string]
When the code is compiled gives the following warning message:
template/generic instantiation of newTable from here
and
Warning: Cannot prove that 'result' is initialized. This will become a compile
time error in the future. [ProveInit]
How can I fix this?
$ nim c -r test.nim
I made some changes that corrected several warnings now it works as expected
with cookies. But it still shows warnings like these:
Warning: Cannot prove that 'n' is initialized. This will become a compile
time error in the future. [ProveInit]
Warning: 'set_session' is not GC-sa
Thank you @enthus1ast and everyone for showing me the way. Now all code
compiles without errors or warnings.
import asynchttpserver, asyncdispatch
import tables
import times
import oids
import cookies
import strformat
import strtabs
import strutils
I found this
[code](https://github.com/dom96/jester/blob/master/tests/fileupload.nim) for
uploading files, but it only works well for small files. With large files
(100MB) it’s very slow and my cpu goes up to close to 100%!
import os, re, jester, asyncdispatch, htmlgen, asyncnet
Thanks @mashingan, but how do I use writeFromStream, can you show me a use case?
I like the Jester but this issue is a problem when uploading multiple small
videos to a website! Is there a well-documented nim web framework that supports
the processing of large files?
Thanks @mashingan, I tested the code and it is awesome :-) But @mashingan is
right, the size of the files is different from the size of the uploaded file (I
think it's an easy fix error)! Will the websocket work if I use the nginx as a
frontend with ssl?
Where can I find documentation about this pragma?
In the following example, does it mean that the procedure with the pragma
".since" will be used starting with Nim 1.1?
include "system/inclrtl"
proc test() =
echo "old test"
proc test() {.since: (1, 1).} =
echo "new test"
test()
R
Thanks for explaining!
Nim don't have a library that support http/2 protocol. I found this library and
it already has a python binding.
[https://github.com/nghttp2/nghttp2](https://github.com/nghttp2/nghttp2)
Any ideas on how to achieve this for Nim?
Thank @shashlick I will give it a try. But, my first approach was to use the
c2nim and it works well.
But, when I import the library it gives the following error:
/home/hdias/test/nghttp2/nghttp2.nim(29, 16) Error: invalid token: _ (\95)|
---|---
## Define WIN32 when build
I needed help to create a template and/or macro that would allow to read small
chunks of data from a http body stream in an elegant manner. My idea can be
seen in the following code:
### Replace this code block
### Begin
let chunkSize = 8*1024
var
Thanks @Hlaaftana but, unfortunately it doesn't work!
/home/hdias/dev/tmp/test.nim(32, 25) template/generic instantiation of
`async` from here
/home/hdias/dev/test.nim(43, 10) template/generic instantiation of
`forStream` from here
/home/hdias/dev/tmp/test.nim(26, 24) templa
I find this repos for mysql and postgresql:
[https://github.com/wiml/nim-asyncmysql](https://github.com/wiml/nim-asyncmysql)
[https://github.com/cheatfate/asyncpg](https://github.com/cheatfate/asyncpg)
[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
70 matches
Mail list logo