Re: javascript new object

2018-02-28 Thread stisa
>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

Re: shorthand for literal type annotations?

2018-02-14 Thread stisa
@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]

Re: Nim Dogfooding

2018-02-06 Thread stisa
> **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.

Re: Long story short.

2018-01-06 Thread stisa
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

Re: How does a

2017-12-11 Thread stisa
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.

Re: Can I somehow show context-specific information in an {.error.} ?

2017-11-20 Thread stisa
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)

Re: Can I somehow show context-specific information in an {.error.} ?

2017-11-20 Thread stisa
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)

Re: Why isn't this concept working as I would expect?

2017-11-05 Thread stisa
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.

Re: Why isn't this concept working as I would expect?

2017-11-04 Thread stisa
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

Re: I enjoy seeing the nimble package updates

2017-10-25 Thread stisa
Check out [https://nimble.directory](https://nimble.directory)/ too, there's a `New packages` section

Re: Cannot get name of type using typedesc

2017-10-24 Thread stisa
@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

Re: project organization question

2017-10-21 Thread stisa
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":

Re: Formatted Backend Output?

2017-10-08 Thread stisa
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

Re: Python-like with, context managers, and the RAII pattern

2017-09-29 Thread stisa
`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:

Re: Code substitution with templates

2017-09-25 Thread stisa
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

Re: Untyped overloading?

2017-09-20 Thread stisa
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

Re: parsecsv problem

2017-08-25 Thread stisa
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"))

Re: Nim newbie request/challenge

2017-08-09 Thread stisa
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

Re: Thoughts on imports

2017-07-20 Thread stisa
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

Re: "Warning: Cannot prove that 'result' is initialized"

2017-07-02 Thread stisa
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

Re: The Nim Language Manual

2017-06-29 Thread stisa
@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

Re: Can concepts/generics do type tags without affecting binary representation of the type?

2017-04-26 Thread stisa
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

Re: Checking in macro if proc has side effects or not

2017-04-21 Thread stisa
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

Re: New website released!

2017-04-20 Thread stisa
@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.

Re: New website released!

2017-04-20 Thread stisa
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?

Re: Need a push on investigation of compiler issue

2017-04-20 Thread stisa
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

Re: R extensions and Nim

2017-04-02 Thread stisa
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

Re: Help in compiling nim on android termux

2017-04-01 Thread stisa
@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

Re: Help in compiling nim on android termux

2017-04-01 Thread stisa
@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.

Re: Help in compiling nim on android termux

2017-03-31 Thread stisa
@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

Re: Help in compiling nim on android termux

2017-03-31 Thread stisa
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

Re: New bie: tuple of fixed length arrays

2017-03-22 Thread stisa
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

Re: REPL?

2017-02-26 Thread stisa
The repl is hidden in `nim secret`, I think because it's not really stable.

Re: ospaths and NimScript

2017-02-24 Thread stisa
Most of them are in [os](https://nim-lang.org/docs/os.html)

Re: Function v. Writing operations

2017-02-19 Thread stisa
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.

Re: var param vs tuple as return value

2017-01-25 Thread stisa
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

Re: Shift operation for array elements

2016-09-25 Thread stisa
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

Re: Shift operation for array elements

2016-09-24 Thread stisa
@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

Re: Shift operation for array elements

2016-09-24 Thread stisa
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) =

Re: zeroMem can't use?

2016-08-28 Thread stisa
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', '\

Re: Basic jupyter notebook kernel

2016-08-24 Thread stisa
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/

Re: Basic jupyter notebook kernel

2016-08-24 Thread stisa
@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

Re: Basic jupyter notebook kernel

2016-08-23 Thread stisa
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 &

Re: Basic jupyter notebook kernel

2016-08-03 Thread stisa
@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

Basic jupyter notebook kernel

2016-08-02 Thread stisa
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