Re: Midday Commander [retrofuturistic file manager]

2020-03-29 Thread jlp765
Yes, that got it working, thanks.


Re: Midday Commander [retrofuturistic file manager]

2020-03-28 Thread jlp765
Mine fails on win10 because it can not find the libraylib.dll.


Hint: 
C:\Users\\source\Midday-Commander-master\Midday-Commander-master\test.exe  
[Exec]
could not load: libraylib.dll
Error: execution of an external program failed: 
'C:\Users\\source\Midday-Commander-master\Midday-Commander-master\test.exe '


Run

and my nim is 


Nim Compiler Version 1.0.4 [Windows: amd64]
Compiled at 2020-01-27
Copyright (c) 2006-2019 by Andreas Rumpf

active boot switches: -d:release


Run


Re: Warning: imported and not used

2019-10-12 Thread jlp765
the `-f` command line parameter of Nim will force a rebuilding of ALL modules


Re: distinct types

2019-09-21 Thread jlp765
I could extend the code example of @mratsim

to have


type
  GN* = distinct GoNatural
  GN2* = distinct GoNatural2

var
  myGN: GN = GN(23)


Run

It is probably useful for the base type of you distinct type to be named, for a 
type like 


 type XXX = distinct range[0.0 .. 1.0] of float

Run

Else you will be typing a lot of 


 range[0.0 .. 1.0] of float 

Run

in your code 


Re: Why do I get table implementation instead of the table during compile time?

2019-09-12 Thread jlp765
`debugEcho` is showing you the table repr

Write your own `$` proc for type `Table[string, SqlQuery]` so that

`echo tableSchemas2`

gives you what you want.


Re: New "Learn Nim" page

2019-01-10 Thread jlp765
How about 


var k: array[10, int]

for i in countup(k.low, k.high, 2):
  k[i] = (i + 1) * 10
  echo k[i]



Run


Re: "Nim needs better documentation" - share your thoughts

2019-01-08 Thread jlp765
**Where to from here?**

So, the documentation can be improved, but saying that accomplishes nothing 
beyond the current status quo.

There should be an official Nim **cookbook** (hosted on nim-lang.org ?) which 
contains code examples that can be referenced from the other documentation 
types (help keep the other doco focused), and is easily contributed to via the 
usual git PRs.


Re: "Nim needs better documentation" - share your thoughts

2019-01-04 Thread jlp765
> 10\. Are you willing to help making Nim documentation better? :)

This is half the crux of the matter.

Documentation developed by a committee won't work. It needs **leadership** , 
but with all of us contributing. (Existing standard Nim doco already has 
leadership by @Dom and @Araq)

**Leadership** is needed for:

  * driving improvements in each category of documentation (Tutorial, How-To 
guides, Explanation, Reference, etc)
  * filling in the blanks of a cookbook
  * adding more Rosettacode examples,
  * extending Macro/Template doco (because this is THE most difficult thing to 
document, although @Araq is already leading the way here, it will need a lot of 
work)
  * keeping consistency across various documentation mechanism, as well as 
within the same mechanism (e.g. Standard Library Modules)
  * identifying where documentation should go, reducing double-ups and 
providing cross-references (e.g., between Tutorial, How-To guides, Explanation, 
Reference)



I see leadership as including

  * promoting (asking for help, keeping everyone aware of what is still needed, 
feedback on progress, etc)
  * gate-keeping (arbitrating between different contributions and ideas)
  * maintaining standards




Re: GC is not cleaning up sequence

2018-11-18 Thread jlp765
Have a look at 
[setLen()](https://nim-lang.org/docs/system.html#setLen%2Cseq%5BT%5D%2CNatural) 
and see if setting the length first before garbage collection helps. 


Re: How to call a proc of Base class from a derived class ?

2018-09-17 Thread jlp765
Check out [Getting Started](https://nim-by-example.github.io/oop/)


Re: CreateFont is not working properly

2018-09-16 Thread jlp765
Only guessing, but the low level `createFontHandle` and `createFont` will 
probably take a cstring, so you will need to pass `fontName.cstring`


Re: type Distinct seq[byte] c compiler error

2018-09-09 Thread jlp765
see [Distinct Type](https://nim-lang.org/docs/manual.html#types-distinct-type) 
and the examples that follow.

Explicit type conversions from a distinct type to its base type and vice versa 
are allowed.


Re: How to use com in Nim ?

2018-09-09 Thread jlp765
Not tested, but how about


import winim/com

proc GetExcelObject*(): com =
result = nil   # should be newCom() ??
try:
result = GetObject("", "Excel.Application")
echo result.ActiveWindow.Caption  # Just for testing. Will delete 
later
except :
echo "Excel is not Opened"


Run


Re: wNim - Nim's Windows GUI Framework

2018-09-09 Thread jlp765
If I recall rightly, winim didn't include menubar functionality.

Can you include that in your demo?


Re: Perfecting Nim

2018-04-25 Thread jlp765
Default `Not Nil` (and cleaning up the associated initialization that springs 
from this).

Newbies always get caught with a seq that hasn't been initialised.

If you want `nil`, be explicit about it.


Re: A

2018-01-27 Thread jlp765
Does `debugEcho()` rather than `echo()` help?


Parallel processing helper procs?

2017-12-12 Thread jlp765
Should Nim make it easier to perform the basic use-cases of parallelism (i.e., 
abstract away the looping)?

Three main use-cases that I am thinking of:

  1. Run something in parallel, that may or may not use the loop number
  2. Run something in parallel that returns a result (and probably does use the 
loop number)
  3. Accumulate the result of use-case 2. (i.e., doesn't need to return each 
value, just some resultant single value)



The third use-case would not be implemented, but can be performed by applying 
existing sequence accumulators to use-case 2.

My thoughts were around functional-programming style helper things like the 
following (using for example, 42 as the number of times to run these in 
parallel, i.e. 0..41 ):

  1. `runParallel(42, myProcToRunParallel())`
  2. `var res: seq[int] = runParallel[int](42, someResultReturningProc(.))`



If the "it" style syntax was used, then example 2. would be

2\. `var res: seq[int] = runParallelIt[int](42, someResultReturningProc(.., 
5*it, ))`

where "it" would be 0..41

I don't understand the complexities of parallelism, but would this be possible, 
and would it be a good thing to implement if it is possible?


Re: How to debug a compile error in a template?

2017-12-05 Thread jlp765
In rare situations, I compile with `--verbosity:2` to get more info.

It is not needed here, but worth remembering.


Re: Array indexed by a subrange type

2017-12-02 Thread jlp765
try


type
  Point = range[0 .. 360]
  AllPoints = Point(0) .. Point(360)
  MyArray = array[AllPoints, int]



Re: Tuple unpacking for an array rvalue?

2017-11-30 Thread jlp765
`macros.nim` only defines `ntyArray`

There is also `ntyOpenArray`


Re: Looking for a set that sorts and deduplicates

2017-11-23 Thread jlp765
`CountTable` from the `tables` library can also do this. I don't know how it 
compares speed-wise with the previous solution

The `keys()` iterator will retrieve the sorted numbers (it sorts on insert??), 
and the value is the number of occurrences.

If you already have a sequence of data, you can use the `toCountTable()` proc 
to convert to a CountTable


Re: Nim compiling using MS VS2015 (windows)

2017-11-20 Thread jlp765
(Initially, `cl.exe` isn't in my default path)

If I run `vccexe.exe` I get the following


"C:\Windows\system32\cmd.exe" /C "C:\Program Files (x86)\Microsoft Visual 
Studio 14.0\VC\vcvarsall && SET"
cl.exe
Traceback (most recent call last)
vccexe.nim(61)   vccexe
osproc.nim(581)  startProcess
oserr.nim(113)   raiseOSError
Error: unhandled exception: The system cannot find the file specified.

Additional info: Requested command not found: 'cl.exe'. OS error: [OSError]


However, if I then run the vcvarsall manually from the command prompt, it will 
set the various environment variables

and `cl.exe` can now run from the command line, and NOW `vccexe.exe` works

and `nim c --cc:vcc -r ...` works

Note: the `C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\vcvarsall` 
needs to be quoted to allow for the spaces in the command (yeah, the joys of 
windows)


Re: "timeinterval" type conversion problem

2017-11-16 Thread jlp765
The `TimeInterval` is an offset to a `Time` (obviously). But the Time value is 
a number (usually representing 1970-01-01 onwards in seconds).

Your interval is actually an interval relative to the year 0 A.D. (or a date 
represented in TimeInterval) which if used with a Time value won't give you 
what you want.

So as @dom96 say, you need to convert `TimeInterval` to `TimeInfo` by hand 
(because your interval isn't really an interval).


Re: completely new to programming

2017-11-13 Thread jlp765
**@puwad**, what are you goals in programming?

career, recreational, have something you want to write/build, web development, 
... ?


Re: bytes to hex string

2017-11-13 Thread jlp765
Have a look at `toHex()` in strutils which for anything bigger than a byte, you 
can specify the number of Hex chars to produce, and for a byte will output two 
hex chars.

so maybe as the equivalent of one of your %x try (untested)


"$1$2$3$4" % [toHex(b[0]), toHex(b[1]), toHex(b[2]), toHex(b[3])]


and not sure what the byte order should be 


Re: Help wrapping a C++ module

2017-11-13 Thread jlp765
Might want to flag procs as `cdecl` with `--cdecl`


Re: Help wrapping a C++ module

2017-11-12 Thread jlp765
I submitted an example to the docs, but it is still [a 
PR](https://github.com/nim-lang/Nim/pull/6711), so have a look at the PR.

And try something like the following (and remove the push and pop pragmas):


const
  hdr = "nimfuzz/fts_fuzzy_match.h"
proc fuzzyMatchSimple*(pattern: cstring; str: cstring): bool {.importcpp: 
"fuzzy_match_simple", header: hdr.}


which will add the line


#include "nimfuzz/fts_fuzzy_match.h"

to the `nimcache/test.cpp` file, and map the c++ function `fuzzy_match_simple` 
to the Nim proc `fuzzyMatchSimple()`


Re: Do we really like the ...It templates?

2017-11-11 Thread jlp765
I tried this for benchmarking


import future, sequtils, times, math

const
  LoopCnt = 100_000_000

var
  sq: seq[float] = newSeqWith(LoopCnt, 0.0)
  t0 = epochTime()

proc setupSeq() =
  for i in 0.. pow(x,2))
  echo "closure: ", epochTime() - t0

proc useLoop1() =
  t0 = epochTime()
  for i in 0..

Re: GraphQL?

2017-11-11 Thread jlp765
Regarding [libGraphQlParser](https://github.com/graphql/libgraphqlparser)

The c++ code doesn't wrap code in namespaces, and has very simple high-level 
calls using standard types, so it should work well with c2nim converting c or 
cpp code (untested of course  )

In other words, a great project in which to learn to use c2nim.

EDIT: it is a BSD licence (whatever the implications are for that)


Re: case statement with exceptions

2017-11-10 Thread jlp765
_(slightly off topic by not addressing directly the case statement, but I think 
this is the heart of the issue)_

If there was an "Invalid" role, which is the "else" case, 


type
Roles = enum
invalid,user,catering,manager,sysadmin


then the consumer of this converter could test and handle that themselves via 
the "role" rather than via exception handling.

But which approach is the preferred approach?


Re: floating point output formating

2017-11-05 Thread jlp765
RFC:

if strutils has `toBin()`, `toHex()`, `toOctal()`, `intToStr()`

and from system.nim, the `$` operator is described as

`The stringify operator for an integer argument. Returns x converted to a 
decimal string. $ is Nim's general way of spelling toString.`

why not add a helper proc to strutils as


proc toString(f: SomeReal, prec: int = 8): string =
  result = f.formatFloat(ffDecimal, prec)



Re: Help with parallelizing a loop

2017-11-03 Thread jlp765
Good call.

[The 
doco](https://nim-lang.org/docs/manual.html#parallel-spawn-parallel-statement) 
doesn't use the `sync()`


Re: Help with parallelizing a loop

2017-11-02 Thread jlp765
from [this post](https://forum.nim-lang.org/t/3257/2)

convert something like the following to suit your specific usage


  var
LoopSz = faces.len
res: array[LoopSz, int]
  parallel:
for i in 0..LoopSz-1:
  spawn whateverNeedsDoingInParallel(..., res[i], )
  sync()
  for i in 0..LoopSz-1:
aggResult = doSomeAggregationOfResults(res[i])


Note: currently don't do `0..

Re: my timerpool implementation

2017-10-31 Thread jlp765
What platforms have you tested it on (Linux/MacOs/Win32/Win64/...)?


Re: How to track down missing nimcache/read.o ?

2017-10-28 Thread jlp765
to get more info on each compile step, set the verbosity level

nim c --verbosity:2 


Re: Winim Excel

2017-10-28 Thread jlp765
No experience here,

but if you google "excel vba saveas worksheet" and find some VBA code like


With ActiveWorkbook
.SaveAs "C:\" & .Sheets(1).Name
.Close 0
End With


then you should be able to do something like


obj.activeSheet.saveAs("insert the new name here :-)")
obj.activeSheet.close(0)



Re: Negative generic type matching

2017-10-23 Thread jlp765
Interesting.

`TypeError` doesn't display the msg "Supply only primitive value type"

but if `ObjectAssignmentType` (or some other Error ?) is used, then the message 
is displayed.

Then it comes down to `{.fatal ...}` for compile-time, or `raise newException` 
for run-time


Re: MemFiles on win32 and win64

2017-10-22 Thread jlp765
I have submitted [PR 6534](https://github.com/nim-lang/Nim/pull/6534)

It still has a problem when -d:release is set (at least on win64) because the 
gcc flag -O3 (or -O1 or -O2) causes some sort of mapping failure.


MemFiles on win32 and win64

2017-10-22 Thread jlp765
For memfiles, I believe there are issues on windows platform with trying to 
open a file again after a close.

(just scoping the size of the problem before raising a PR)

**Can someone please test this on win32?** (I know it fails on win64)

Also test **with/without** the compiler setting `-d:release`


import os, memfiles, times

proc runTst1(fname: string) =
  var
file = memfiles.open(fname, fmRead)
i = 0
t0 = epochTime()
  for field in lines(file):
inc(i)
  memfiles.close(file)
  echo "Read lines ", i, " lines! ", epochTime() - t0

proc main() =
  if paramCount() < 1:
quit("ERROR: Please provide a file name for read testing")
  runTst1(paramStr(1))
  runTst1(paramStr(1))
main()




Re: Problem using

2017-10-21 Thread jlp765
try 


var cnt = array[rescnt, int]
parallel:
for i in 0..rescnt-1:
cnt[i] = spawn segcount(i*KB, Kn)
sync()
for i in 0..rescnt-1:
   primecnt += cnt[i].uint



Re: Fastest way to count number of lines

2017-10-20 Thread jlp765
How giant is a "giant text file"?

On my machine a 75M file takes roughly 0.12 sec to count the lines (it is dummy 
data, so not very random).

If GigaBytes in size, then close enough might be good enough 

I didn't see @cblake mention it, but you could count the bytes to read 100 
lines of a big file and use that to estimate the overall number of lines.


Re: Problem using

2017-10-20 Thread jlp765
Try


 for i in 0..rescnt-1:
cnt[i] = spawn segcount(i*KB, Kn)


I think the issue is with `..<`


Re: Fastest way to count number of lines

2017-10-20 Thread jlp765
Even faster (avoiding some string allocations)


import memfiles
for line in memSlices(memfiles.open("foo")):
  inc(i)



Re: Beginner question about nil access

2017-10-20 Thread jlp765
You can't add to a Nil. Firstly initialize it.


proc formatTodos(list: TodoList): string =
  result = ""
  for todo in list.items():
result.add("Todo: " & todo.desc)
result.add("\n")


(insert Viccini saying: "you fell for one of the classic blunders ") 

There was talk of making "seq" and other "array like" variables to auto 
initialise to stop this happening.

Not sure if that will make Nim 1.0 or if it will happen at all (or maybe the 
default "not nil" will be the solution)


Re: Unhandled exception: key not found [KeyError]

2017-10-19 Thread jlp765
Ironically, it is newbies who recognize what is missing.

Add a **PR** as you learn, so others can benefit. It also gets you familiar 
with contributing to Nim.

There have been many suggestions of a **cookbook** for easy cut and paste of 
example code. It hasn't really gained traction, unfortunately.

Another help may be [Rosetta Code](http://rosettacode.org/wiki/Category:Nim) 
(although it doesn't have a lot of json examples)


Re: Pragma for temporarily making strict identifier names?

2017-10-17 Thread jlp765
If the `enum` that defines SDL_QUIT is marked `{.pure.}`, then you have to 
refer to SDL_QUIT as [fully 
qualified](https://nim-lang.org/docs/manual.html#pragmas-pure-pragma)


type
  sdlEv {.pure.} = enum
...
SDL_QUIT,
...

if e.`type` == sdlEv.SDL_QUIT:
SDL_Quit()


It makes your code much more verbose, and may not be style you want your code 
to be, but may be an option.

Also note, in writing this in Nim, should try for [NEP1 coding 
style](https://nim-lang.org/docs/nep1.html) to be consistent with other Nim 
programs (but then not consistent with SDL C   and yes, my example wasn't 
NEP1 either)


Re: Error: expression has no address with openArray

2017-10-13 Thread jlp765
Two ways (at least):

  * make it a `var openArray[]`
  * use `unsafeAddr`




Re: noob confusion stream of conciousness

2017-10-12 Thread jlp765
SqLite is written in C

SqLite therefore uses cstring

Don't bother with seq[char], just use cstring which Nim easily converts to 
string

* * *

Why not copy what db_sqlite has done, and have your own `setupQuery()` which 
calls SqLite's `prepare_v2()`

then you can 


var stmt = setupQuery(db, query, args)
# now step thru the stmt to iterate thru rows of data


but don't let me stop you doing things the hard way 


Re: Extract repetitive unstructured data

2017-10-10 Thread jlp765
Taking a "big picture" approach:

  * If you are going to automate extracting data, you must know the rules that 
define the data "fields" you want to extract, or else no tool will do it for 
you.
  * most tools have some regular expression (RE) capability (not just perl), 
but is an RE the answer to **how do I identify each field?**. If you can 
delineate between fields without using an RE, then that may make your code 
faster, easier to modify, or more readable (but it also may not).
  * Are these files small enough that you can read the whole file into memory 
and process a single string of data, or do you need to process the file 
iteratively (by line, or chuck of data) to save on memory?



If you end up using regular expressions in Nim,
cheat by leveraging what is already done in nimgrep. It is easy to end up 
with RE that is slow in Nim, so if speed is an issue, make sure you benchmark 
it. (The RE isn't slow because it uses PCRE. The reason (I believe) is that it 
is easy (for a newbie) to write code with lots of string allocations that slow 
it down).

The following probably applies to more structured data, but I'll mention it for 
completeness:
@Araq posted about how using [a tool like 
sqlite](https://forum.nim-lang.org/t/2925#18403) can be a good tool if you are 
then manipulating the extracted data.


Re: How to compiles only to C

2017-10-10 Thread jlp765
What about in [Nim Backend 
Integration](https://nim-lang.org/docs/backends.html) ?

The Backend stuff is part of the [Nim Compiler User 
Guide](https://nim-lang.org/docs/nimc.html#backend-language-options)


Re: How to compiles only to C

2017-10-10 Thread jlp765
@rayman22201

> though it's not as prominent as it could be in the docs

Improvement is only a PR away 

You were volunteering to improve this, right?


Re: Error: cannot instantiate: 'T'

2017-10-09 Thread jlp765
Try either (on line 18)


var valueT = test[uint16]()


or


var valueT: uint16 = test[uint16]()


The issue was that `test()` needed to be "told" what the generic type `T` was.


Re: How to write (mostly) "architecture independent" (32/64 bits) code?

2017-10-09 Thread jlp765
  * You know your requirements, so design to that. If you need more than 
high(int64), then use bignum or 
  * The int type is different on different systems, so for your case, don't 
define anything as int. Use specific int sized types like int32 or int64 (or 
bignum, or ...) so that both ends are consistent. That will have speed 
implications (especially if you need bignum)
  * The point is valid that you must have some protocol to talk client/server, 
and it will define the type/size of the binary data you send/receive. Each end 
either converts or uses that data as is.
  * As I understand it, float is consistent across 32/64 bit platforms (maybe 
someone else can clarify that further).



> And it's way simpler to just use uint64 for IDs, than to implement some 
> complicated ID-reusing system.

Nim defaults to using `int` rather than `uint` (change of mindset from C), so 
you should really be using `int64` rather than `uint64`. You can of course use 
uint64, but if so, there are specific uint operators for this (not doing this 
will add even more potential problems).


Re: range - Warning: Cannot prove that 't' is initialized.

2017-10-06 Thread jlp765
> What am I doing wrong?

answer: nothing wrong

but initializing t to zero (0) by default fails, because zero is not in the 
range `'a'.. 'z'`

So you would need to do 


var t: range['a'..'z'] = 'c'


**HOWEVER** the warning still issues when itialized. This is I assume a bug  
(which I will log as an issue)

Edit: [Issue 6474](https://github.com/nim-lang/Nim/issues/6474)


Re: Another reason to deprecate ..

2017-10-05 Thread jlp765
_(there are two things being discussed here: speed and coding style. This post 
has to do with speed differences)_

I have simplified the benchmark I posted before.

The statement

> it's way slower than using explicit numerical bounds

seems VERY difficult to prove, given the following code:


import times, sequtils

const
  LoopCnt = 50_000_000

var
  t0 = epochTime()
  ival = newSeqWith(LoopCnt, 0)

proc p1() =
  t0 = epochTime()
  for j in 0..LoopCnt-1: ival[j] += 1
  echo "Dur (..) : ", 1_000_000*(epochTime() - t0)

proc p2() =
  t0 = epochTime()
  for j in 0..

Re: Another reason to deprecate ..

2017-10-04 Thread jlp765
It should be noted (for completeness) that with a Garbage Collected language, 
the GC can add random timings into the benchmark.

I have also found that when benchmarking, also switch around the order of two 
tests within the code, because that also changes things (can trigger the GC 
differently, and change your results).

That said, here is my little benchmark test, where I call the two tests in 
different orders, and for me I get results where either looping can be faster 
or slower than the other (ie, neither wins outright), but of course, YMMV:


import times

const
  Sz = 1000
  LoopCnt = 500_000

var
  ss1: seq[string] = @["the","rain","in","Spain"]
  si1: seq[int] = @[]
  sf1: seq[float] = @[]
  
  ss2: seq[string] = @["the","rain","in","Spain"]
  si2: seq[int] = @[]
  sf2: seq[float] = @[]
  
  t0 = epochTime()

proc p1() =
  for i in 0..Sz-1:
si1.add(i)
sf1.add(i.float)
  for j in 0 .. LoopCnt-1:
for i in 0..Sz-1:
  si1[i] += 1
  sf1[i] += 1.0
  if i < ss1.len:
ss1[i].add($i)
  echo "Dur (..) : ", epochTime() - t0

proc p2() =
  for i in 0..

Re: Traybar support ?

2017-10-02 Thread jlp765
Shouldn't `nimx` be extended to include this.

My understanding is that `nimx` is a nim gui library, aimed at working on the 
various platforms that Nim supports, using various GUI libs (gtk, sdl. ...)


Re: Using Plotly.js in Nim

2017-09-22 Thread jlp765
This is an excellent example (YMMV).

It raises a question: `Is there a guide for JS development in Nim?`

I looked in the "docs", and "learn" and came across [Nim backend 
integration](https://nim-lang.org/docs/backends.html#nim-code-calling-the-backend-javascript-invocation-example)

Should an FAQ question be added, something like `"How do I use Nim to write a 
JS App"?`


Re: Compile Time Evaluation of Constants From C-Header Files

2017-08-29 Thread jlp765
Have a look at 
[static](https://nim-lang.org/docs/manual.html#statements-and-expressions-static-statement-expression)


static:
  # compile time stuff here



Re: Been away for 9 months. What changed? Need some help to get back on track.

2017-08-28 Thread jlp765
Yeah, I guess I assumed a blog was stories rather than news announcements. 
Other (younger) people probably would not have made that assumption.


Re: Been away for 9 months. What changed? Need some help to get back on track.

2017-08-26 Thread jlp765
> Why isn't this obvious?

Blog didn't register with me as being what I was looking for. 


Re: Been away for 9 months. What changed? Need some help to get back on track.

2017-08-26 Thread jlp765
You should be able to look at the **release notes** from the past releases.

However, the new web site doesn't make that easy to do. The files sit in the 
`web\news` directory of the repository, but how you access them from the web 
site is a mystery to me.


optional int parameters for a proc

2017-08-26 Thread jlp765
**Issue**:
Need `int` type parameters to be optional, and to test whether the 
parameter has been passed to the `proc` or not, BUT the `int` type does not 
allow a `nil` value

So, how do you do the equivalent of


proc xxx(param1: string, param2: int = nil, param3: int = nil)
  if not param2.isNil():
# do something with param2




Re: Nim documentation

2017-08-24 Thread jlp765
On the [Nim docs page](https://nim-lang.org/documentation.html) there is [the 
Searchable Index](https://nim-lang.org/docs/theindex.html)


Re: Gource visualization of the Nim repo history

2017-08-16 Thread jlp765
It shows that @Araq, @Dom96, et. al. have been "busy bees"


Re: OOP Macro section of Nim by Example doesn't seem to work

2017-07-26 Thread jlp765
So someone is doing a pull request to [Nim By 
Example](https://github.com/flaviut/nim-by-example) to fix this, right? 


Re: Having a hard time getting raylib bindings to work

2017-07-24 Thread jlp765
It is not Nim's problem.

>From the `dlopen` doco, you definitely need to either use `ldconfig` or set 
>`LD_LIBRARY_PATH`, because `dlopen` does not check `/usr/local/lib` by default:


   o   (ELF only) If the executable file for the calling program
   contains a DT_RPATH tag, and does not contain a DT_RUNPATH tag,
   then the directories listed in the DT_RPATH tag are searched.
   
   o   If, at the time that the program was started, the environment
   variable LD_LIBRARY_PATH was defined to contain a colon-separated
   list of directories, then these are searched.  (As a security
   measure, this variable is ignored for set-user-ID and set-group-
   ID programs.)
   
   o   (ELF only) If the executable file for the calling program
   contains a DT_RUNPATH tag, then the directories listed in that
   tag are searched.
   
   o   The cache file /etc/ld.so.cache (maintained by ldconfig(8)) is
   checked to see whether it contains an entry for filename.
   
   o   The directories /lib and /usr/lib are searched (in that order).




Re: Documentation contribution

2017-07-23 Thread jlp765
Most System documents have two links following each "section":

_Source_ _Edit_

Clicking on the `Edit` link will create a new Pull Request with the changes you 
make 


Re: In-Memory Database

2017-07-17 Thread jlp765
For SQLite, have a look at the doco 
[db_sqlite](https://nim-lang.org/docs/db_sqlite.html)


import db_sqlite, math

let theDb = open(":memory:",nil,nil,nil)
#
# now do create tables, insert data, select data, 
# using SQL (sqlite flavoured)
#
theDb.exec(sql"Drop table if exists myTestTbl")
theDb.exec(sql("""create table myTestTbl (
 IdINTEGER PRIMARY KEY,
 Name  VARCHAR(50) NOT NULL,
 i INT(11),
 f DECIMAL(18,10))"""))

theDb.exec(sql"BEGIN")
for i in 1..1000:
  theDb.exec(sql"INSERT INTO myTestTbl (name,i,f) VALUES (?,?,?)",
"Item#" & $i, i, sqrt(i.float))
theDb.exec(sql"COMMIT")

for x in theDb.fastRows(sql"select * from myTestTbl"):
  echo x

theDb.close()




Re: vcc and nim vs mingw with vulkan

2017-07-17 Thread jlp765
If you want to try to get vcc working (or define your own msvsc)

  * backup config/nim.cfg
  * edit config/nim.cfg (see below, the existing vcc definitions are for a 
really old compiler)
  * compile as `nim c --cc:vcc file.nim`




# Configuration for the Visual C/C++ compiler:
#vcc.exe = "vccexe.exe"
vcc.exe = "cl.exe"
#vcc.linkerexe = "vccexe.exe"
vcc.linkerexe = "link.exe"

# set the options for specific platforms:
@if i386:
  #vcc.options.always = "--platform:x86 /nologo"
  vcc.options.always = "/nologo"
  #vcc.options.linker = "--platform:x86 /nologo /DEBUG /Zi /F33554432" # 
set the stack vcc.options.linker = "/nologo   /DEBUG /Zi /F33554432" # set the 
stack size to 32 MiB
@elif amd64:
  #vcc.options.always = "--platform:amd64 /nologo"
  vcc.options.always = "/nologo"
  #vcc.options.linker = "--platform:amd64 /nologo /DEBUG /Zi /F33554432" # 
set the stack size to 32 MiB
  vcc.options.linker = "/nologo /DEBUG /Zi /F33554432" # set the stack size 
to 32 MiB
@elif arm:
  vcc.options.always = "--platform:arm /nologo"
  vcc.options.linker = "--platform:arm /nologo /DEBUG /Zi /F33554432" # set 
the stack size to 32 MiB
@else:
  vcc.options.always = "/nologo"
  vcc.options.linker = "/nologo /DEBUG /Zi /F33554432" # set the stack size 
to 32 MiB
@end

vcc.options.debug = "/Zi /FS /Od"
vcc.options.speed = "/O2"
vcc.options.size = "/O1"



Re: Multidimesional Sequences

2017-07-12 Thread jlp765
You can combine the initialization into a single call


import seqUtils

var rows = 2
var cols = 3
var s = newSeqWith(rows, newSeq[string](cols))
for row in 0..

Add Nim to The Computer Language Benchmarks Game?

2017-06-25 Thread jlp765
@def has written [Nim code](https://github.com/def-/nim-benchmarksgame) for 
most of the benchmarks in [The Computer Language Benchmarks 
Game](https://forum.nim-lang.org/benchmarksgame.alioth.debian.org/)

Is it worth everyone checking to see if the code can be improved, and then 
submitting this to the site for addition to the benchmarks?

It is yet another way to "advertise" the language.


date and string slices

2017-06-18 Thread jlp765
Are there any plans for date slices to do something like


 dt in '2017-03-26'..'2017-04-25':  # enumerate days




 dt in '2016-03'..'2017-03':  # enumerate months



I've shown this as strings, but it could be via some helper function, or , 
but the real question is what the nim way to easily work with ranges of dates, 
and be able to step by different amounts (days, months, years, ...)

and similarly, how to do this with date/times, and with just times, 


Re: Python3 extension help needed

2017-05-20 Thread jlp765
Try disabling 
[MarkAndSweep](https://nim-lang.org/docs/system.html#GC_disableMarkAndSweep) 
temporarily.


Re: Surprising floating point equality

2017-05-14 Thread jlp765
 is your friend 

There are a plenty of articles written on floating point comparison.


Re: Can't use proc from other module (written by myself)

2017-05-14 Thread jlp765
Tell it to export asd() by making it asd*()


# module test

proc asd*() =
   echo "hello"



Re: Nim added to the CSV Game benchmark

2017-05-07 Thread jlp765
I question the results when something beats C for speed. Either it is poor C 
code, or there is something weird going on.

Sure, get close or the same, but beat C for speed? You must be doing some ASM 
stuff that is faster than C-generated ASM (good for them, if that is the case).


Re: Fastest way to pack CSV file

2017-04-23 Thread jlp765
`grep` doesn't use the PCRE back-tracking library, so is probably faster than 
implementing it in Nim (which uses PCRE, I believe).

How it would compare with Nim matching strings rather than doing RE matching? I 
would guess grep would be quicker than Nim unless you can avoid string 
allocations in Nim (use all cstring stuff).

You would have to try it and see.

Of course, the grep solution doesn't let you play with the data like the SQL 
solution does 


Re: Fastest way to pack CSV file

2017-04-22 Thread jlp765
Another way would be to have the program produce a grep regular expression that 
is the concatenation of the namefile values into a string

and run a grep command in a shell, like


grep -Ev '^(name1|name2|name3|...),' csvfile > newfile


but then you could do this in nimscript or bash or ... 


Re: getTotalMem reports huge memory total

2017-03-30 Thread jlp765
On Win7 64bit

`nim c -d:release`

  * refc and v2 garbage collector grows to **6,160,384**
  * markAndSweep garbage collector grows to **4,927,488**



`nim c -d:release --memTracker:on`

makes all the three grow to **4,927,488**


Re: cannot assign result of a template with block argument unless surrounded by a block expression

2017-03-24 Thread jlp765
By passing nil (ok, by setting the default to nil), you can get foo3() behaving 
as follows


template foo(_: untyped): auto =
  echo "foo"
  1

template foo2(_: varargs[untyped]): auto =
  echo "foo2"
  block:
discard
  2

template foo3(_: untyped = nil): auto =
  echo "foo3"
  3

let x = (block:
  foo:
discard)

let y = foo2()

let z = foo3()

echo x
echo y
echo z




Re: Endb and compiler localDebugInfo

2017-03-18 Thread jlp765
Wow,

it has taken a while for me to get `endb` modifications done. It is still a 
couple of weeks away, and my coding will not pass the rigorous scrutiny of 
@Araq (and others), so there will be lots of suggested improvements. It has 
been such a lot of back-and-forth with changes over time - and I will probably 
have to consolidate all the changes into one commit (as a separate branch to 
devel so it can be cleaned up easily?)

BUT,

I think it is an improvement (YMMV).

Just to give a bit of a heads up:

The commands have changed slightly: 


- GENERAL -
h, help   display this help message
q, quit   quit the debugger and the program
   repeat the previous debugger command
- EXECUTING ---
Note: precede the command by a number to repeat: 3 s  for three steps
s, step   step into a proc, or to next source code line.
ss, sys   system step into lib/ files (but not lib/system/ 
files).
  ss to delve into lib/ files; f, s or n to return 
to
  the upper level.
n, next   next step, stepping over proc calls.
f, skipcurrentforward steps until the current routine finishes.
c, continue, r, run   continue execution until the next breakpoint (if 
any).
i, ignore continue execution, ignore all breakpoints.
- BREAKPOINTS 
b, break [fromline [toline]] [file]
  set a new breakpoint for line and file.
  If line or file are omitted the current one is 
used.
  [file] does not require the full path or 
extension.
bp, breakpoints   display the entire breakpoint list.
t, toggle  [file]
  enable or disable a breakpoint.
  [file] does not require the full path or 
extension.
fn, filenames list all valid filenames.
- DATA DISPLAY 
e, expand toggle showing values (for local or global 
variables).
  Disable expansion if there are large objects or
  sequences with lots of data (default is off).
g, globals [file] display [to file] global variables,
  which are vars from global scope or an imported 
lib.
l, locals [file]  display [to file] variables in the current stack 
frame.
  (If objects are displayed as [], set the md 
higher)
v, variables [file]   display [to file] the variables registered in the
  current scope, registered while stepping through 
code.
p, printevaluate  and print to screen (if in local 
or
  global list).  Evaluates regardless of the Expand 
setting.
o, out file evaluate  and write it to 
w, where [n]  display the current execution point, and 
optionally
  n lines of preceeding step history.
u, up go up in the call stack (doesn't change the 
execution point).
d, down   go down in the call stack.
bt, backtrace display the entire call stack.
md, maxdisplay   set the display's recursion maximum (0..9).


and the output has changed.

So for test source code (filename = `tst_end.nim`) of 


type
  MyObj = object
s: string
i: int
var
  i = 123
  s = "Hello there"
  m = MyObj(s: "Some string", i: 42)

proc p1(s: var string, i: var int): string =
  var s2 = "Wow"
  var
i2: int
  i2 = 123
  s = "Another string"
  i *= 2
  {.watchpoint: i.}
  result = s & " " & $i & " :: " & $i2 & " " & s2

proc main() =
  var
s = "Greetings"
i: int
  i = 654
  echo p1(m.s, m.i)

when isMainModule:
  main()  # -> Another string 84 :: 123 Wow
  {.watchpoint: m.s .}
  echo i, " ",s   # -> 123 Hello there


which when run normally produces 


Another string 84 :: 123 Wow
123 Hello there


will look this this when stepping through the code (I used 13s to step thirteen 
times repetitively)


endb| tst_endb.nim(6):  tst_endb ->   i = 123
endb| >> 13s
endb| tst_endb.nim(7):  tst_endb ->   s = "Hello there"
endb| tst_endb.nim(8):  tst_endb ->   m = MyObj(s: "Some string", i: 42)
endb| tst_endb.nim(28): tst_endb ->   main()  # -> Another 
string 84 :: 123 Wow
endb| tst_endb.nim(22): main -> s = "Greetings"
endb| tst_endb.nim(24): main ->   i = 654

Re: Tutorial 'Slices' section ^ operator confusion

2017-03-18 Thread jlp765
Will do.

Feature request: Can the tutorials get the same `Edit` link that the docs do, 
for easy PR generation ?


Re: Tutorial 'Slices' section ^ operator confusion

2017-03-18 Thread jlp765
I'll give it a try:

`b[0..^1]` is equivalent to `b[0..b.len-1]`

where ^1 is a "shortcut" that makes it easy to get the last element.

Because the string ends in a period (`b = "Slices are useless."`) then to get 
the portion of the string that is "useless" and replace it with "useful", 
remembering that indices are zero based,


"Slices are useless."
 |  | |
 0 1117   using indices
^19^8^2   using ^ syntax


then

`b[11..^2]` is the portion "useless" and

`b[11..^2] = "useful"` replaces the "useless" portion with "useful"

and hence

`echo b` displays `Slices are useful.`

Note: you could also do it as `b[^8..^2] = "useful"` or as `b[11..b.len-2] = 
"useful"` or as `b[11..

Re: REPL?

2017-02-28 Thread jlp765
The VM doesn't handle all Nim imports (but as per nimscript?).


Integer overflows

2017-02-27 Thread jlp765
I just added a Nim example to 
[RosettaCode](http://rosettacode.org/wiki/Integer_overflow#Nim)

Please check for any errors and suggest improvements.

The page does give a good summary of how Nim handles these edge cases.


Re: REPL?

2017-02-26 Thread jlp765
I have updated the rosettacode page.


Re: REPL?

2017-02-26 Thread jlp765
That functionality is no longer valid.

There are some quasi REPL offerings in nimble (compile and run in the 
background?)


Re: ospaths and NimScript

2017-02-25 Thread jlp765
Oops, didn't read the top of the doco. (didn't realise should import os for 
nim, but ospaths for nimscript).

Make things idiot proof, and the world builds better idiots 


ospaths and NimScript

2017-02-24 Thread jlp765
Why are some of the procs only available to nimscript (getHomeDir, getTempDir, 
etc), but weren't made available in nim?


Re: Nim Syntax ''Skins''

2017-02-22 Thread jlp765
To really mess with our minds, do you also have an optional skin translation 
like
skin (one syntax) `->` AST `->` skin (another syntax)

Secondly, if the intermediate AST syntax was exportable (to file), does that 
give Nim a platform-independent representation (assuming it includes the `when 
defined():` code)?

Thirdly, if this ever became reality, documenting and tracking changes to the 
AST would be very important.


Re: Nim Syntax ''Skins''

2017-02-22 Thread jlp765
So is this:
skin (parsing?) `->` AST intermediate syntax `->` backend (c, c++, ObjC, 
JS, LLVM, ...)


Re: Designing a data frame API

2017-02-20 Thread jlp765
Coming from a Python Pandas perspective,

  * How does DataFrame handle multiple columns of uniform but different types 
(like when a csv file is read that has date, string, int, float,... columns)? 
Currently, it looks like DataFrame only holds a single data type.
  * are there plans for Grouping and aggregated operations?




Re: Nim Advocacy & Promotion Strategies

2017-02-13 Thread jlp765
I haven't seen any **CodeProject** articles on programming in Nim?

Might be a good way to pick up some extra interest.


Re: [RFC]: What's wrong with me or with httpclient :-)

2017-02-10 Thread jlp765
on win7 64 and `Nim Compiler Version 0.16.1 (2017-02-09) [Windows: amd64]`

`TEST[SyncClient]: Processed 1000 requests in 1 seconds!`

or 0 seconds


Re: New in todo.txt

2017-01-28 Thread jlp765
> That's great. What's the syntax for declaring possibly nil types?
> 
> nil ref T.

[Optional Types](https://en.wikipedia.org/wiki/Option_type) suggests another 
alternative of

`T?`

so


  var
v1: int   # not nil
v2: int?  # can be nil
  
  proc xyz[T?](): T? =
result = nil  # <- compile error, since not allowed




Re: Audio/Video File Read/Write Support In NIM

2017-01-24 Thread jlp765
**@videobuddha - what do you currently use (language/libraries/codecs/...)?**

There are a few Nimble packages that wrap external libraries already:

**audio**


  * nim-ao
  * nim-ogg
  * nim-vorbis
  * nim-portaudio
  * nim-sndfile
  * sndhdr
  * nshout
  * taglib
  * sdl2 (for gaming)


**video**


  * nim-ogg
  * vidhdr
  * sdl2 (for gaming)



**A generic video/audio module** that abstracted lower level libraries would be 
of benefit (and is what I understand as being sort of what you are wanting).

* * *

If there was a programming language called `XYZ` that supported direct 
manipulation of video/audio files, then tomorrow, when I write my own unique 
fantasic (in my option) new shiny video/audio file format, then the `XYZ` 
language is obsolete and useless because it doesn't support by new shiny format 
(just trying to highlight that of course it is not the problem of `XYZ` that it 
doesn't support my new format).

So I agree with **@Krux02**

> but (Nim) allows (you) to implement all your dreams that you want to have

It just needs support for more file formats, and a library to abstract the 
access to those libraries.


Re: Audio/Video File Read/Write Support In NIM

2017-01-22 Thread jlp765
Not quite what you are proposing, but there is an `opencv` nimble package (only 
a partial wrapper, IIRC).

I wonder how realistic implementing this would be given the Copyright issues 
with various codecs.


InfoWorld Nim article

2017-01-17 Thread jlp765
Check out this article 
http://www.infoworld.com/article/3157745/application-development/nim-language-draws-from-best-of-python-rust-go-and-lisp.html


Re: Nim VFS (virtual file system)

2017-01-17 Thread jlp765
VFS seems to be at least a two-headed beast:

  * allowing an archive to be treated like a normal file system
  * packaging/bundling a distribution of some kind



For the packaging part, "platform independence" is an important goal.

> (@LibMan) I wonder if we can come up with an intermediate format that stores 
> a Nim project as one binary AST file (for) faster compilation on any platform.

This provides obfuscation as well as "platform independence". (Should the 
packaging always include the AST, and optionally the source code?)


  1   2   >