>From the
>[manual](https://nim-lang.org/docs/manual.html#implementation-specific-pragmas-importcpp-pragma)
> :
proc cppMethod(this: CppObj, a, b, c: cint) {.importcpp: "#.CppMethod(@)".}
Produces:
x->CppMethod(1, 2, 3)
As a special rule to keep backwards compat
@Ar : if you are on devel, you can use
[mapLiterals](https://github.com/nim-lang/Nim/blob/devel/lib/pure/collections/sequtils.nim#L721)
from sequtils
import sequtils
let x = mapLiterals([0.1, 1.2, 2.3, 3.4], int)
doAssert x is array[4, int]
> **miran**: 3. How do I share a link to a specific comment in the thread?
There's a PR open for this [#114](https://github.com/nim-lang/nimforum/pull/114)
Anyway,the forum is fairly useable, only thing I miss is notifications for
replies.
Hi, welcome to Nim community!
You may consider adding your company to [Companies Using
Nim](https://github.com/nim-lang/Nim/wiki/Companies-using-Nim) if you end up
using nim in production.
All contributions to nim ecosystem are welcome! Feel free to drop by on irc (or
[gitter](https://gitter.i
ror: execution of an external program failed:
'C:\Users\stisa\OneDrive\Progetti\nimtemp\kueues.exe '
compiling with `nim c -r --threads:on kueues.nim` on a Windows 10 x64, using
gcc.
Mmh there is an error proc in macros that I _think_ does that:
[https://nim-lang.org/docs/macros.html#error,string,NimNode](https://nim-lang.org/docs/macros.html#error,string,NimNode)
You can use asserts:
let b: byte = 42'u8
let c = 42'u16
proc test*[T](t: T): bool =
assert(sizeof(T) == 1, "invalid parameter size: " & $sizeof(T))
result = true
echo test(b)
echo test(c)
Uh strange, I tried it here
[https://glot.io/snippets/ev7buwzukn](https://glot.io/snippets/ev7buwzukn) and
it worked fine, it's probably a regression.
This works for me:
type
ConceptA = concept c
ConceptB = concept c
c.myProc(ConceptA)
Obj = object
proc myProc(obj: Obj, x: ConceptA) = discard
echo Obj is ConceptB #true
As for why, I'm not really sure as I
Check out [https://nimble.directory](https://nimble.directory)/ too, there's a
`New packages` section
@LeuGim sorry to hear that, I'll try to fix it later today.
I'm not a webdev, so I was under the impression that the `Access-Control...`
part was to be done server-side.
As for the `innerText` bit, you are right, Firefox only added it in 45. I'll
try using `textContent` instead, which should be
You can also use nimscript to create the dir ( eg `mkdir "tests"`), or do some
nice things like build all tests in a dir, eg
import ospaths
task tests, "Runs tests":
withdir "tests":
for file in listfiles("."):
if splitfile(file).ext == ".nim":
Besides embedsrc, see also
[https://nim-lang.org/docs/nimc.html#compiler-usage-command-line-switches](https://nim-lang.org/docs/nimc.html#compiler-usage-command-line-switches)
. The``genMapping`` option may be useful too.
I'm not sure this is what you are asking, but if you want to know how the
`with` is a keyword, so you can't use that. You could use something like this
maybe?
import macros
macro take(args,body:untyped):untyped =
result = newstmtlist()
result.add(newvarstmt(args[^1],args[1]))
for st in body: result.add(st)
take 3 as f:
You can also mark the whole template with `{.dirty.}`
template someCode(): untyped {.dirty.}=
var
fname: string = "Mark"
age: int = 44
someCode()
echo fname # "Mark"
echo age # 44 Notice both symbols are visible outside the template.
S
My guess is that you need `mixin` to have the symbol lookup happen later, but
I'm not familiar with that part of the language.
`mixin` is mentioned here
[https://nim-lang.org/docs/manual.html#generics-symbol-lookup-in-generics](https://nim-lang.org/docs/manual.html#generics-symbol-lookup-in-gene
With [existsFile](https://nim-lang.org/docs/os.html#existsFile,string) you
could do something like
import os
let filename = "my.png"
if not existsFile(filename):
raise newException(IOError, (filename & " not found"))
Sounds interesting, I might try doing a direct port from cpp to nim when I get
some free time.
Btw, download is indeed behind a paywall (looks like scribd offers a month free
but after that it's paid). Reading is free though.
Copy pasting from the pdf is impossible, as latex or whatever mangles
For 1, if the condition is available at compile time (generally this means
`abc` and `def` are `const`) you can use a `when` block to import the module,
eg:
when cond:
import foo # this is only imported if `cond` is true and evaluable at
compile time
if cond:
foo.b
You can avoid the warning by having the enum start at 0:
type MouseButton* = enum
mbNone
mbLeft = 1
mbMiddle = 2
mbRight = 3
Since enum default to the value 0, and your enum starts at 1, the default value
of your enum is invalid:
type Mous
@oyster : the source is [text
files](https://github.com/nim-lang/Nim/tree/devel/doc/manual) (they are
actually rst) which you can convert to pdf with `koch pdf`, it does
rst->latex->pdf
If you want a prebuilt version, I built the pdf some time ago:
[here](https://github.com/stisa/mi
This is the closest thing I can think of:
import macros
macro dotAccess(o: typed, str: static[string]): untyped =
# Macro to do `o.str`, probably not the best way
newDotExpr(o,newIdentNode(str))
type
DataTable = concept x
x is tuple|object
Something like this?
import macros
proc clean(a, b: int) : int =
result = 2 * a + b
proc dirty(a,b:int): int =
echo "dirty"
3
macro hasNoSideEffects(p : typed) : untyped =
result = newCall("compiles", newNimNode(nnkProcDef))
l
@andrea: for packages sites, there are also
[http://nimism.co](http://nimism.co)/ and
[https://nimble.directory](https://nimble.directory)/ , it would make sense to
ask their devs to merge into a single project.
Docker is mentioned under unix for some reason
[https://nim-lang.org/install_unix.
I like the new website, it's definitely an improvement over the old one,
especially on mobile.
Also, did you know that
[https://nim-lang.org/blog.html](https://nim-lang.org/blog.html) leads to the
new blog, while [https://nim-lang.org/blog](https://nim-lang.org/blog) leads to
araq's musings?
I don't know if it's a compiler bug or not, the manual says `The [] subscript
operator for arrays/openarrays/sequences can be overloaded.` but eg in macros
and I think tables it's used.
Anyway, for me on `git hash: b7bffa35c70eb1a55fe9e35307ba4e99e48abe69`
* Tuple and object versions with sub
Just guessing, never tried anything like it, but you could try pre generating
the sources for the platforms you want with something like [cross
compiling](https://nim-lang.org/docs/nimc.html#cross-compilation) and then
detect the one to compile with R?
It would be similar to how Nim does bootst
@NastyRigger: that's what `-d:android` does:
[https://github.com/nim-lang/Nim/blob/c480505797f9d82b9b19a72b5a5abde9c0cb0fd4/lib/posix/posix.nim#L2426](https://github.com/nim-lang/Nim/blob/c480505797f9d82b9b19a72b5a5abde9c0cb0fd4/lib/posix/posix.nim#L2426)
@cheatfate : thanks for the pointer, I'll
@amedeo : try compiling koch with `nim c -d:android koch` , if it works you can
add `define:android` to `config/nim.cfg` so you won't need to define it every
time you compile something.
@NastyRigger : This is just a guess, and I can't test it, but you could try
changing `sigtimedwait` into `__rt_sigtimedwait` . Looks like `sigtimedwait` is
present in `signal.h` starting from android api 23.
@Araq : I could try making a PR, I'm guessing the part in `nim.cfg` should go
in a `@if
Just removed termux and reinstalled from scratch ( I can only test on my phone,
android 7 ), here are my steps:
apt install git
apt install clang
git clone https://github.com/nim-lang/Nim
cd Nim && git clone https://github.com/nim-lang/csources
apt install libandroid
Since arrays need to have a know length at compilè time, a tuple of arrays is
simply:
type
A = tuple
ints:array[3,int] # an array that contains 3 integers
strings:array[3,string] # 3 strings
var
arrint = [1,2,3]
arrstr = ["one","two","three
The repl is hidden in `nim secret`, I think because it's not really stable.
Most of them are in [os](https://nim-lang.org/docs/os.html)
Looking at the docs [here](https://nim-lang.org/docs/system.html#14) , `..` is
an alias for `countup`.
btw, this
for i in ..10: echo i
works.
There's an irc channel here
[http://webchat.freenode.net/?channels=nim](http://webchat.freenode.net/?channels=nim)
, which is bridged to gitter, so you don't have to sign up. It's also logged,
so you can read past conversations ( logs go back to about june 2012 I think ?
) [http://irclogs.nim-l
shift[T](a: var openarray[T]; d: int) =
if d == 0: discard # do nothing
elif abs(d) >= a.len: # reset all
for el in a.mitems: el.reset
elif d > 0: # right shift
moveMem(addr a[d], addr a[0], (a.len - d)*sizeof(T))
for j in 0..https://gist.github.com
@OderWat: do you mean something like this?
proc shift[T](a: var openarray[T]; d: int) =
if d == 0: discard # do nothing
elif abs(d) >= a.len: # reset all
zeroMem(addr a[0], a.len*sizeof(T))
elif d > 0: # right shift
moveMem(addr a[d], addr a[0], (a.le
Nice, though I'm used to shift meaning "remove the first value of the
(resizable) array and return the value", I think your proc feels more like it's
"scrolling" the array?
Anyway, naming aside, what do you think of this version?
proc scroll[T](a: var openarray[T]; d: int) =
Nim has implicit initialization (
[http://nim-lang.org/docs/manual.html#statements-and-expressions-var-statement](http://forum.nim-lang.org///nim-lang.org/docs/manual.html#statements-and-expressions-var-statement)
) so:
var x : array[10,char]
echo repr x # ['\0', '\0', '\0', '\
Hi Peter,
I knew the shadow variable looked too easy! Oh well... :)
( sorry if I keep asking obvious questions, I'm not used to handling memory and
the like. I'll have to read up on how memory is handled by nim, the gc, etc )
So you have compile master> master runs block1, forwards its
memory/
@mora: Sounds like a good plan!
I'm still relatively new to nim, so it's probably more detailed than anything I
would have thought of.
A couple of questions, sorry if they are obvious / make little sense:
> The python wrapper will pass the code this binary, which will compile it, and
> call it
nim](https://github.com/stisa/jupyter-nim-kernel/blob/master/resources/master.nim)
there is a ported version commented out, but as I don't understand how it
should work the ported code is probably useless.
>From what I can understand, it compiles a master as a dynlib that should then
&
@OderWat: Thanks for the PR!
I didn't think about tempnames, I guess I got lucky ( or I just didn't notice
the bug ).
As per disabling `hint[Processing]`, I am on Windows 10 64-bit, and it's still
not silent. I guess it's similar to
[http://forum.nim-lang.org/t/2350/1](http://forum.nim-lang.or
Hi all, I got a basic kernel for jupyter notebook working, you can find it on
[github](https://github.com/stisa/jupyter-nim-kernel) .
It's based on
[jupyter-c-kernel](https://github.com/brendan-rius/jupyter-c-kernel) (
actually, it's mostly the same ) and it uses the python impleme
45 matches
Mail list logo