Re: How to raise an exception from a template?

2020-04-05 Thread jyapayne
You should also be able to do


template final_sort2(v: typed) =
  raise newException(Exception, "Incompatible type: " & $v)


Run

Because type overloading does not include return types


Re: How to raise an exception from a template?

2020-04-05 Thread spip
Replying myself to my question.

Even if the flow of control is supposed to stop because of the exception, as 
the template is declared to return a typedesc, the last instruction **must** be 
a typedesc else the compiler prints another error... So to get the expected 
behaviour, the correct last template is now:


template final_sort2(v: typed): typedesc =
  raise newException(Exception, "Incompatible type: " & $v)
  AST_null


Run


Re: How to write shell scripts in Nim

2020-04-05 Thread kaushalmodi
I have a bit involved NimScript: 
[https://github.com/kaushalmodi/nim_config/blob/master/config.nims](https://github.com/kaushalmodi/nim_config/blob/master/config.nims)

See if going through it and referring to docs helps you. 


How to raise an exception from a template?

2020-04-05 Thread spip
I'm using Nim type system and templates to build a table of allowed types in a 
DSL language, like the following:


template final_sort2(v: bool): typedesc =
  AST_bool
template final_sort2(v: int): typedesc =
  AST_int
...
template final_sort2(v: typed): typedesc =
  {.line: instantiationInfo().}:
raise newException(Exception, "Incompatible type: " & $v)


Run

How can I have the compiler raise the exception when the last template is 
selected?

The code works without that last template, but the error message and the stack 
trace reported by the compiler does not help the developer understand the 
reason of the problem.


Error: in expression 'final_sort(b)(ite`gensym19185006)': identifier 
expected, but found 'final_sort(b)'


Run

I would rather have a specific message reported when I can. 


Re: Destructor not called for ref object

2020-04-05 Thread lscrd
As far as I know, the default has not changed in 1.2. It’s better as some 
programs will not work with `--gc:arc` without changes (if you have created 
cycles). I suppose the default is likely to change with 2.0.


Re: How to write shell scripts in Nim

2020-04-05 Thread blueray
I looked at the documentation. It is too hard for me to decode. I googled for 
nimscript tutorial. Yielded nothing. That is why I am here just to have a head 
start. Hopefully this spoon feeding will nourish us to become pro someday. 


Re: How to write shell scripts in Nim

2020-04-05 Thread SolitudeSF
https://nim-lang.github.io/Nim/nimscript.html


Re: Destructor not called for ref object

2020-04-05 Thread Sixte
Honestly I supposed that --gc:arc is the new default gc for Nim 1.2. I'm 
surprised a bit. So, what is the default gc for Nim 1.2 ? 


Re: Having problems with concepts that won't finish compiling

2020-04-05 Thread Araq
Report bugs on github please. Having said that, I think your solution without 
concepts is fine and all you need to do is to use `method` rather `proc` to get 
dynamic dispatch.


Re: How to write shell scripts in Nim

2020-04-05 Thread blueray
I use Linux. So, will the file extension be a factor here?

I have few more questions:

How do we take arguments?

How do we read stdin?

How do we write to stdout?

How do we pipe?

How do we use Linux commands like pwd / ls / cd / sed / grep etc inside the 
script?

Will '#!/usr/bin/env nim' take care of the compilation of the script? 


Re: jester params

2020-04-05 Thread decigs
using wrk benchmark


wrk http://localhost:5000
wrk http://localhost:5000/param


Re: How to write shell scripts in Nim

2020-04-05 Thread Vindaar
Aside from putting that shebang line at the top of the file you want to run as 
a script, the file has to be saved as a NimScript file, namely use a .nims file 
ending.

someScript.nims 


#!/usr/bin/env nim

echo "Hello from NimScript!"
echo defined(NimScript)


Run

and then in your terminal: 


chmod +x someScript.nims
./someScript.nims


Run

and it should run just fine. 


Re: jester params

2020-04-05 Thread decigs
i mean somthing like compiled with d:release : import jester

routes :
get "/@id":

> let val = @let val = "id" resp "hi

get Requests/sec: 16536.58

> * * *
> 
> import jester

routes :


get "/":
resp "hi"

get Requests/sec: 40102.21


How to write shell scripts in Nim

2020-04-05 Thread blueray
I am looking for a bash alternative to write scripts. I came to know that Nim 
can do this.

[https://github.com/nim-lang/Nim/issues/3301](https://github.com/nim-lang/Nim/issues/3301)
 says:

#!/usr/bin/env nim should work now.

I went through Nimscript page, and also some documentations. I could not find 
how to do it.

It would be helpful to have a complete guide on how to write and use the 
script. 


Re: jester params

2020-04-05 Thread geotre
Probably best to open an issue on github ( 
[https://github.com/dom96/jester](https://github.com/dom96/jester)/ ) with an 
example


Having problems with concepts that won't finish compiling

2020-04-05 Thread hugogranstrom
I'm trying to make a generic Spline type for my splines in NumericalNim and the 
behavior I want is that all splines should have a eval proc acting on a single 
float. What I then wanted was to just write one proc that works for all splines 
that instead act on a seq[float] and uses the individual splines' eval procs in 
a for loop. At first I hard coded my splines like this: 


type
  SplineType*[T] = CubicSpline[T] or HermiteSpline[T] # Here
  CubicSpline*[T] = ref object
X: seq[float]
high: int
len: int
coeffs: seq[array[5, float]]
  HermiteSpline*[T] = ref object
X: seq[float]
high: int
len: int
Y: seq[T]
dY: seq[T]

proc eval*[T](spline: CubicSpline[T], x: float): T =
...

proc eval*[T](spline: HermiteSpline[T], x: float): T =
...

proc eval*[T](spline: SplineType[T], x: openArray[float]): seq[T] =
  result = newSeq[T](x.len)
  for i, xi in x:
result[i] = eval(spline, xi)


Run

This compiles and works as expected when I call the eval proc with a 
seq[float]. But I want this to work on any Spline I or the user creates in the 
future so I found concepts which seemed to fit my needs. But I can't get it to 
compile :/ Rather, it never finishes. It feels like it is in some kind of 
infinite loop or something. The way I tried to use concepts was this: 


type
  SplineType*[T] = concept s
s.eval(float) is T


Run

To test this out replace [this 
line](https://github.com/HugoGranstrom/numericalnim/blob/613062201ebd560e42a4cab2337b656a8f9b694e/src/numericalnim/interpolate.nim#L5)
 with the above concept and then run the test file for interpolate.

> I would very much appreciate any help I could get on this matter :-)


jester params

2020-04-05 Thread decigs
hi, i am new here

weird behaviour from jester params are very slow is even slow than database 
query i mean somtheing like @ " param" . any solution to that


Re: Destructor not called for ref object

2020-04-05 Thread lscrd
Note that I have been able to get the right result by compiling your example 
with `--gc:arc`.


Re: WebRTC support 

2020-04-05 Thread enthus1ast
in the browser via js. Natively i'm not aware of any ready to use libraries for 
webrtc. There is status-im/libp2p, though.


Re: Call for testing of arm64, armhf, and i386 snaps of Nim

2020-04-05 Thread adnan

u9898287@pop-os:~/proj/nimbed$ cat nim.nim
echo "hello world"
u9898287@pop-os:~/proj/nimbed$ nim c -r nim.nim
Hint: system [Processing]
Hint: widestrs [Processing]
Hint: io [Processing]
Hint: nim [Processing]
CC: stdlib_io.nim
CC: stdlib_system.nim
CC: nim.nim
/home/u9898287/.cache/nim/nim_d/@mnim.nim.c: In function ‘NimMainModule’:
/home/u9898287/.cache/nim/nim_d/@mnim.nim.c:127:14: warning: passing 
argument 1 of ‘echoBinSafe’ discards ‘const’ qualifier from pointer target type 
[-Wdiscarded-qualifiers]
  127 |  echoBinSafe(TM__2KdnOX4IskX1tJhgQCK1Ag_2, 1);
  |  ^~~~
/home/u9898287/.cache/nim/nim_d/@mnim.nim.c:44:60: note: expected 
‘NimStringDesc **’ {aka ‘struct NimStringDesc **’} but argument is of type 
‘NimStringDesc * const*’ {aka ‘struct NimStringDesc * const*’}
   44 | N_LIB_PRIVATE N_NIMCALL(void, echoBinSafe)(NimStringDesc** args, NI 
argsLen_0);
  |^~~~
/home/u9898287/.cache/nim/nim_d/stdlib_system.nim.c: In function 
‘sysFatal__1rw9bzpRcCrBi6FIqHe7a4wsystem’:
/home/u9898287/.cache/nim/nim_d/stdlib_system.nim.c:4866:1: warning: 
‘noreturn’ function does return
 4866 | }
  | ^
/home/u9898287/.cache/nim/nim_d/stdlib_system.nim.c: In function 
‘sysFatal__loKUBbrfPTCD1cUb5IkxkAsystem’:
/home/u9898287/.cache/nim/nim_d/stdlib_system.nim.c:5335:1: warning: 
‘noreturn’ function does return
 5335 | }
  | ^
/home/u9898287/.cache/nim/nim_d/stdlib_system.nim.c: In function 
‘sysFatal__wxS1DD5S67Tovuyk2fdOLwsystem’:
/home/u9898287/.cache/nim/nim_d/stdlib_system.nim.c:5685:1: warning: 
‘noreturn’ function does return
 5685 | }
  | ^
Hint:  [Link]
Hint: 13891 LOC; 1.484 sec; 21.145MiB peakmem; Debug build; proj: 
/home/u9898287/proj/nimbed/nim.nim; out: /home/u9898287/proj/nimbed/nim 
[SuccessX]
Hint: /home/u9898287/proj/nimbed/nim  [Exec]
hello world


Run

Pop OS 19.10.


Re: Destructor not called for ref object

2020-04-05 Thread juando
Thanks. I will. I didn't know whether it was an issue or me doing something 
wrong.


Re: Destructor not called for ref object

2020-04-05 Thread Araq
Please report issues on github.


WebRTC support 

2020-04-05 Thread BeepBooper
Any suggestions about WebRTC support in Nim?