Re: Render SVG To Display And Update Periodically

2016-10-19 Thread ketmar via Digitalmars-d-learn

On Wednesday, 19 October 2016 at 03:27:10 UTC, Basile B. wrote:
https://github.com/Pctg-x8/nanovg-d, I even think it's been 
announced here last year.


this is wrapper. my thing is complete port.


Re: Render SVG To Display And Update Periodically

2016-10-19 Thread ketmar via Digitalmars-d-learn

On Tuesday, 18 October 2016 at 21:00:12 UTC, Karabuta wrote:

This thing really needs a GitHub repo

never.


Re: Render SVG To Display And Update Periodically

2016-10-19 Thread Jason C. Wells via Digitalmars-d-learn
This is probably a general programming question. I'll follow up 
here since this thread is the inspiration for my current question.


When attempting to compile simpledisplay.d, I get the following:

C:\...\dlang\arsd-master>dmd -Lgdi32.lib -L user32.lib 
simpledisplay.d color.d

OPTLINK (R) for Win32  Release 8.00.17
Copyright (C) Digital Mars 1989-2013  All rights reserved.
http://www.digitalmars.com/ctg/optlink.html
OPTLINK : Warning 9: Unknown Option : NOIGDI32.LIBUSER32.LIB
simpledisplay.obj(simpledisplay)
 Error 42: Symbol Undefined _D9invariant12_d_invariantFC6ObjectZv
simpledisplay.obj(simpledisplay)
** snip **

Interestingly enough, simpledisplay.obj and simpledisplay.exe are 
produced. Aren't errors fatal? The EXE is not a valid win32 
application.


I am used to makefiles. The author doesn't use dub for these 
programs. (dub ~=make?)


gdi32.lib and user32.lib appear in multiple directories.  I added 
"C:\Program Files (x86)\Windows Kits\8.1\Lib\winv6.3\um\x64" to 
%LIB% which seemed sensible to do. I still get the warning:


OPTLINK : Warning 9: Unknown Option : NOIGDI32.LIBUSER32.LIB

So, I'm still figuring out how to set up a compile. I presume 
that dmd is not finding gdi32.lib and user32.lib.  What am I 
missing?


Regards,
Jason C. Wells


Re: Static Length Propagation of Ranges

2016-10-19 Thread Meta via Digitalmars-d-learn

On Wednesday, 19 October 2016 at 20:15:14 UTC, Nordlöw wrote:

On Wednesday, 19 October 2016 at 20:13:15 UTC, Nordlöw wrote:

On Wednesday, 19 October 2016 at 20:10:04 UTC, Meta wrote:

Thanks! Add at

https://github.com/nordlow/phobos-next/blob/master/src/algorithm_ex.d#L2234


I would add this: not sure if it's what you're intending or 
not, but as `in` expands to `const scope` and the semantics 
of scope will probably be changing soon (or more accurately, 
actually implemented), you may want to just go with `const` 
instead.


Ok, thanks. I updated.


BTW: So what about const ref? Will this differ to `in` with 
regards to `scope`? If so will the compiler(s) be smart enough 
to not copy the large stack array when I only qualify with 
`const`?


Well, scope does not imply ref so in both cases a copy will be 
made.


Re: Static Length Propagation of Ranges

2016-10-19 Thread Nordlöw via Digitalmars-d-learn

On Wednesday, 19 October 2016 at 20:13:15 UTC, Nordlöw wrote:

On Wednesday, 19 October 2016 at 20:10:04 UTC, Meta wrote:

Thanks! Add at

https://github.com/nordlow/phobos-next/blob/master/src/algorithm_ex.d#L2234


I would add this: not sure if it's what you're intending or 
not, but as `in` expands to `const scope` and the semantics of 
scope will probably be changing soon (or more accurately, 
actually implemented), you may want to just go with `const` 
instead.


Ok, thanks. I updated.


BTW: So what about const ref? Will this differ to `in` with 
regards to `scope`? If so will the compiler(s) be smart enough to 
not copy the large stack array when I only qualify with `const`?


Re: Static Length Propagation of Ranges

2016-10-19 Thread Nordlöw via Digitalmars-d-learn

On Wednesday, 19 October 2016 at 20:10:04 UTC, Meta wrote:

Thanks! Add at

https://github.com/nordlow/phobos-next/blob/master/src/algorithm_ex.d#L2234


I would add this: not sure if it's what you're intending or 
not, but as `in` expands to `const scope` and the semantics of 
scope will probably be changing soon (or more accurately, 
actually implemented), you may want to just go with `const` 
instead.


Ok, thanks. I updated.


Re: List defined version specifications

2016-10-19 Thread Johan Engelen via Digitalmars-d-learn
On Wednesday, 19 October 2016 at 10:25:51 UTC, Lodovico Giaretta 
wrote:

Hi!

A simple question: is there a way to list all defined version 
specifications?


Perhaps not what you are looking for but on the commandline:


 bin/ldc2 -v test.d

...
predefs   LDC all D_Version2 assert X86_64 D_InlineAsm_X86_64 
D_HardFloat
  LittleEndian D_LP64 D_PIC OSX darwin Posix D_ObjectiveC 
LDC_LLVM_309


-Johan


Re: Static Length Propagation of Ranges

2016-10-19 Thread Meta via Digitalmars-d-learn

On Wednesday, 19 October 2016 at 19:39:46 UTC, Nordlöw wrote:

On Wednesday, 19 October 2016 at 19:01:50 UTC, Meta wrote:

https://goo.gl/t9m3YK

I'm actually pretty impressed that this kind of code can be 
written in D.


Thanks! Add at

https://github.com/nordlow/phobos-next/blob/master/src/algorithm_ex.d#L2234


I would add this: not sure if it's what you're intending or not, 
but as `in` expands to `const scope` and the semantics of scope 
will probably be changing soon (or more accurately, actually 
implemented), you may want to just go with `const` instead.


Re: Static Length Propagation of Ranges

2016-10-19 Thread Nordlöw via Digitalmars-d-learn

On Wednesday, 19 October 2016 at 19:01:50 UTC, Meta wrote:

https://goo.gl/t9m3YK

I'm actually pretty impressed that this kind of code can be 
written in D.


Thanks! Add at

https://github.com/nordlow/phobos-next/blob/master/src/algorithm_ex.d#L2234


Re: Static Length Propagation of Ranges

2016-10-19 Thread Meta via Digitalmars-d-learn

On Wednesday, 19 October 2016 at 18:56:35 UTC, Meta wrote:
Couldn't you do this? Mind you I'm not able to test the code 
right now, but I think it can work with some tweaking.


typeof(fn(E.init))[n] map1(alias fn, E, size_t n)(E[n] 
container)

{
import std.algorithm.iteration : map;
import std.array : array;

typeof(return) sres;
return container[].map!fn.copy(sres[]);
}

@safe pure nothrow unittest
{
   int[42] c;
   //result should be a static array of length 42
   auto result = map1!(_ => _^2)(c);
}


Sorry, that code had a few mistakes. The working code:

import std.algorithm;
import std.range;

typeof(fn(E.init))[n] map1(alias fn, E, size_t n)(E[n] container)
{
import std.algorithm.iteration : map;
import std.array : array;

typeof(return) sres;
container[].map!fn.copy(sres[]);
return sres;
}

void main()
{
   int[42] c;
   //result should be a static array of length 42
   auto result = map1!(_ => _^2)(c);
   assert(is(typeof(result) == typeof(c)));
}

https://goo.gl/t9m3YK

I'm actually pretty impressed that this kind of code can be 
written in D.


Re: Static Length Propagation of Ranges

2016-10-19 Thread Meta via Digitalmars-d-learn

On Wednesday, 19 October 2016 at 13:59:29 UTC, Nordlöw wrote:

Is there a generic way to do


typeof(fn(E.init))[] map1(alias fn, E, size_t n)(E[n] container)
{
  import std.algorithm.iteration : map;
  import std.array : array;
  return container[].map!fn.array;
}

@safe pure nothrow unittest
{
  int[42] c;
  auto result = map1!(_ => _^2)(c);
}


but with propagation of length of return value of `f` to a 
static array instead, without having to specialize each range 
separately?


One less elegant way would be to replace the call to `array` 
with an overload of `std.container.util.make` for static 
arrays, that checks at run-time that the length of the output 
static array matches the length of the input range?


Couldn't you do this? Mind you I'm not able to test the code 
right now, but I think it can work with some tweaking.


typeof(fn(E.init))[n] map1(alias fn, E, size_t n)(E[n] container)
{
import std.algorithm.iteration : map;
import std.array : array;

typeof(return) sres;
return container[].map!fn.copy(sres[]);
}

@safe pure nothrow unittest
{
   int[42] c;
   //result should be a static array of length 42
   auto result = map1!(_ => _^2)(c);
}


Any recent success with SWIG?

2016-10-19 Thread Ryan via Digitalmars-d-learn
I would like to use a library with a c interface from D (gdal 
actually), but I can't find any bindings. I've looked at htod, 
but I also see that gdal has project maintained SWIG interfaces 
and SWIG claims to work with D (both D1 and D2).


So I installed the latest SWIG, but I haven't been able to get 
the SWIG provided D examples to work. Everything compiles, but 
when I run an example I get an Access Violation, it looks like it 
is trying to use a null pointer somewhere.


Has anyone had success with this? Or maybe has SWIG support for D 
fallen behind?


I'm using windows 10 with MSYS2 as my shell environment to 
support the Autotools build files that came with SWIG, which is 
what they recommend on the website for building the examples.


Thanks,


Re: SQLite

2016-10-19 Thread WebFreak001 via Digitalmars-d-learn
On Wednesday, 19 October 2016 at 16:01:37 UTC, Alfred Newman 
wrote:

Hello,

I am trying to handle a SQLite3 table with D. During my 
researchs, I discovered the lib 
https://dlang.org/phobos/etc_c_sqlite3.html.


However, for any reason, there is no code snippets or sample 
codes available there. So, I am stucked.


etc.c.sqlite3 is just a C wrapper, take a look at C examples for 
sqlite3. The D docs don't usually include documentation for 
simple C wrappers.



If you want a proper D library for sqlite3, try d2sqlite3 from 
dub. IMO it's really easy to use and works really well.


Your example using d2sqlite3:

auto stmt = db.prepare("INSERT INTO COMPANY (ID, NAME, AGE, 
ADDRESS, SALARY) VALUES (:id, :name, :age, :address, :salary)");

stmt.inject(1, "Paul", 32, "California", 2);
stmt.inject(2, "Allen", 25, "Texas", 15000);
stmt.inject(3, "Teddy", 23, "Norway", 2);
stmt.inject(4, "Mark", 25, "Rich-Mond", 65000);


Re: std.paralellism.Task value type problems

2016-10-19 Thread Ryan via Digitalmars-d-learn
On Wednesday, 19 October 2016 at 15:28:25 UTC, Benjamin Thaut 
wrote:
I would like to use std.paralellism.TaskPool to schedule 
various tasks I create. The problem however is that these tasks 
don't have a lifetime which is bound to any function scope I 
have. So I need to create a new task object on the heap and 
push it into a array for bookkeeping. The problem however is 
that std.paralellism.Task is a struct and the only way to 
instanciate it is to use std.paralelism.task which returns it 
as a value. I have no idea at the moment how to allocate a 
instance of std.paralellism.Task on the heap. Any suggestions?


Kind Regards
Benjamin Thaut


Try the link below for the documentation. There are 2 versions of 
task, one returns a struct on the stack, the second returns a 
struct on the GC heap.


https://dlang.org/phobos/std_parallelism.html#.task


Re: SQLite

2016-10-19 Thread bachmeier via Digitalmars-d-learn
On Wednesday, 19 October 2016 at 16:01:37 UTC, Alfred Newman 
wrote:

Hello,

I am trying to handle a SQLite3 table with D. During my 
researchs, I discovered the lib 
https://dlang.org/phobos/etc_c_sqlite3.html.


[...]


I've never used SQLite from D, but Adam Ruppe has an interface 
with an example here:

https://github.com/adamdruppe/arsd/blob/master/sqlite.d


SQLite

2016-10-19 Thread Alfred Newman via Digitalmars-d-learn

Hello,

I am trying to handle a SQLite3 table with D. During my 
researchs, I discovered the lib 
https://dlang.org/phobos/etc_c_sqlite3.html.


However, for any reason, there is no code snippets or sample 
codes available there. So, I am stucked.


I have the following sample structure table:
   sql = "INSERT INTO COMPANY (ID,NAME,AGE,ADDRESS,SALARY) "  \
 "VALUES (1, 'Paul', 32, 'California', 2.00 ); " \
 "INSERT INTO COMPANY (ID,NAME,AGE,ADDRESS,SALARY) "  \
 "VALUES (2, 'Allen', 25, 'Texas', 15000.00 ); " \
 "INSERT INTO COMPANY (ID,NAME,AGE,ADDRESS,SALARY)" \
 "VALUES (3, 'Teddy', 23, 'Norway', 2.00 );" \
 "INSERT INTO COMPANY (ID,NAME,AGE,ADDRESS,SALARY)" \
 "VALUES (4, 'Mark', 25, 'Rich-Mond ', 65000.00 );";

Can you pls provide a code snippet or some hints to the following 
job:

- Create a table with the layout above
- Iterate through the records given a basic SELECT WHERE Query

Thanks in advance, AN


std.paralellism.Task value type problems

2016-10-19 Thread Benjamin Thaut via Digitalmars-d-learn
I would like to use std.paralellism.TaskPool to schedule various 
tasks I create. The problem however is that these tasks don't 
have a lifetime which is bound to any function scope I have. So I 
need to create a new task object on the heap and push it into a 
array for bookkeeping. The problem however is that 
std.paralellism.Task is a struct and the only way to instanciate 
it is to use std.paralelism.task which returns it as a value. I 
have no idea at the moment how to allocate a instance of 
std.paralellism.Task on the heap. Any suggestions?


Kind Regards
Benjamin Thaut


Static Length Propagation of Ranges

2016-10-19 Thread Nordlöw via Digitalmars-d-learn

Is there a generic way to do


typeof(fn(E.init))[] map1(alias fn, E, size_t n)(E[n] container)
{
  import std.algorithm.iteration : map;
  import std.array : array;
  return container[].map!fn.array;
}

@safe pure nothrow unittest
{
  int[42] c;
  auto result = map1!(_ => _^2)(c);
}


but with propagation of length of return value of `f` to a static 
array instead, without having to specialize each range separately?


One less elegant way would be to replace the call to `array` with 
an overload of `std.container.util.make` for static arrays, that 
checks at run-time that the length of the output static array 
matches the length of the input range?


Re: List defined version specifications

2016-10-19 Thread Basile B. via Digitalmars-d-learn
On Wednesday, 19 October 2016 at 10:25:51 UTC, Lodovico Giaretta 
wrote:

Hi!

A simple question: is there a way to list all defined version 
specifications?


Something like:

pragma(msg, __traits(allVersions));

Example output (DMD on Ubuntu x64, release build):

[all, D_InlineAsm_X86_64, X86_64, Posix, linux, 
DigitalMars, CRuntime_Glibc, D_Version2, LittleEndian, D_LP64, 
D_HardFloat, D_SIMD, D_NoBoundsChecks, ELFv2]


Thank you in advance.


No, but they can be generated with a string mixin:

static __gshared string[] definedVersions;

enum predefinedVersions = [
"ARM_Thumb","assert","ELFv1","ELFv2",
"HPPA","HPPA64","Posix","unittest",
"Win32","Win64","Windows","X86","X86_64"
];

alias addDefinedVer = (ver) => `version(`~ ver ~`) 
definedVersions~="`

~ ver ~ `";`;

string genDefinedVersions()
{
import std.meta: aliasSeqOf;
import std.range: iota;
string result;
foreach(i; aliasSeqOf!(iota(0, predefinedVersions.length)))
result ~= addDefinedVer(predefinedVersions[i]);
return result;
}

void main()
{
mixin(genDefinedVersions);
}

The problem being that they are not available at compile time.


Re: std.experimental.allocator and GC.addRange

2016-10-19 Thread Basile B. via Digitalmars-d-learn
On Wednesday, 19 October 2016 at 08:34:57 UTC, Benjamin Thaut 
wrote:
Lets assume I have a allocator which cains together multiple 
building blocks from std.experimental.allocator and at the end 
there is a mallocator providing the underlying memory. Now I 
alloacte a type which contains a pointer into GC memory. 
Obviously the memory of the mallocator is not scanned by the GC 
so the pointer might become dangling if the GC chooses to 
collect. I'm wondering if std.experimental.allocator has any 
building blocks or mechanism to automatically call GC.addRange.


Kind Regards
Benjamin Thaut


No and that's a problem. There was a thread the other day about 
that:

https://forum.dlang.org/thread/iubialncuhahhxsfv...@forum.dlang.org

The problem is easily verifiable:
https://issues.dlang.org/show_bug.cgi?id=15790

The solution would be to add a static scanner in make. (the range 
must be added before the call the __ctor).


List defined version specifications

2016-10-19 Thread Lodovico Giaretta via Digitalmars-d-learn

Hi!

A simple question: is there a way to list all defined version 
specifications?


Something like:

pragma(msg, __traits(allVersions));

Example output (DMD on Ubuntu x64, release build):

[all, D_InlineAsm_X86_64, X86_64, Posix, linux, DigitalMars, 
CRuntime_Glibc, D_Version2, LittleEndian, D_LP64, D_HardFloat, 
D_SIMD, D_NoBoundsChecks, ELFv2]


Thank you in advance.


Re: Trying to use Dustmite

2016-10-19 Thread Nordlöw via Digitalmars-d-learn

On Wednesday, 19 October 2016 at 08:50:47 UTC, Nordlöw wrote:
I want to reduce with respect to AssertError thrown in the 
function `err`. BUt when I call


dustmite src 'dmd tester && ./tester | grep -qF "Assertion 
failure"'


Found it. Shall be:

dustmite src 'dmd tester && ./tester 2>&1 | grep -qF 
"Assertion failure"'




Re: From Python to Dlang

2016-10-19 Thread Laeeth Isharc via Digitalmars-d-learn

On Tuesday, 18 October 2016 at 12:03:54 UTC, Alfred Newman wrote:

Hello and greetings,

I'm a brand new D developer coming from Python.

I decided to move to D, mainly because it's a compiled language 
and has a great runtime speed (and I don't feel confortable 
at Cython environment at all). And of course, D has a nice 
community and the language has nice syntax too... and is a joy 
to code with.


However, I have some important production code in Python to 
migrate to D and every help will count !


So, can you pls guys suggest me any resource like "D for a 
Python Developer" or so ? BTW, I just ordered the "D 
Programming Language" book from AA.


Cheers


Welcome.

Bear in mind that you can embed python in your D code using pyd 
if you want to do the port in stages.   You can write D libraries 
for python too - that's a bit fiddlier though,  and docs are a 
bit stale.




Re: Trying to use Dustmite

2016-10-19 Thread Nordlöw via Digitalmars-d-learn

On Wednesday, 19 October 2016 at 08:50:47 UTC, Nordlöw wrote:
object.Exception@dustmite.d(270): Initial test fails (try using 
--no-redirect for details)


When I add the flag --no-redirect to DMD I instead get


Loading src/tester.d
None => core.exception.AssertError@tester.d(3): Assertion failure

??:? _d_assert [0x4276bb]
??:? void tester.__assert(int) [0x4275ec]
??:? void tester.err(int) [0x427562]
??:? _Dmain [0x427599]
??:? 
_D2rt6dmain211_d_run_mainUiPPaPUAAaZiZ6runAllMFZ9__lambda1MFZv 
[0x427b32]
??:? void rt.dmain2._d_run_main(int, char**, extern (C) int 
function(char[][])*).tryExec(scope void delegate()) [0x427a7c]
??:? void rt.dmain2._d_run_main(int, char**, extern (C) int 
function(char[][])*).runAll() [0x427aee]
??:? void rt.dmain2._d_run_main(int, char**, extern (C) int 
function(char[][])*).tryExec(scope void delegate()) [0x427a7c]

??:? _d_run_main [0x4279ed]
??:? main [0x427625]
??:? __libc_start_main [0xa71282f]
No
object.Exception@dustmite.d(270): Initial test fails

??:? _Dmain [0x5c6be8]
??:? 
_D2rt6dmain211_d_run_mainUiPPaPUAAaZiZ6runAllMFZ9__lambda1MFZv 
[0x62544e]
??:? void rt.dmain2._d_run_main(int, char**, extern (C) int 
function(char[][])*).tryExec(scope void delegate()) [0x625398]
??:? void rt.dmain2._d_run_main(int, char**, extern (C) int 
function(char[][])*).runAll() [0x62540a]
??:? void rt.dmain2._d_run_main(int, char**, extern (C) int 
function(char[][])*).tryExec(scope void delegate()) [0x625398]

??:? _d_run_main [0x625309]
??:? main [0x61732d]
??:? __libc_start_main [0xbe15382f]


Which doesn't seem to be what I want, right?


Trying to use Dustmite

2016-10-19 Thread Nordlöw via Digitalmars-d-learn

I'm trying to figure out how to use DustMite.

I have a file `tester.d` in a clean sub-directory `src` containing


void err(int x)
{
assert(x > 0);
}

auto inc(int x)
{
return x + 1;
}

void main(string[] args)
{
auto y = inc(42);
err(10);
err(-10);
}


I want to reduce with respect to AssertError thrown in the 
function `err`. BUt when I call


dustmite src 'dmd tester && ./tester | grep -qF "Assertion 
failure"'


I doesn't progress but instead I get

Loading src/tester.d
None => No
object.Exception@dustmite.d(270): Initial test fails (try using 
--no-redirect for details)


??:? _Dmain [0x5c6be8]
??:? 
_D2rt6dmain211_d_run_mainUiPPaPUAAaZiZ6runAllMFZ9__lambda1MFZv 
[0x62544e]
??:? void rt.dmain2._d_run_main(int, char**, extern (C) int 
function(char[][])*).tryExec(scope void delegate()) [0x625398]
??:? void rt.dmain2._d_run_main(int, char**, extern (C) int 
function(char[][])*).runAll() [0x62540a]
??:? void rt.dmain2._d_run_main(int, char**, extern (C) int 
function(char[][])*).tryExec(scope void delegate()) [0x625398]

??:? _d_run_main [0x625309]
??:? main [0x61732d]
??:? __libc_start_main [0xb429f82f]

What am doing wrong?


Re: weighted round robin

2016-10-19 Thread Marc Schütz via Digitalmars-d-learn

On Tuesday, 18 October 2016 at 16:43:19 UTC, vino wrote:

On Wednesday, 12 October 2016 at 13:44:59 UTC, Erikvv wrote:
In your first post you mention it should be weighted, but I 
see no weights anywhere.


Hi Marc,

  I am at the initial stage of implementing the round robin 
algorithm and still not reached the next part of weighted , if 
you have the code then please send me at present i am trying to 
implement this algorithm in my Server socket program and i 
would require few more days to complete it.


Note that I'm not the one you wrote the above comment ;-)


std.experimental.allocator and GC.addRange

2016-10-19 Thread Benjamin Thaut via Digitalmars-d-learn
Lets assume I have a allocator which cains together multiple 
building blocks from std.experimental.allocator and at the end 
there is a mallocator providing the underlying memory. Now I 
alloacte a type which contains a pointer into GC memory. 
Obviously the memory of the mallocator is not scanned by the GC 
so the pointer might become dangling if the GC chooses to 
collect. I'm wondering if std.experimental.allocator has any 
building blocks or mechanism to automatically call GC.addRange.


Kind Regards
Benjamin Thaut


Re: Visual Studio Linker Problem

2016-10-19 Thread Kagamin via Digitalmars-d-learn

On Tuesday, 18 October 2016 at 18:18:16 UTC, Jason C. Wells wrote:

I'm not sure where LIB was set.


At least in vs2013 it's taken from registry somewhere 
HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Microsoft 
SDKs\Windows\v8.1 (maybe v10 in your case).