Re: scope block do not handle failure, but try-catch does

2014-12-14 Thread drug via Digitalmars-d-learn

On 13.12.2014 23:26, Suliman wrote:

I reread docs and understood that scope not for such case.

Next code is do what I need:
try
{
string dbname = config.getKey("dbname");
string dbpass = config.getKey("dbpass");
string dbhost = config.getKey("dbhost");
string dbport = config.getKey("dbport");
}

catch (Exception msg)
{
writeln("Can't parse config: %s", msg.msg);
}

What you need probably is the following:

string dbpass, dbhost, dbport;

{ // This bracket is intended to define new scope
// New if in the current scope from now any failure occurs
// the compiler will call writeln with message
scope(failure) writeln("Can't parse config: %s", msg.msg);

dbname = config.getKey("dbname");
dbpass = config.getKey("dbpass");
dbhost = config.getKey("dbhost");
dbport = config.getKey("dbport");
} // the current scope ends, so if a failure happens later writeln won't 
be called


Re: Fast matrix struct

2014-12-14 Thread anonymous via Digitalmars-d-learn

On Sunday, 14 December 2014 at 22:14:55 UTC, Ryan wrote:
I'm writing a Matrix struct that I plan to use for some number 
crunching, which will be intensive at times. So I want it to be 
fast.


Will I do better by manually managing the memory myself with 
malloc and free in the constructors/destructor or just using 
plain D arrays?


The manual way I could bypass the GC and bounds checks. I don't 
need (or want) any of the fancy appending concatenation and the 
potential slowdowns from the heap allocations that comes with 
the builtin arrays.


But I have to wonder, if I just don't use those features, will 
it be just as fast with the GC (assuming I compile out the 
bounds checks with the -release compiler option)?


Right now my strategy is to malloc one large chunk of memory in 
the constructor (and postblit) and treat the 2-d matrix as a 
1-d array internally. Then just use pointer arithmetic to 
access the elements.


I know the best way to know is just to test. But writing both 
versions would take a LOT of work, and I'm looking for guidance 
about which path will probably be most fruitful.


Thanks,


Just a hint about "a LOT of work":

--
struct Hop {

  version(noGC) // defined with a custom compiler switch 
-version=noGC

private T[] arr;
  else
std.container.Array!T arr;

}
--

The GC-free array already exist in the standard library.


Re: Fastest Way to Append Multiple Elements to an Array

2014-12-14 Thread anonymous via Digitalmars-d-learn

On Sunday, 14 December 2014 at 23:52:15 UTC, zeljkog wrote:

On 15.12.14 00:16, "Nordlöw" wrote:

or some other trick?


void append(T, Args...)(ref T[] arr, Args args){
  arr.length += args.length;
  foreach(i, e; args)
arr[$ - args.length + i] = args[i];
}


void main()
{
  int[] arr = [1, 2, 3, 4, 5];
  arr.append(3, 10, 14);
  writeln(arr);
}

output:
[1, 2, 3, 4, 5, 3, 10, 14]


Maybe *std.array.Appender* should be used in append().

(http://dlang.org/phobos/std_array.html#.Appender)

Even if i often myself feel too lazy to use it and use only the 
concat. op instead.




Re: Fastest Way to Append Multiple Elements to an Array

2014-12-14 Thread zeljkog via Digitalmars-d-learn

On 15.12.14 01:00, "Nordlöw" wrote:

Isn't this algorithm already encoded somewhere in Phobos?

I don't know.


Re: Fastest Way to Append Multiple Elements to an Array

2014-12-14 Thread Nordlöw

On Sunday, 14 December 2014 at 23:52:15 UTC, zeljkog wrote:

void append(T, Args...)(ref T[] arr, Args args){
  arr.length += args.length;
  foreach(i, e; args)
arr[$ - args.length + i] = args[i];
}


Isn't this algorithm already encoded somewhere in Phobos?


Re: Fastest Way to Append Multiple Elements to an Array

2014-12-14 Thread zeljkog via Digitalmars-d-learn
On 15.12.14 00:16, "Nordlöw" wrote:
> or some other trick?

void append(T, Args...)(ref T[] arr, Args args){
  arr.length += args.length;
  foreach(i, e; args)
arr[$ - args.length + i] = args[i];
}


void main()
{
  int[] arr = [1, 2, 3, 4, 5];
  arr.append(3, 10, 14);
  writeln(arr);
}

output:
[1, 2, 3, 4, 5, 3, 10, 14]


Fastest Way to Append Multiple Elements to an Array

2014-12-14 Thread Nordlöw

What's the fastest way to append multiple elements to an array?:

Either

arr ~= e1;
arr ~= e2;
arr ~= e3;

or

arr ~= [e1,e2,e3];

or some other trick?


Fast matrix struct

2014-12-14 Thread Ryan via Digitalmars-d-learn
I'm writing a Matrix struct that I plan to use for some number 
crunching, which will be intensive at times. So I want it to be 
fast.


Will I do better by manually managing the memory myself with 
malloc and free in the constructors/destructor or just using 
plain D arrays?


The manual way I could bypass the GC and bounds checks. I don't 
need (or want) any of the fancy appending concatenation and the 
potential slowdowns from the heap allocations that comes with the 
builtin arrays.


But I have to wonder, if I just don't use those features, will it 
be just as fast with the GC (assuming I compile out the bounds 
checks with the -release compiler option)?


Right now my strategy is to malloc one large chunk of memory in 
the constructor (and postblit) and treat the 2-d matrix as a 1-d 
array internally. Then just use pointer arithmetic to access the 
elements.


I know the best way to know is just to test. But writing both 
versions would take a LOT of work, and I'm looking for guidance 
about which path will probably be most fruitful.


Thanks,


Re: Compact Printing of Tuples

2014-12-14 Thread bearophile via Digitalmars-d-learn

Nordlöw:


Why arent' Tuples defaultly printed as

(1, 2)

instead

Tuple!(int, int)(1, 2)

?

What's the most convenient of tweak this behaviour so I get 
untyped-printing. Is there a function to convert a Tuple to 
into a D parameter tuple?


I'd like a shorter representation of tuples expecially when you 
have an array of them. A single tuple is acceptable to print it 
in the longer current form.


You can open an enhancement request.

Bye,
bearophile


Re: How can I define a label inside a switch?

2014-12-14 Thread ketmar via Digitalmars-d-learn
On Sun, 14 Dec 2014 18:48:15 +
Meta via Digitalmars-d-learn  wrote:

> On Sunday, 14 December 2014 at 18:41:54 UTC, MachineCode wrote:
> > The labels are disabled then? I find that goto case case_value 
> > ugly and prefer goto labelName; but if it's the only way to go 
> > let's do it
> 
> I'm not sure if it's intentionally not supported, or just an 
> oversight. Probably the former, so you should use "goto case". I 
> agree it is annoying having to type out the expression for which 
> case to go to; I can't remember if there was any rationale given 
> for disallowing such a case.

i believe that this is just an oversight. technically that label
belongs to the previous case, so that case is assumed to have some code
after `break` or `goto`, even if there is no real code follows. not
sure if it worth fixing though.


signature.asc
Description: PGP signature


Re: How can I define a label inside a switch?

2014-12-14 Thread Meta via Digitalmars-d-learn

On Sunday, 14 December 2014 at 18:41:54 UTC, MachineCode wrote:
The labels are disabled then? I find that goto case case_value 
ugly and prefer goto labelName; but if it's the only way to go 
let's do it


I'm not sure if it's intentionally not supported, or just an 
oversight. Probably the former, so you should use "goto case". I 
agree it is annoying having to type out the expression for which 
case to go to; I can't remember if there was any rationale given 
for disallowing such a case.


Re: How can I define a label inside a switch?

2014-12-14 Thread MachineCode via Digitalmars-d-learn
On Sunday, 14 December 2014 at 18:27:28 UTC, ketmar via 
Digitalmars-d-learn wrote:

On Sun, 14 Dec 2014 18:24:39 +
MachineCode via Digitalmars-d-learn 


wrote:

I used to do it in C but in D it's giving this compile error 
message:


> switch case fallthrough - 'use goto case;' if intended

Here's the code:

> switch(value) {
> // alof of cases here
> // ...
> white: // regular label
>case 'a': case 'c':
>case 'd': case 'k':
>do_something();
>break;
>  case 'e':
>do_something2();
> break;
>  default: assert(0);
> }

How is it fall through if there's a break? does D switch 
differ from C in any way?
why do you need that? you can use literally what compiler told 
you:

`goto case 'a';` for example.


The labels are disabled then? I find that goto case case_value 
ugly and prefer goto labelName; but if it's the only way to go 
let's do it


Re: How can I define a label inside a switch?

2014-12-14 Thread ketmar via Digitalmars-d-learn
On Sun, 14 Dec 2014 18:24:39 +
MachineCode via Digitalmars-d-learn 
wrote:

> I used to do it in C but in D it's giving this compile error 
> message:
> 
> > switch case fallthrough - 'use goto case;' if intended
> 
> Here's the code:
> 
> > switch(value) {
> > // alof of cases here
> > // ...
> > white: // regular label
> > case 'a': case 'c':
> > case 'd': case 'k':
> > do_something();
> > break;
> >  case 'e':
> >do_something2();
> > break;
> >  default: assert(0);
> > }
> 
> How is it fall through if there's a break? does D switch differ 
> from C in any way?
why do you need that? you can use literally what compiler told you:
`goto case 'a';` for example.


signature.asc
Description: PGP signature


How can I define a label inside a switch?

2014-12-14 Thread MachineCode via Digitalmars-d-learn
I used to do it in C but in D it's giving this compile error 
message:



switch case fallthrough - 'use goto case;' if intended


Here's the code:


switch(value) {
// alof of cases here
// ...
white: // regular label
case 'a': case 'c':
case 'd': case 'k':
do_something();
break;
 case 'e':
   do_something2();
break;
 default: assert(0);
}


How is it fall through if there's a break? does D switch differ 
from C in any way?


DUB not passing "dflags": ["-fPIC"] for gdc, ldmd2 only for DMD

2014-12-14 Thread Gabor Mezo via Digitalmars-d-learn
I'm coming from this thread: 
http://forum.dlang.org/thread/zzjeajhjpzhnvgxqu...@forum.dlang.org


I a nutshell:

- DUB didn't compile my dynamic library project, and Martin 
linked me this issue: 
https://github.com/D-Programming-Language/dub/issues/352. The 
workaround is to put: "dflags": ["-fPIC"] in dub.json
- It builds and works if dub uses DMD. But if I invoke it with 
--complier=gdc, or --compiler=ldmd2, then the linker issue arise 
again, DUB not emit -fPIC I think.


dub.json:

{
"name": "node-d-sample",
"description": "A minimal D application.",
"copyright": "Copyright © 2014, gabor",
"authors": ["gabor"],
"dependencies": {
},
"libs": [ "phobos2" ],
"targetName": "node-d-sample",
"targetPath": "lib",
"targetType": "dynamicLibrary",
"dflags": ["-fPIC"]
}

dub --compiler=gdc:

Performing main compilation...
dub build "node-d-sample" --arch=x86_64 --compiler=gdc
"--build=release"
Building package node-d-sample in
/home/gabor/sandbox/node-d-sample/
Building node-d-sample ~master configuration "library", build
type release.
Running gdc...
/usr/bin/ld:
/usr/lib/gcc/x86_64-linux-gnu/4.9/libgphobos2.a(minfo.o):
relocation R_X86_64_32 against
`_D32TypeInfo_APxS6object10ModuleInfo6__initZ' can not be used
when making a shared object; recompile with -fPIC
/usr/lib/gcc/x86_64-linux-gnu/4.9/libgphobos2.a: error adding
symbols: Bad value
collect2: error: ld returned 1 exit status
FAIL
.dub/build/library-release-linux.posix-x86_64-gdc_2065-33A38D9D3DC714C1501A18C957A2B35B/
node-d-sample dynamicLibrary
Error executing command build: gdc failed with exit code 1.

Exit code 2
Build complete -- 1 error, 0 warnings

dub --compiler=ldmd2:

Performing main compilation...
dub build "node-d-sample" --arch=x86_64 --compiler=ldmd2
"--build=release"
The determined compiler type "ldc" doesn't match the expected
type "dmd". This will probably result in build errors.
Building package node-d-sample in
/home/gabor/sandbox/node-d-sample/
Building node-d-sample ~master configuration "library", build
type release.
Running ldmd2...
/usr/bin/ld:
/home/gabor/dev/ldc2-0.15.0-beta1-linux-x86_64/bin/../lib/libdruntime-ldc.a(eh.o):
relocation R_X86_64_32 against `.rodata..str1' can not be used
when making a shared object; recompile with -fPIC
/home/gabor/dev/ldc2-0.15.0-beta1-linux-x86_64/bin/../lib/libdruntime-ldc.a:
error adding symbols: Bad value
collect2: error: ld returned 1 exit status
Error: /usr/bin/gcc failed with status: 1
FAIL
.dub/build/library-release-linux.posix-x86_64-ldc_2066-212B345732639D80C27025028ED586A2/
node-d-sample dynamicLibrary
Error executing command build: ldmd2 failed with exit code 1.

Exit code 2
Build complete -- 1 error, 0 warnings


Re: Are there any methods like isDestroyed or isDisposed to detect whether some object is destroyed or not?

2014-12-14 Thread via Digitalmars-d-learn

On Sunday, 14 December 2014 at 16:05:13 UTC, Dan Olson wrote:

"Marc "Schütz\""  writes:

On Saturday, 13 December 2014 at 21:20:43 UTC, Andrey 
Derzhavin wrote:


import std.stdio;

class ObjectAType {
   bool ok;
   this() {ok = true;}
}

void main()
{
   auto a = new ObjectAType;
   assert(a.ok);
   destroy(a);
   assert(!a.ok);  // a has been destroyed.
}



This method of detection of collected objects is what I 
needed.

Thanks to everybody for your advise.


Be careful - the memory could still have been reused. For 
example:


assert(a.ok);
destroy(a);
// ... lots of code, maybe multi-threaded ...
assert(!a.ok);// can fail

If between `destroy()` and the second `assert()`, the memory 
of the
object is collected, a new object (of the same or different 
type) can
have been placed there. You will then read an arbitrary piece 
of data

from that new object, which may or may not evaluate to `true`.


In this case the object cannot be collected by gc because there 
is still
a good reference to it (variable 'a').  I agree if delete was 
used

instead of destroy that is would be unsafe.
--
dano


Right, but I see it only as a simplified example. In a real 
program, that reference will most likely be a member of object 
whose destructor is being run.


Re: Are there any methods like isDestroyed or isDisposed to detect whether some object is destroyed or not?

2014-12-14 Thread Dan Olson via Digitalmars-d-learn
"Marc "Schütz\""  writes:

> On Saturday, 13 December 2014 at 21:20:43 UTC, Andrey Derzhavin wrote:
>>>
>>> import std.stdio;
>>>
>>> class ObjectAType {
>>>bool ok;
>>>this() {ok = true;}
>>> }
>>>
>>> void main()
>>> {
>>>auto a = new ObjectAType;
>>>assert(a.ok);
>>>destroy(a);
>>>assert(!a.ok);  // a has been destroyed.
>>> }
>>>
>>
>> This method of detection of collected objects is what I needed.
>> Thanks to everybody for your advise.
>
> Be careful - the memory could still have been reused. For example:
>
> assert(a.ok);
> destroy(a);
> // ... lots of code, maybe multi-threaded ...
> assert(!a.ok);// can fail
>
> If between `destroy()` and the second `assert()`, the memory of the
> object is collected, a new object (of the same or different type) can
> have been placed there. You will then read an arbitrary piece of data
> from that new object, which may or may not evaluate to `true`.

In this case the object cannot be collected by gc because there is still
a good reference to it (variable 'a').  I agree if delete was used
instead of destroy that is would be unsafe.
--
dano


Re: SQLLite driver

2014-12-14 Thread Nicolas Sicard via Digitalmars-d-learn

On Sunday, 14 December 2014 at 13:47:21 UTC, Suliman wrote:

On Sunday, 14 December 2014 at 13:33:27 UTC, Suliman wrote:
There is also a branch named `develop` which at least 
compiles, maybe it is usable.


how to add to dub this branch?


Compiling using dmd...
Linking...
OPTLINK (R) for Win32  Release 8.00.15
Copyright (C) Digital Mars 1989-2013  All rights reserved.
http://www.digitalmars.com/ctg/optlink.html
sqlite3.lib
 Warning 2: File Not Found sqlite3.lib
C:\Users\Dima\AppData\Roaming\dub\packages\d2sqlite3-0.5.2\d2sqlite3.lib(d2sqlit
e3)
 Error 42: Symbol Undefined _sqlite3_close
C:\Users\Dima\AppData\Roaming\dub\packages\d2sqlite3-0.5.2\d2sqlite3.lib(d2sqlit
e3)
 Error 42: Symbol Undefined _sqlite3_enable_shared_cache
C:\Users\Dima\AppData\Roaming\dub\packages\d2sqlite3-0.5.2\d2sqlite3.lib(d2sqlit
e3)
 Error 42: Symbol Undefined _sqlite3_open
C:\Users\Dima\AppData\Roaming\dub\packages\d2sqlite3-0.5.2\d2sqlite3.lib(d2sqlit
e3)
 Error 42: Symbol Undefined _sqlite3_changes
C:\Users\Dima\AppData\Roaming\dub\packages\d2sqlite3-0.5.2\d2sqlite3.lib(d2sqlit
e3)
 Error 42: Symbol Undefined _sqlite3_total_changes
C:\Users\Dima\AppData\Roaming\dub\packages\d2sqlite3-0.5.2\d2sqlite3.lib(d2sqlit
e3)
 Error 42: Symbol Undefined _sqlite3_errcode
C:\Users\Dima\AppData\Roaming\dub\packages\d2sqlite3-0.5.2\d2sqlite3.lib(d2sqlit
e3)
 Error 42: Symbol Undefined _sqlite3_errmsg
C:\Users\Dima\AppData\Roaming\dub\packages\d2sqlite3-0.5.2\d2sqlite3.lib(d2sqlit
e3)
 Error 42: Symbol Undefined _sqlite3_open_v2
C:\Users\Dima\AppData\Roaming\dub\packages\d2sqlite3-0.5.2\d2sqlite3.lib(d2sqlit
e3)
 Error 42: Symbol Undefined _sqlite3_finalize
C:\Users\Dima\AppData\Roaming\dub\packages\d2sqlite3-0.5.2\d2sqlite3.lib(d2sqlit
e3)
 Error 42: Symbol Undefined _sqlite3_bind_parameter_count
C:\Users\Dima\AppData\Roaming\dub\packages\d2sqlite3-0.5.2\d2sqlite3.lib(d2sqlit
e3)
 Error 42: Symbol Undefined _sqlite3_clear_bindings
C:\Users\Dima\AppData\Roaming\dub\packages\d2sqlite3-0.5.2\d2sqlite3.lib(d2sqlit
e3)
 Error 42: Symbol Undefined _sqlite3_reset
C:\Users\Dima\AppData\Roaming\dub\packages\d2sqlite3-0.5.2\d2sqlite3.lib(d2sqlit
e3)
 Error 42: Symbol Undefined _sqlite3_step
C:\Users\Dima\AppData\Roaming\dub\packages\d2sqlite3-0.5.2\d2sqlite3.lib(d2sqlit
e3)
 Error 42: Symbol Undefined _sqlite3_prepare_v2
C:\Users\Dima\AppData\Roaming\dub\packages\d2sqlite3-0.5.2\d2sqlite3.lib(d2sqlit
e3)
 Error 42: Symbol Undefined _sqlite3_column_count
C:\Users\Dima\AppData\Roaming\dub\packages\d2sqlite3-0.5.2\d2sqlite3.lib(d2sqlit
e3)
 Error 42: Symbol Undefined _sqlite3_column_type
C:\Users\Dima\AppData\Roaming\dub\packages\d2sqlite3-0.5.2\d2sqlite3.lib(d2sqlit
e3)
 Error 42: Symbol Undefined _sqlite3_column_name
C:\Users\Dima\AppData\Roaming\dub\packages\d2sqlite3-0.5.2\d2sqlite3.lib(d2sqlit
e3)
 Error 42: Symbol Undefined _sqlite3_column_text
C:\Users\Dima\AppData\Roaming\dub\packages\d2sqlite3-0.5.2\d2sqlite3.lib(d2sqlit
e3)
 Error 42: Symbol Undefined _sqlite3_column_double
C:\Users\Dima\AppData\Roaming\dub\packages\d2sqlite3-0.5.2\d2sqlite3.lib(d2sqlit
e3)
 Error 42: Symbol Undefined _sqlite3_column_int64
C:\Users\Dima\AppData\Roaming\dub\packages\d2sqlite3-0.5.2\d2sqlite3.lib(d2sqlit
e3)
 Error 42: Symbol Undefined _sqlite3_column_blob
C:\Users\Dima\AppData\Roaming\dub\packages\d2sqlite3-0.5.2\d2sqlite3.lib(d2sqlit
e3)
 Error 42: Symbol Undefined _sqlite3_column_bytes
--- errorlevel 22
FAIL 
.dub\build\application-debug-windows-x86-dmd_2066-668EB54A2EBB0CE5C55E2AC62

166BCB8\ seismodownloader executable
Error executing command run: dmd failed with exit code 22.



Warning 2: File Not Found sqlite3.lib


Does it's mean that I should to find this lib and put it in 
package folder?


Yes, you need to link the sqlite3 library, but I'm sorry I can't
help you more, because I've never done this with dub on Windows...

The develop branch is more up-to-date. It should compile with
2.066.1. And the API is supposed to be cleaner. See the examples
to find the changes.

--
Nicolas


Re: dub dustmite

2014-12-14 Thread Vlad Levenfeld via Digitalmars-d-learn

No luck, unfortunately.


Re: SQLLite driver

2014-12-14 Thread Suliman via Digitalmars-d-learn

On Sunday, 14 December 2014 at 13:33:27 UTC, Suliman wrote:
There is also a branch named `develop` which at least 
compiles, maybe it is usable.


how to add to dub this branch?


Compiling using dmd...
Linking...
OPTLINK (R) for Win32  Release 8.00.15
Copyright (C) Digital Mars 1989-2013  All rights reserved.
http://www.digitalmars.com/ctg/optlink.html
sqlite3.lib
 Warning 2: File Not Found sqlite3.lib
C:\Users\Dima\AppData\Roaming\dub\packages\d2sqlite3-0.5.2\d2sqlite3.lib(d2sqlit
e3)
 Error 42: Symbol Undefined _sqlite3_close
C:\Users\Dima\AppData\Roaming\dub\packages\d2sqlite3-0.5.2\d2sqlite3.lib(d2sqlit
e3)
 Error 42: Symbol Undefined _sqlite3_enable_shared_cache
C:\Users\Dima\AppData\Roaming\dub\packages\d2sqlite3-0.5.2\d2sqlite3.lib(d2sqlit
e3)
 Error 42: Symbol Undefined _sqlite3_open
C:\Users\Dima\AppData\Roaming\dub\packages\d2sqlite3-0.5.2\d2sqlite3.lib(d2sqlit
e3)
 Error 42: Symbol Undefined _sqlite3_changes
C:\Users\Dima\AppData\Roaming\dub\packages\d2sqlite3-0.5.2\d2sqlite3.lib(d2sqlit
e3)
 Error 42: Symbol Undefined _sqlite3_total_changes
C:\Users\Dima\AppData\Roaming\dub\packages\d2sqlite3-0.5.2\d2sqlite3.lib(d2sqlit
e3)
 Error 42: Symbol Undefined _sqlite3_errcode
C:\Users\Dima\AppData\Roaming\dub\packages\d2sqlite3-0.5.2\d2sqlite3.lib(d2sqlit
e3)
 Error 42: Symbol Undefined _sqlite3_errmsg
C:\Users\Dima\AppData\Roaming\dub\packages\d2sqlite3-0.5.2\d2sqlite3.lib(d2sqlit
e3)
 Error 42: Symbol Undefined _sqlite3_open_v2
C:\Users\Dima\AppData\Roaming\dub\packages\d2sqlite3-0.5.2\d2sqlite3.lib(d2sqlit
e3)
 Error 42: Symbol Undefined _sqlite3_finalize
C:\Users\Dima\AppData\Roaming\dub\packages\d2sqlite3-0.5.2\d2sqlite3.lib(d2sqlit
e3)
 Error 42: Symbol Undefined _sqlite3_bind_parameter_count
C:\Users\Dima\AppData\Roaming\dub\packages\d2sqlite3-0.5.2\d2sqlite3.lib(d2sqlit
e3)
 Error 42: Symbol Undefined _sqlite3_clear_bindings
C:\Users\Dima\AppData\Roaming\dub\packages\d2sqlite3-0.5.2\d2sqlite3.lib(d2sqlit
e3)
 Error 42: Symbol Undefined _sqlite3_reset
C:\Users\Dima\AppData\Roaming\dub\packages\d2sqlite3-0.5.2\d2sqlite3.lib(d2sqlit
e3)
 Error 42: Symbol Undefined _sqlite3_step
C:\Users\Dima\AppData\Roaming\dub\packages\d2sqlite3-0.5.2\d2sqlite3.lib(d2sqlit
e3)
 Error 42: Symbol Undefined _sqlite3_prepare_v2
C:\Users\Dima\AppData\Roaming\dub\packages\d2sqlite3-0.5.2\d2sqlite3.lib(d2sqlit
e3)
 Error 42: Symbol Undefined _sqlite3_column_count
C:\Users\Dima\AppData\Roaming\dub\packages\d2sqlite3-0.5.2\d2sqlite3.lib(d2sqlit
e3)
 Error 42: Symbol Undefined _sqlite3_column_type
C:\Users\Dima\AppData\Roaming\dub\packages\d2sqlite3-0.5.2\d2sqlite3.lib(d2sqlit
e3)
 Error 42: Symbol Undefined _sqlite3_column_name
C:\Users\Dima\AppData\Roaming\dub\packages\d2sqlite3-0.5.2\d2sqlite3.lib(d2sqlit
e3)
 Error 42: Symbol Undefined _sqlite3_column_text
C:\Users\Dima\AppData\Roaming\dub\packages\d2sqlite3-0.5.2\d2sqlite3.lib(d2sqlit
e3)
 Error 42: Symbol Undefined _sqlite3_column_double
C:\Users\Dima\AppData\Roaming\dub\packages\d2sqlite3-0.5.2\d2sqlite3.lib(d2sqlit
e3)
 Error 42: Symbol Undefined _sqlite3_column_int64
C:\Users\Dima\AppData\Roaming\dub\packages\d2sqlite3-0.5.2\d2sqlite3.lib(d2sqlit
e3)
 Error 42: Symbol Undefined _sqlite3_column_blob
C:\Users\Dima\AppData\Roaming\dub\packages\d2sqlite3-0.5.2\d2sqlite3.lib(d2sqlit
e3)
 Error 42: Symbol Undefined _sqlite3_column_bytes
--- errorlevel 22
FAIL 
.dub\build\application-debug-windows-x86-dmd_2066-668EB54A2EBB0CE5C55E2AC62

166BCB8\ seismodownloader executable
Error executing command run: dmd failed with exit code 22.



Warning 2: File Not Found sqlite3.lib


Does it's mean that I should to find this lib and put it in 
package folder?


Re: SQLLite driver

2014-12-14 Thread Suliman via Digitalmars-d-learn
There is also a branch named `develop` which at least compiles, 
maybe it is usable.


how to add to dub this branch?



Re: Compact Printing of Tuples

2014-12-14 Thread Tobias Pankrath via Digitalmars-d-learn

On Sunday, 14 December 2014 at 11:53:21 UTC, Nordlöw wrote:

Why arent' Tuples defaultly printed as

(1, 2)

instead

Tuple!(int, int)(1, 2)

?

What's the most convenient of tweak this behaviour so I get 
untyped-printing. Is there a function to convert a Tuple to 
into a D parameter tuple?


Tuple.expand?

template Wrapper(Tuple)
{
  static if(isTuple!Tuple)
  {
struct Wrapper(Tuple)
{
Tuple tup;
alias tup this;
// should use a better overload
string toString()
{
  auto app = appender!string();
  app.put("(");
  app.put(to!string(wrapper(tuple[0])));
  foreach(t; tuple.expand[1 .. $])
  {
app.put(", ");
app.put(to!string(wrapper(t
  }
  app.put(")");
  return app.data;
}
}
  }
  else
alias Wrapper = Tuple;
}

auto wrapper(T)(T t) { return Wrapper!T(t); }


Re: All Unordered Pairs of Elements in a Range

2014-12-14 Thread Nordlöw
On Saturday, 13 December 2014 at 23:08:13 UTC, H. S. Teoh via 
Digitalmars-d-learn wrote:

Sounds like:

https://issues.dlang.org/show_bug.cgi?id=6788


T


I guess what's missing here is to make it work for ForwardRanges, 
right?


Compact Printing of Tuples

2014-12-14 Thread Nordlöw

Why arent' Tuples defaultly printed as

(1, 2)

instead

Tuple!(int, int)(1, 2)

?

What's the most convenient of tweak this behaviour so I get 
untyped-printing. Is there a function to convert a Tuple to into 
a D parameter tuple?


Re: SQLLite driver

2014-12-14 Thread via Digitalmars-d-learn
On Sunday, 14 December 2014 at 07:18:46 UTC, Rikki Cattermole 
wrote:

On 14/12/2014 7:35 p.m., Suliman wrote:
Yes I used 2.0.65, but after updating compiler the situation 
did not

resolved...

http://www.everfall.com/paste/id.php?apd0bfs5z4eg


Ah oh, I remember this issue from 2.064 -> 2.065.
Definitely hasn't been upgraded.

https://github.com/biozic/d2sqlite3/issues/6


There is also a branch named `develop` which at least compiles, 
maybe it is usable.


Re: Wrapping multiple extern (C) declarations in a template

2014-12-14 Thread via Digitalmars-d-learn

On Saturday, 13 December 2014 at 19:03:42 UTC, aldanor wrote:
If I now want to have exactly the same module but with all 
function declarations wrapped as described above, I have to 
public import it in another module and then do some template 
magic. However, it wouldn't be possible to retain the same 
function names since they've been imported to the namespace 
(it's then also not possible to extern them as private 
initially since then you won't be able to import/wrap them in a 
different module). Hence the idea of mixing the wrapping 
template in the initial .d header.


You can also use `static import`. That way, the imported symbols 
will only be accessible via their fully-qualified name (e.g. 
`mypackage.mybindings.foo` instead of `foo`) and won't pollute 
the module's namespace.


Re: Are there any methods like isDestroyed or isDisposed to detect whether some object is destroyed or not?

2014-12-14 Thread via Digitalmars-d-learn
On Saturday, 13 December 2014 at 21:20:43 UTC, Andrey Derzhavin 
wrote:


import std.stdio;

class ObjectAType {
   bool ok;
   this() {ok = true;}
}

void main()
{
   auto a = new ObjectAType;
   assert(a.ok);
   destroy(a);
   assert(!a.ok);  // a has been destroyed.
}



This method of detection of collected objects is what I needed.
Thanks to everybody for your advise.


Be careful - the memory could still have been reused. For example:

assert(a.ok);
destroy(a);
// ... lots of code, maybe multi-threaded ...
assert(!a.ok);// can fail

If between `destroy()` and the second `assert()`, the memory of 
the object is collected, a new object (of the same or different 
type) can have been placed there. You will then read an arbitrary 
piece of data from that new object, which may or may not evaluate 
to `true`.


The only case where this can be safe is when you can guarantee 
that there are no new memory allocations between the destruction 
and the test, or that the GC doesn't run. The first condition may 
also be no longer sufficient if the GC starts moving objects 
around (the current one doesn't).


Really, in practice you just cannot safely access GC managed 
resources from inside a GC destructor. You're just asking for 
trouble if you try to hack around that fact.


Re: How to share modules when using -shared?

2014-12-14 Thread MrSmith via Digitalmars-d-learn
On Wednesday, 10 December 2014 at 00:44:41 UTC, Justin Whear 
wrote:
I'm trying to build components that I can dynamically link and 
keep
running into an issue with sharing modules between the host and 
the

pluggable components. Assuming a layout like this:

  host.d  -- loads components at runtime
  a.d -- a module that builds to `a.so`
  b.d -- a module that builds to `b.so`
  common.d

If a.d and b.d both import common.d, all is well.  If host.d 
imports

common.d as well, I get this at runtime:
Fatal Error while loading 'a.so':
The module 'common' is already defined in 'host'.

Test session with sources here: http://pastebin.com/LxsqHhJm

Some of this can be worked around by having host.d use its own 
extern
definitions, but how does this work with interfaces?  My tests 
thus far

have resulted in object invariant failures.


You can have common in separate .so file, or include it in host.


Re: dub dustmite

2014-12-14 Thread MrSmith via Digitalmars-d-learn

On Friday, 12 December 2014 at 04:25:01 UTC, Vlad Levenfeld wrote:
I'm trying to reduce a bug with dub dustmite feature and I must 
be doing it wrong somehow, my regular dub output looks like 
this:


  source/experimental.d(2403): Error: struct 
experimental.Product!(int[], int[]).Product no size yet for 
forward reference

ulong[2]
  source/experimental.d(2454): Error: template instance 
experimental.Product!(int[], int[]) error instantiating
  source/experimental.d(2462):instantiated from here: 
by!(int[], int[])
  FAIL 
.dub/build/application-debug-linux.posix-x86_64-dmd_2067-44246AA2375AB6C7D895600135F734E4/ 
engine_vx executable

  Error executing command run:
  dmd failed with exit code 1.

and then when I run this command

  dub dustmite ~/dubdust --compiler-regex="Product no size yet"

I get

  Executing dustmite...
  None => No
  object.Exception@dustmite.d(243): Initial test fails

It seems like a pretty simple case, I'm not sure what's going 
on.


Try using --combined. This will test all packages at the same 
time if you have dependencies.


Re: std.array oddness

2014-12-14 Thread ketmar via Digitalmars-d-learn
On Sun, 14 Dec 2014 05:15:43 +
earthfront via Digitalmars-d-learn 
wrote:

> On Saturday, 13 December 2014 at 06:40:41 UTC, ketmar via 
> Digitalmars-d-learn wrote:
> > auto names = File("names.txt")
> > .byLine!(char,char)(KeepTerminator.no, ',')
> > .map!"a.idup"
> > .array;
> 
> Awesome. "map!idup" does the trick.
> 
> I had looked at the "byLine" doc before posting, in particular, 
> this line:
> "Note:
> Each front will not persist after popFront is called, so the 
> caller must copy its contents (e.g. by calling to!string) if 
> retention is needed."
> 
> This explains the behavior though I didn't get it then. It's 
> talking about the "range" methods.
> Following the component based stuff from Walter's article can be 
> brain-bendy. And in this case, requires careful reading of the 
> docs.
> But I like it.
it's a matter of time to become used with that "ranges" stuff. but then
you will start seeing ranges everywhere. ;-)


signature.asc
Description: PGP signature