Re: mysql-native v2.1.0-rc1: New features

2018-02-24 Thread Suliman via Digitalmars-d-announce

What about string interpolation like:

conn.exec("INSERT INTO table_name VALUES ({i}, {s})"); ?

Instead of:
conn.exec("INSERT INTO table_name VALUES (?, ?)", i, s);


Re: iota to array

2018-02-24 Thread H. S. Teoh via Digitalmars-d-learn
On Sun, Feb 25, 2018 at 06:22:03AM +, psychoticRabbit via 
Digitalmars-d-learn wrote:
[..]
> printArray(doubleArr); // why is it printing ints instead of doubles??
[...]
> void printArray(T)(const ref T[] a) if (isArray!(T[]))
> {
> foreach(t; a)
> writeln(t);

Try:

writefln("%.3f", t);

instead.


> }
> 
> -


T

-- 
Dogs have owners ... cats have staff. -- Krista Casada


Re: iota to array

2018-02-24 Thread Jonathan M Davis via Digitalmars-d-learn
On Sunday, February 25, 2018 06:22:03 psychoticRabbit via Digitalmars-d-
learn wrote:
> On Sunday, 25 February 2018 at 05:40:19 UTC, Jonathan M Davis
>
> wrote:
> > int[] intArr = iota(1, 11).array();
> >
> > - Jonathan M Davis
>
> thanks!
>
> oh man.  It's so easy to do stuff in D ;-)
>
> But this leads me to a new problem now.
>
> When I run my code below, I get ints printed instead of doubles??
>
> -
> module test;
>
> import std.stdio : writeln;
> import std.traits : isArray;
> import std.array : array;
> import std.range : iota;
>
>
> void main()
> {
>  int[] intArr = iota(1, 11).array(); // 1..10
>  double[] doubleArr = iota(1.0, 11.0).array(); // 1.0..10.0
>  char[] charArr = iota('a', '{').array();  // a..z
>
>  printArray(intArr);
>  printArray(doubleArr); // why is it printing ints instead of
> doubles??
>  printArray(charArr);
> }
>
> void printArray(T)(const ref T[] a) if (isArray!(T[]))
> {
>  foreach(t; a)
>  writeln(t);
> }
>
> -

It's not printing ints. It's printing doubles. It's just that all of the
doubles have nothing to the right of the decimal point, so they don't get
printed with a decimal point. If you did something like start with 1.1, then
you'd see decimal points, because there would be data to the right of the
decimal point. The same thing happens if you do

writeln(1.0);

as opposed to something like

writeln(1.3);

BTW, you can just call writeln on the array directly, and then you'll get
something like

[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]

- Jonathan M Davis



Re: iota to array

2018-02-24 Thread Uknown via Digitalmars-d-learn
On Sunday, 25 February 2018 at 06:22:03 UTC, psychoticRabbit 
wrote:
On Sunday, 25 February 2018 at 05:40:19 UTC, Jonathan M Davis 
wrote:


int[] intArr = iota(1, 11).array();


- Jonathan M Davis


thanks!

oh man.  It's so easy to do stuff in D ;-)

But this leads me to a new problem now.

When I run my code below, I get ints printed instead of 
doubles??


-
module test;

import std.stdio : writeln;
import std.traits : isArray;
import std.array : array;
import std.range : iota;


void main()
{
int[] intArr = iota(1, 11).array(); // 1..10
double[] doubleArr = iota(1.0, 11.0).array(); // 1.0..10.0
char[] charArr = iota('a', '{').array();  // a..z

printArray(intArr);
printArray(doubleArr); // why is it printing ints instead 
of doubles??

printArray(charArr);
}

void printArray(T)(const ref T[] a) if (isArray!(T[]))
{
foreach(t; a)
writeln(t);
}

-


2 Things:
1. You can just use writeln to directly print Arrays. If you want 
a specific format for the array you can use writef/writefln
2. By default, writeln will print [1, 2, 3] when your array 
contains [1.0, 2.0, 3.0], since thats considered neater. You can 
use writefln to address that. You can see this here: 
https://run.dlang.io/is/bNxIsH


You can read more about format strings here:
https://dlang.org/phobos/std_format.html#format-string


Re: iota to array

2018-02-24 Thread psychoticRabbit via Digitalmars-d-learn
On Sunday, 25 February 2018 at 05:40:19 UTC, Jonathan M Davis 
wrote:


int[] intArr = iota(1, 11).array();


- Jonathan M Davis


thanks!

oh man.  It's so easy to do stuff in D ;-)

But this leads me to a new problem now.

When I run my code below, I get ints printed instead of doubles??

-
module test;

import std.stdio : writeln;
import std.traits : isArray;
import std.array : array;
import std.range : iota;


void main()
{
int[] intArr = iota(1, 11).array(); // 1..10
double[] doubleArr = iota(1.0, 11.0).array(); // 1.0..10.0
char[] charArr = iota('a', '{').array();  // a..z

printArray(intArr);
printArray(doubleArr); // why is it printing ints instead of 
doubles??

printArray(charArr);
}

void printArray(T)(const ref T[] a) if (isArray!(T[]))
{
foreach(t; a)
writeln(t);
}

-


Re: How do you get comfortable with Dlang.org's Forum?

2018-02-24 Thread Nick Sabalausky (Abscissa) via Digitalmars-d

On 02/24/2018 08:31 PM, psychoticRabbit wrote:


NNTP is not the future..it's the past.


Uhh, so? This isn't fasion. Merit matters, not fad-compliance.


Re: iota to array

2018-02-24 Thread Seb via Digitalmars-d-learn
On Sunday, 25 February 2018 at 05:24:54 UTC, psychoticRabbit 
wrote:

Hi. Anyone know whether something like this is possible?

I've tried various conversions/casts, but no luck yet.

Essentially, I want to cast the result set of the iota to an 
array, during initialisation of the variable.


You can't do that, because iota is a range and only exists as a 
range struct on the stack.
Think about it as a struct with three variables (start, end, 
stepSize) - not as an array.
Of course, iota is a lot smarter than that as things like  
`10.iota[3 .. $]` or `3 in 10.iota` work, but it's important to 
notice that e.g. `iota[1 .. 2]` just returns a new range object. 
No GC allocation happens here and "the array" never actually 
exists in memory.



no, I don't want to use 'auto'. I want an array object ;-)


This has nothing to do with auto. Auto is just a filler word for 
the compiler that says: "whatever is the type of the declaration, 
use this as the type".

In other words, the compiler does this automatically for you:

---
typeof(10.iota) r = 10.iota;
---

Anyhow it looks like what you want to do is to __allocate__ an 
array. You can do so with std.array.array.


---
import std.array, std.range;
void main()
{
   int[] arr = 10.iota.array;
}
---

https://run.dlang.io/is/kKSzjH

Again, notice that the actual implementation of array is this (in 
the non-optimized case):


---
auto array(Range)(Range r)
{
auto a = appender!(E[])(); // <- allocation happens in the 
appender

foreach (e; r)
a.put(e);
return a.data;
}
---

(without constraints for simplicity)

Of course, Phobos has a more sophisticated version of 
std.array.array, but it's basically like this:


https://github.com/dlang/phobos/blob/master/std/array.d#L97


--
module test;

import std.stdio;
import std.range : iota;

void main()
{
int[] intArr = iota(1, 11); // 1..10
double[] doubleArr = iota(1.0, 11.0); // 1.0..10.0
char[] charArr = iota('a', '{');  // a..z
}
-





Re: iota to array

2018-02-24 Thread Jonathan M Davis via Digitalmars-d-learn
On Sunday, February 25, 2018 05:24:54 psychoticRabbit via Digitalmars-d-
learn wrote:
> Hi. Anyone know whether something like this is possible?
>
> I've tried various conversions/casts, but no luck yet.
>
> Essentially, I want to cast the result set of the iota to an
> array, during initialisation of the variable.
>
> no, I don't want to use 'auto'. I want an array object ;-)
>
> --
> module test;
>
> import std.stdio;
> import std.range : iota;
>
> void main()
> {
>  int[] intArr = iota(1, 11); // 1..10
>  double[] doubleArr = iota(1.0, 11.0); // 1.0..10.0
>  char[] charArr = iota('a', '{');  // a..z
> }
> -

As with any range, you can call std.array.array to convert it to an array.
So, you can have:

int[] intArr = iota(1, 11).array();

or more idiomatically:

auto intArr = iota(1, 11).array();

And auto does _not_ mean that it's not an array. It just means that the type
is inferred, which is pretty much required when you're dealing with ranges,
because the range types get a bit disgusting to type even if they're not
Voldemort types, and if they are Voldemort types, then you pretty much have
to use auto, since you can't refer to the type by name. But in general, even
when you know exactly what the type is, it's good practice to use auto,
since then you're avoiding repeating the type, and it makes it so that you
don't have to change as much code later if the type of the variable changes.
The classic example of where auto should be used when you know exactly what
the type is would be with new. e.g.

MyClass c = new MyClass;

is unnecessarily redundant, and

auto c = new MyClass;

is preferred. In your case, providing the type isn't redundant, since the
type isn't listed on the right-hand side of the expression, but it's still
unnecessary to list the type, so auto is generally preferred - though
obviously, if you really want to be explicit about the types everywhere,
there's nothing stopping you from doing so. It just makes the code harder to
maintain if the type ever changes.

- Jonathan M Davis



iota to array

2018-02-24 Thread psychoticRabbit via Digitalmars-d-learn

Hi. Anyone know whether something like this is possible?

I've tried various conversions/casts, but no luck yet.

Essentially, I want to cast the result set of the iota to an 
array, during initialisation of the variable.


no, I don't want to use 'auto'. I want an array object ;-)

--
module test;

import std.stdio;
import std.range : iota;

void main()
{
int[] intArr = iota(1, 11); // 1..10
double[] doubleArr = iota(1.0, 11.0); // 1.0..10.0
char[] charArr = iota('a', '{');  // a..z
}
-



Re: Aliasing multiple delegates to the same name - very strange behaviour

2018-02-24 Thread Meta via Digitalmars-d

On Sunday, 25 February 2018 at 04:59:58 UTC, Basile B. wrote:

Use templates to prevent implicit conversion:

alias f(T = int) = (T n) => 0;
alias f(T = char) = (T n) => 'a';
alias f(T = bool) = (T n) => false;

Bug report is invalid and can be closed.


Please don't be so hasty. The main focus of that defect is 
whether it is a bug or a feature that the same alias can be 
declared multiple times. I've updated the title to reflect that.


[Issue 18520] Different functions and function/delegate literals can be aliased to the same name

2018-02-24 Thread d-bugmail--- via Digitalmars-d-bugs
https://issues.dlang.org/show_bug.cgi?id=18520

monkeywork...@hotmail.com changed:

   What|Removed |Added

 Status|RESOLVED|REOPENED
 Resolution|INVALID |---
Summary|Different delegates can be  |Different functions and
   |aliased to the same name|function/delegate literals
   |multiple times  |can be aliased to the same
   ||name

--- Comment #3 from monkeywork...@hotmail.com ---
Re-opening this until I can get clarification on whether it is supposed to be
an error or not to define the same alias 3 times. In my second example it
compiles and works correctly, making me think that this is a feature, not a
bug.

--


[Issue 18520] The same alias can be declared multiple times if a function or function/delegate literal is aliased

2018-02-24 Thread d-bugmail--- via Digitalmars-d-bugs
https://issues.dlang.org/show_bug.cgi?id=18520

monkeywork...@hotmail.com changed:

   What|Removed |Added

Summary|Different functions and |The same alias can be
   |function/delegate literals  |declared multiple times if
   |can be aliased to the same  |a function or
   |name|function/delegate literal
   ||is aliased

--


Re: Aliasing multiple delegates to the same name - very strange behaviour

2018-02-24 Thread Meta via Digitalmars-d
On Sunday, 25 February 2018 at 04:47:47 UTC, Nicholas Wilson 
wrote:

On Sunday, 25 February 2018 at 04:06:43 UTC, Meta wrote:
I just filed this bug: 
https://issues.dlang.org/show_bug.cgi?id=18520


Not only does the following code compile and link 
successfully, it prints 0 three times when ran:


alias f = (int n) => 0;
alias f = (char c) => 'a';
alias f = (bool b) => false;

void main()
{
import std.stdio;
writeln(f(int.init));  //Prints 0
writeln(f(char.init)); //Prints 0
writeln(f(bool.init)); //Prints 0
}
[...]
4. Is there any different semantically or mechanically between 
my first and second examples?


Type promotions to int maybe?
Have you tried casting them?


void main()
{
import std.stdio;
writeln(f(cast(int)int.init));
writeln(f(cast(char)char.init));
writeln(f(cast(bool)bool.init));
}


Ah, I tried changing it to the following:

struct NoPromote {}

alias f = (int n) => 0;
alias f = (char c) => 'a';
alias f = (NoPromote np) => NoPromote();

void main()
{
import std.stdio;
writeln(f(int.init));   //Prints 0
writeln(f(char.init));  //Prints 0
writeln(f(NoPromote.init)); //Prints 0
}

And I get "Error: function literal __lambda5 (int n) is not 
callable using argument types (NoPromote)". It was already 
apparent from the fact that the program printed 0 each time, but 
this confirms that the first function literal is the only one 
that _really_ gets aliased to f. Actually, this is unnecessary, 
because if I just change the order and move the bool function up 
to be the first, I get "Error: function literal __lambda4 (bool 
b) is not callable using argument types (char)".


Did I mention how much I hate the fact that char and bool 
implicitly convert to int?





[Issue 18520] Different delegates can be aliased to the same name multiple times

2018-02-24 Thread d-bugmail--- via Digitalmars-d-bugs
https://issues.dlang.org/show_bug.cgi?id=18520

Basile B.  changed:

   What|Removed |Added

 Status|NEW |RESOLVED
 Resolution|--- |INVALID

--- Comment #2 from Basile B.  ---
This due to implicit conversion which has for effect to make the first overload
always working.

a way to overcome this:

alias f(T = int) = (T n) => 0;
alias f(T = char) = (T n) => 'a';
alias f(T = bool) = (T n) => false;

--


Re: Aliasing multiple delegates to the same name - very strange behaviour

2018-02-24 Thread Basile B. via Digitalmars-d

On Sunday, 25 February 2018 at 04:06:43 UTC, Meta wrote:
I just filed this bug: 
https://issues.dlang.org/show_bug.cgi?id=18520


Not only does the following code compile and link successfully, 
it prints 0 three times when ran:


alias f = (int n) => 0;
alias f = (char c) => 'a';
alias f = (bool b) => false;

void main()
{
import std.stdio;
writeln(f(int.init));  //Prints 0
writeln(f(char.init)); //Prints 0
writeln(f(bool.init)); //Prints 0
}

However, when I change the code to the following, it works as 
one could reasonably expect, given the circumstances:


int  f1(int n)  { return 0; }
char f2(char c) { return 'a'; }
bool f3(bool b) { return false; }

alias f = f1;
alias f = f2;
alias f = f3;

void main()
{
import std.stdio;
writeln(f(int.init));  //Prints 0
writeln(f(char.init)); //Prints 'a'
writeln(f(bool.init)); //Prints false
}

I've got some questions:

1. Which is the intended behaviour? Should this code fail to 
compile and there's a bug with aliases, or should this code 
compile and my first example work correctly, but there is 
currently a bug where this feature interacts badly with 
function/delegate literals?


2. If the answer to 1 is "this could should compile and work 
correctly", in what cases does D allow multiple aliases with 
the same name to be defined, as in my first and second example 
(which compile without issue)?


3. Is this related to overload sets in some way?

4. Is there any different semantically or mechanically between 
my first and second examples?


Use templates to prevent implicit conversion:

alias f(T = int) = (T n) => 0;
alias f(T = char) = (T n) => 'a';
alias f(T = bool) = (T n) => false;

Bug report is invalid and can be closed.


Re: Aliasing multiple delegates to the same name - very strange behaviour

2018-02-24 Thread Nicholas Wilson via Digitalmars-d

On Sunday, 25 February 2018 at 04:06:43 UTC, Meta wrote:
I just filed this bug: 
https://issues.dlang.org/show_bug.cgi?id=18520


Not only does the following code compile and link successfully, 
it prints 0 three times when ran:


alias f = (int n) => 0;
alias f = (char c) => 'a';
alias f = (bool b) => false;

void main()
{
import std.stdio;
writeln(f(int.init));  //Prints 0
writeln(f(char.init)); //Prints 0
writeln(f(bool.init)); //Prints 0
}
[...]
4. Is there any different semantically or mechanically between 
my first and second examples?


Type promotions to int maybe?
Have you tried casting them?


void main()
{
import std.stdio;
writeln(f(cast(int)int.init));
writeln(f(cast(char)char.init));
writeln(f(cast(bool)bool.init));
}


Re: Template Constraints

2018-02-24 Thread Jonathan via Digitalmars-d-learn
On Saturday, 24 February 2018 at 03:04:07 UTC, Adam D. Ruppe 
wrote:

On Saturday, 24 February 2018 at 02:54:13 UTC, Jonathan wrote:
I am having trouble finding many useful explanations of using 
template constraints beyond basic usage.


The constraint is just like static if as to what it allows 
inside, so you can check almost anything in there.


Like for the cast, you might do

void name(T)(T t) if(__traits(compiles, cast(int) t) {}

just seeing it the cast compiles.

You might also do

if(is(T : int))

which asks if T is implicitly convertible to int. But since you 
want explicit cast, the compiles is prolly the way to go.


is: https://dlang.org/spec/expression.html#IsExpression
compiles: https://dlang.org/spec/traits.html#compiles


Thanks, this was just what I needed to know.


Aliasing multiple delegates to the same name - very strange behaviour

2018-02-24 Thread Meta via Digitalmars-d
I just filed this bug: 
https://issues.dlang.org/show_bug.cgi?id=18520


Not only does the following code compile and link successfully, 
it prints 0 three times when ran:


alias f = (int n) => 0;
alias f = (char c) => 'a';
alias f = (bool b) => false;

void main()
{
import std.stdio;
writeln(f(int.init));  //Prints 0
writeln(f(char.init)); //Prints 0
writeln(f(bool.init)); //Prints 0
}

However, when I change the code to the following, it works as one 
could reasonably expect, given the circumstances:


int  f1(int n)  { return 0; }
char f2(char c) { return 'a'; }
bool f3(bool b) { return false; }

alias f = f1;
alias f = f2;
alias f = f3;

void main()
{
import std.stdio;
writeln(f(int.init));  //Prints 0
writeln(f(char.init)); //Prints 'a'
writeln(f(bool.init)); //Prints false
}

I've got some questions:

1. Which is the intended behaviour? Should this code fail to 
compile and there's a bug with aliases, or should this code 
compile and my first example work correctly, but there is 
currently a bug where this feature interacts badly with 
function/delegate literals?


2. If the answer to 1 is "this could should compile and work 
correctly", in what cases does D allow multiple aliases with the 
same name to be defined, as in my first and second example (which 
compile without issue)?


3. Is this related to overload sets in some way?

4. Is there any different semantically or mechanically between my 
first and second examples?


[Issue 18520] Different delegates can be aliased to the same name multiple times

2018-02-24 Thread d-bugmail--- via Digitalmars-d-bugs
https://issues.dlang.org/show_bug.cgi?id=18520

--- Comment #1 from monkeywork...@hotmail.com ---
The code seemingly functions correctly when I change it as follows:

int  f1(int n)  { return 0; }
char f2(char c) { return 'a'; }
bool f3(bool b) { return false; }

alias f = f1;
alias f = f2;
alias f = f3;

void main()
{   
import std.stdio;
writeln(f(int.init));  //Prints 0
writeln(f(char.init)); //Prints 'a'
writeln(f(bool.init)); //Prints false
}

--


[Issue 18520] New: Different delegates can be aliased to the same name multiple times

2018-02-24 Thread d-bugmail--- via Digitalmars-d-bugs
https://issues.dlang.org/show_bug.cgi?id=18520

  Issue ID: 18520
   Summary: Different delegates can be aliased to the same name
multiple times
   Product: D
   Version: D2
  Hardware: All
OS: All
Status: NEW
  Severity: normal
  Priority: P1
 Component: dmd
  Assignee: nob...@puremagic.com
  Reporter: monkeywork...@hotmail.com

The following code compiles with DMD 2.070.2 and prints 0 three times:

alias f = (int n) => 0;
alias f = (char c) => 'a';
alias f = (bool b) => false;

void main()
{
import std.stdio;
writeln(f(int.init));  //Prints 0
writeln(f(char.init)); //Prints 0
writeln(f(bool.init)); //Prints 0
}

It looks like the int overload is getting called each time.

--


Re: countUntil to print all the index of a given string.

2018-02-24 Thread Jonathan M Davis via Digitalmars-d-learn
On Sunday, February 25, 2018 02:58:33 Seb via Digitalmars-d-learn wrote:
> On Sunday, 25 February 2018 at 02:37:00 UTC, Jonathan M Davis
>
> wrote:
> > If any exceptions could be thrown, then a lazy solution can't
> > be @nogc (something that's often the case with strings thanks
> > to auto-decoding and UTFExceptions), and a solution could be
> > eager without allocating if the result doesn't require any
> > allocation.
>
> FYI -dip1008 is a thing now and part of 2.079.
> See also:
>
> https://dlang.org/changelog/pending.html#dip1008
> https://run.dlang.io/is/clNX6G
> https://github.com/dlang/DIPs/blob/master/DIPs/DIP1008.md

That will help eventually, but it requires a compiler flag, so it's really
not going to help for code in general right now, and the fact that that DIP
does nothing to solve the problem of how to create exception messages
without allocating them on the GC heap means that exceptions in general are
still frequently going to result in allocations unless you jump through
several hoops to be able to create an exception message that's in a static
array or malloc-ed or something. So, I don't know how much it's going to
help in practice outside of code where the programmer is absolutely
determined to have no GC allocations.

> > Also, you could have a lazy range that involves a lambda that
> > allocates a closure.
>
> Of course, or a @nogc range that allocates with malloc or eagerly
> steps through the entire range.
>
> Anyhow I just mentioned it because it's the best form of
> automatic checking that we have (what the OP was asking for) and
> in many cases when an algorithm can't be @nogc it does allocate
> somewhere which is a red flag.

Yeah. There does tend to be a correlation between @nogc and whether a range
is lazy, but it's not guaranteed, so I'm inclined to think that it's a poor
idea to rely on it and that it's just ultimately better to look at the
documentation or even the code.

- Jonathan M Davis



Re: Postgres and other database interfaces

2018-02-24 Thread Seb via Digitalmars-d

On Saturday, 24 February 2018 at 23:17:46 UTC, Denis F wrote:

On Saturday, 24 February 2018 at 22:24:58 UTC, bachmeier wrote:
3. Looking at the source code, you have already written a 
bunch of comments. Those are documentation once you turn them 
into html.


I'm for the comments to be documentation. But I am paranoid and 
do not like that the  documentation generator should be granted 
write access to the repository.


If you talk about using Travis to build the documentation and 
push to gh-pages like e.g explained here [1]. There are solutions:


a) Use branch protection (GH offers this. No one can force push 
something to protected branches)
b) Use a dedicated bot account (if you are worried about leaking 
the credentials)

c) Use a dedicated *-docs repo to which Travis pushes
d) Push to a different location (e.g. S3, netlify
...

[1] 
https://forum.dlang.org/post/tkcndtapfypabsncx...@forum.dlang.org


Re: compilers w/ different language features: version block

2018-02-24 Thread Seb via Digitalmars-d-learn

On Sunday, 25 February 2018 at 01:19:02 UTC, Seb wrote:

On Sunday, 25 February 2018 at 00:42:20 UTC, Seb wrote:

On Sunday, 25 February 2018 at 00:36:16 UTC, kdevel wrote:

   [...]


Are you looking for something like this?

---
static if (__traits(compiles, () { static foreach (i; [0]){} 
}))

version = supportsStaticForeach;

void main()
{
version(supportsStaticForeach) {
   pragma(msg, "Yay, your compiler is new enough.");
}
}
---


https://run.dlang.io/is/PZN5Nv


[...]


Don't support GDC (or only GDC-master)?


Ah sorry I replied too fast. Yeah `mixin` is the only way to 
workaround this if you really, really have to support GDC.


BTW there's one trick that might work on your setup - conditional 
imports:


---
static if (__traits(compiles, () { static foreach (i; [0]){} }))
version = supportsStaticForeach;

void main()
{
version(supportsStaticForeach) {
   import compat.staticforeach;
} else {
   import compat.no_staticforeach;
}
}
---

With rdmd this should work out of the box - with DUB you would 
need to tweak the source paths. DUB allows all options to be 
compiler-specific, so e.g. something like this for a dub.sdl 
could work:


---
sourcePaths-dmd "compat/staticforeach"
sourcePaths-ldc "compat/staticforeach"
sourcePaths-gdc "compat/no_staticforeach"
---


Re: Postgres and other database interfaces

2018-02-24 Thread Joe via Digitalmars-d

On Saturday, 24 February 2018 at 23:04:39 UTC, Denis F wrote:
If anyone really want to impliment your idea, at my first 
glance at the PEP 249 I had a feeling that this is work for 
time less than a 1-2 weeks. It can be a simple wrapper over 
dpq2, mysql-native, sqlite3, etc.


I'm not saying that anyone should implement something like PEP 
249, particularly *not* as a wrapper over those libraries. My 
point is that if the implementors of dpq2, mysql-native, etc., 
could "get together" (at DConf, in forums, by email) and discuss 
their interfaces, perhaps they could agree on a set of D database 
interface classes and then each would work towards that common 
set. That's more or less what the Python DB-SIG did. Then every 
library would benefit because, for one, the common set can be 
documented just once. Also, if it's a sufficiently reasonable 
spec, the libraries that don't move towards it should see less 
adoption because, unless the divergent library has a 
significantly enhanced interface, developers will shy away from 
having to learn a different one.


It's the same concept as the SQL (and other) Standards. There may 
be variances between implementations but no one has implemented a 
RETRIEVE or PROJECT statement in lieu of a SELECT statement (and 
note there *were* relational systems that used the former).


Joe


Re: countUntil to print all the index of a given string.

2018-02-24 Thread Seb via Digitalmars-d-learn
On Sunday, 25 February 2018 at 02:37:00 UTC, Jonathan M Davis 
wrote:
If any exceptions could be thrown, then a lazy solution can't 
be @nogc (something that's often the case with strings thanks 
to auto-decoding and UTFExceptions), and a solution could be 
eager without allocating if the result doesn't require any 
allocation.


FYI -dip1008 is a thing now and part of 2.079.
See also:

https://dlang.org/changelog/pending.html#dip1008
https://run.dlang.io/is/clNX6G
https://github.com/dlang/DIPs/blob/master/DIPs/DIP1008.md


Also, you could have a lazy range that involves a lambda that 
allocates a closure.


Of course, or a @nogc range that allocates with malloc or eagerly 
steps through the entire range.


Anyhow I just mentioned it because it's the best form of 
automatic checking that we have (what the OP was asking for) and 
in many cases when an algorithm can't be @nogc it does allocate 
somewhere which is a red flag.


Re: countUntil to print all the index of a given string.

2018-02-24 Thread Jonathan M Davis via Digitalmars-d-learn
On Sunday, February 25, 2018 01:49:05 Seb via Digitalmars-d-learn wrote:
> On Tuesday, 20 February 2018 at 08:44:37 UTC, aberba wrote:
> > On Sunday, 18 February 2018 at 15:23:14 UTC, Cym13 wrote:
> >> On Sunday, 18 February 2018 at 14:48:59 UTC, Cym13 wrote:
> >>> [...]
> >>
> >> Just thought of a much better/simpler solution for that last
> >> case that also doesn't force you to read all data (which might
> >>
> >> be impossible when dealing with infinite ranges):
> >> import std.range;
> >> import std.algorithm;
> >>
> >> a[]
> >>
> >>  .enumerate   // get tuples (index,
> >>
> >> value)
> >>
> >>  .filter!(t => t[1] == "Test2")   // keep only if value ==
> >>
> >> "Test2"
> >>
> >>  .map!(t => t[0]) // keep only the index
> >>
> >> part
> >>
> >>  .writeln;
> >>
> >> Completely lazy.
> >
> > How does one detect an operation as lazy or not?  Is the some
> > compile-time or runtime check for that?
> >
> > My guess is by referring to the docs function signature.
>
> While it's not a replacement for checking the code manually,
> @nogc helps a lot:

That doesn't actually tell you whether the range is lazy. It just tells you
whether any allocations may occur. If any exceptions could be thrown, then a
lazy solution can't be @nogc (something that's often the case with strings
thanks to auto-decoding and UTFExceptions), and a solution could be eager
without allocating if the result doesn't require any allocation. Also, you
could have a lazy range that involves a lambda that allocates a closure.

So, yeah, a lot of the time, @nogc means that the range is lazy, but it
doesn't guarantee it, and not being able to be @nogc doesn't mean that it's
eager. So, I'd argue that while @nogc gives you a clue, it's ultimately a
pretty poor way to try and figure out whether a range is lazy or not. All it
really tells you is whether it's guaranteed that no allocations will occur
on the GC heap.

- Jonathan M Davis



Re: Double link list

2018-02-24 Thread Joel via Digitalmars-d-learn

On Saturday, 24 February 2018 at 09:48:13 UTC, Joel wrote:
I'm trying some code for practice, but it isn't working 
properly - it prints just one number when printing in reverse.


[snip]

Thanks guys. And I got it working with 'if (head is tail)' etc.



Re: NNTP client configuration

2018-02-24 Thread Walter Bright via Digitalmars-d

On 2/24/2018 1:58 AM, Jonathan M Davis wrote:

LOL. The cost of going to dconf when it's in Germany and you live in the US
isn't exactly small, and for some folks, it's not easy to get away even if
they can afford the cost. Of course, when it's in the US, then the folks in
Europe would have the same problem, so someone is always going to lose out
in that regard. Every year that it's been in Germany, I've at least briefly
considered not going due to the cost, but I hate the idea of missing dconf,
so I've made it work one way or another.


And we're glad to see you every year!


Re: countUntil to print all the index of a given string.

2018-02-24 Thread Seb via Digitalmars-d-learn

On Tuesday, 20 February 2018 at 08:44:37 UTC, aberba wrote:

On Sunday, 18 February 2018 at 15:23:14 UTC, Cym13 wrote:

On Sunday, 18 February 2018 at 14:48:59 UTC, Cym13 wrote:

[...]


Just thought of a much better/simpler solution for that last 
case that also doesn't force you to read all data (which might 
be impossible when dealing with infinite ranges):


import std.range;
import std.algorithm;

a[]
 .enumerate   // get tuples (index, 
value)
 .filter!(t => t[1] == "Test2")   // keep only if value == 
"Test2"
 .map!(t => t[0]) // keep only the index 
part

 .writeln;

Completely lazy.


How does one detect an operation as lazy or not?  Is the some 
compile-time or runtime check for that?


My guess is by referring to the docs function signature.


While it's not a replacement for checking the code manually, 
@nogc helps a lot:



---
void main() @nogc
{
import std.container, std.stdio;
auto a = Array!string("Test1", "Test2", "Test3", "Test1", 
"Test2");

import std.algorithm, std.range;
auto r = a[].enumerate.filter!(t => t[1] == "Test2").map!(t 
=> t[0]);

debug r.writeln; // std.stdio.writeln allocates at the moment
}
---

https://run.dlang.io/is/Fo32sN


Re: How do you get comfortable with Dlang.org's Forum?

2018-02-24 Thread rikki cattermole via Digitalmars-d

On 25/02/2018 2:31 PM, psychoticRabbit wrote:

NNTP is not the future..it's the past.


Good news, mailing lists will exist long after we're all dead and gone.
Right along with those stupid little phpbb installs.

You'd have to transition some very massive and important projects off of 
it and they are significantly harder to use than DFeed is.


Re: mysql-native v2.1.0-rc1: New features

2018-02-24 Thread Nick Sabalausky (Abscissa) via Digitalmars-d-announce
Minor second release candidate, 'v2.1.0-rc2'. Only thing this changes is 
to update the example in the readme to include the new simplified 
prepared statement interface.


Re: How do you get comfortable with Dlang.org's Forum?

2018-02-24 Thread psychoticRabbit via Digitalmars-d
On Saturday, 24 February 2018 at 20:29:34 UTC, Walter Bright 
wrote:


Yeah, the immutability of NNTP posts is a feature, not a bug.


but aren't git changes essentially immutable too?
as long is there is a history of the changes, there is no problem 
with changes.


I'm really only interested in the correct version of the persons 
intention, not some multitude of changes.


It also has the effect of encouraging people to pause a moment 
before hitting [Send], which is definitely a good thing.


yeah right. a good thing if we were robots instead of humans.

NNTP is not the future..it's the past.


Re: compilers w/ different language features: version block

2018-02-24 Thread Seb via Digitalmars-d-learn

On Sunday, 25 February 2018 at 00:42:20 UTC, Seb wrote:

On Sunday, 25 February 2018 at 00:36:16 UTC, kdevel wrote:

   [...]


Are you looking for something like this?

---
static if (__traits(compiles, () { static foreach (i; [0]){} }))
version = supportsStaticForeach;

void main()
{
version(supportsStaticForeach) {
   pragma(msg, "Yay, your compiler is new enough.");
}
}
---


https://run.dlang.io/is/PZN5Nv


[...]


Don't support GDC (or only GDC-master)?


Ah sorry I replied too fast. Yeah `mixin` is the only way to 
workaround this if you really, really have to support GDC.


Re: Vibe.d no more using static this() {}

2018-02-24 Thread Seb via Digitalmars-d-learn

On Friday, 23 February 2018 at 23:11:13 UTC, aberba wrote:
I recently noticed vibe.d now using main loop which call the 
vibe.d event loop.


"Recently"?
FWIW this has been phased out a long time ago ;-)

---

0.7.23 (2015)

Definition of either VibeCustomMain or VibeDefaultMain is now a 
hard requirement - this is the final deprecation phase for 
VibeCustomMain


https://github.com/vibe-d/vibe.d/blob/master/CHANGELOG.md#features-and-improvements-10

Added a compile time warning when neither VibeCustomMain, nor 
VibeDefaultMain versions are specified - starts the transition 
from VibeCustomMain to VibeDefaultMain


https://github.com/vibe-d/vibe.d/blob/master/CHANGELOG.md#features-and-improvements-14


0.7.30 (2016)

Added runApplication as a single API entry point to properly 
initialize and run a vibe.d application (this will serve as the 
basis for slowly phasing out the VibeDefaultMain convenience 
mechanism)


https://github.com/vibe-d/vibe.d/blob/master/CHANGELOG.md#features-and-improvements-4

---



Why that change?


In short, because there are too many problems with starting the 
eventloop by default without stating so and requiring the user to 
know what's going on. I don't know all the reasons, but one 
example that comes to my mind is that if you use Vibe.d for a 
simple curl-like script, you might be wondering why it never 
exits.
Also you mention `static this` in your title, but usually `shared 
static this` should be used.



There are also other concerns, e.g. the @safe-ty of the eventloop 
is never checked when you use the default main method.



Hence, in 2014 VibeDefaultMain was introduced to move away 
VibeCustomMain (which required the user to take explicit action 
when the eventloop shouldn't run).


Nowadays, a user neds to choose whether to use the default main 
loop (versions "VibeDefaultMain") or call 
runEventLoop/runApplication, but "VibeDefaultMain" with shared 
static this is deprecated.


[Issue 18515] freebsd 11 ships with gcc unable to link 32 bit binaries, dmd uses it by default

2018-02-24 Thread d-bugmail--- via Digitalmars-d-bugs
https://issues.dlang.org/show_bug.cgi?id=18515

--- Comment #7 from Jonathan M Davis  ---
Well, I'm able to build and run the tests for Phobos, druntime, and dmd without
having gcc installed on a 64-bit FreeBSD 11.1 system. I'd guess that that works
for 32-bit as well (aside from the test failures that are being worked
through), but I don't know. 2.068.2 certainly won't work that way though.

--


Re: compilers w/ different language features: version block

2018-02-24 Thread Jonathan M Davis via Digitalmars-d-learn
On Sunday, February 25, 2018 00:36:16 kdevel via Digitalmars-d-learn wrote:
> A code fragment using static foreach
>
> https://forum.dlang.org/thread/jiefcxwqbjzqnmtaz...@forum.dlang.org#post-b
> eruryblsptnunsowjph:40forum.dlang.org
>
> does not compile with the current GDC (GCC 4.9.4 and 5.5.0). I
> tried to encapsulate this code into a version block but GDC still
> checks the syntax. Is there any more elegant way besides of using
> a mixin?:
>
> version (DigitalMars) {
>pragma (msg, "DMD");
>mixin (`
>enum typenames = ["float", "double", "real", "short",
> "int", "long"];
>static foreach (s; typenames) {
>   pragma (msg, s);
>   disp[s] = mixin ("!" ~ s);
>}
>`);
> }

For static foreach? No. As I undarstand it, because of how the grammar works
with static foreach, there is no way to have it in the code (other than a
string mixin) unless the compiler supports it.

If you want to use newer features, I would suggest avoiding gdc until they
finish playing catch-up. They have yet to do an official release that's more
up-to-date than 2.068.2 of the front-end. When the frontend switched from
C++ to D, the gdc folks did a lot of rewriting to update their stuff, and
it's taken them a while to finish. What they have on github should be more
up-to-date, but I don't know what state it's in, and they have yet to do a
release with all of those updates. At some point, the gdc guys will catch
up, but for now, it's probably better to avoid it - especially if you want
to use newer features like static foreach.

So, I would suggest that you either use dmd or ldc. ldc has actually managed
to stay fairly up-to-date and is usually at most a release or so behind dmd.

But if you really want code to work with both gdc and and newer compilers,
then as far as static foreach goes, you'll have to do stuff like use string
mixins or different files for different compilers. Unfortunately, you can't
just use different version blocks.

- Jonathan M Davis



Re: compilers w/ different language features: version block

2018-02-24 Thread Seb via Digitalmars-d-learn

On Sunday, 25 February 2018 at 00:36:16 UTC, kdevel wrote:

A code fragment using static foreach

https://forum.dlang.org/thread/jiefcxwqbjzqnmtaz...@forum.dlang.org#post-beruryblsptnunsowjph:40forum.dlang.org

does not compile with the current GDC (GCC 4.9.4 and 5.5.0). I 
tried to encapsulate this code into a version block but GDC 
still checks the syntax. Is there any more elegant way besides 
of using a mixin?:


   version (DigitalMars) {
  pragma (msg, "DMD");
  mixin (`
  enum typenames = ["float", "double", "real", "short", 
"int", "long"];

  static foreach (s; typenames) {
 pragma (msg, s);
 disp[s] = mixin ("!" ~ s);
  }
  `);
   }


Are you looking for something like this?

---
static if (__traits(compiles, () { static foreach (i; [0]){} }))
version = supportsStaticForeach;

void main()
{
version(supportsStaticForeach) {
   pragma(msg, "Yay, your compiler is new enough.");
}
}
---


https://run.dlang.io/is/PZN5Nv


Is there any more elegant way besides of using a mixin?:


Don't support GDC (or only GDC-master)?


compilers w/ different language features: version block

2018-02-24 Thread kdevel via Digitalmars-d-learn

A code fragment using static foreach

https://forum.dlang.org/thread/jiefcxwqbjzqnmtaz...@forum.dlang.org#post-beruryblsptnunsowjph:40forum.dlang.org

does not compile with the current GDC (GCC 4.9.4 and 5.5.0). I 
tried to encapsulate this code into a version block but GDC still 
checks the syntax. Is there any more elegant way besides of using 
a mixin?:


   version (DigitalMars) {
  pragma (msg, "DMD");
  mixin (`
  enum typenames = ["float", "double", "real", "short", 
"int", "long"];

  static foreach (s; typenames) {
 pragma (msg, s);
 disp[s] = mixin ("!" ~ s);
  }
  `);
   }



[Issue 18480] [Reg 2.079] dmd hangs with self-alias declaration

2018-02-24 Thread d-bugmail--- via Digitalmars-d-bugs
https://issues.dlang.org/show_bug.cgi?id=18480

Martin Nowak  changed:

   What|Removed |Added

 CC||c...@dawg.eu
Summary|dmd 2.079 hangs |[Reg 2.079] dmd hangs with
   ||self-alias declaration

--


Re: short s, t; t = -s: no (longer) works: Deprecation: integral promotion not done for -s, use

2018-02-24 Thread ixid via Digitalmars-d-learn

On Saturday, 24 February 2018 at 20:07:04 UTC, kdevel wrote:

I don't get the point of the deprecation message:

--- intprom.d
import std.stdio;

void main ()
{
   short s, t;
   t = -s;
}
---

$ dmd intprom.d
intprom.d(6): Deprecation: integral promotion not done for -s, 
use '-transition=intpromote' switch or -cast(int)(s)


What shall I do in order to get my template code

void mymain (T) ()
{
   :
  b[i] = -b [i];
   :
}

compiled for any type for which negation is defined?


It's ridiculous and is going to cause endless pain and spammed or 
forgotten casts in generic code. It will turn off newbies to D.


Re: Postgres and other database interfaces

2018-02-24 Thread Denis F via Digitalmars-d

On Saturday, 24 February 2018 at 22:24:58 UTC, bachmeier wrote:

On Saturday, 24 February 2018 at 18:41:21 UTC, Denis F wrote:


Hi! Here is dpq2 and vibe-d-postgresql developer.

The problem is that I do not know English very well. So,I 
think it's better not to write any documentation than to write 
the wrong one.


There are still some steps you can take:

1. Put a statement on the project page encouraging people to 
create an issue if there is something not documented. Even 
better, have a Gitter community where they can post questions. 
You can create an example to show how it's done. Those examples 
can then be added to the project.




Done!

2. Decide on the common use cases for your library. Provide 
examples useful to someone getting started for each of the 
common use cases.


What is a bad with example?

3. Looking at the source code, you have already written a bunch 
of comments. Those are documentation once you turn them into 
html.


I'm for the comments to be documentation. But I am paranoid and 
do not like that the  documentation generator should be granted 
write access to the repository.




Re: Postgres and other database interfaces

2018-02-24 Thread Denis F via Digitalmars-d

On Saturday, 24 February 2018 at 20:45:03 UTC, Joe wrote:

On Saturday, 24 February 2018 at 18:56:23 UTC, Denis F wrote:
It seems to me that this is a common misconception that it is 
possible to create a good universal tool for accessing the 
database in place of the many existing ones.


I don't think what is needed a "good universal tool" but a good 
enough common interface. Python PEP 249 is very similar to what 
I've seen in the D libraries I've looked at: there is a 
Connection class of some kind, and a Cursor (or command or 
query) class, each with a set of well-defined (and generally 
not unexpected) methods: commit/rollback on the connection, 
execute/fetch/etc. on the cursor). PEP 249 also standardizes 
the exceptions and some datatypes.


Currently in dpq2 all of these things are implemented except 
cursors (I think cursors became "unpopular" lately)




It's not perfect, or universal enough, but I believe it allowed 
db development under Python to proceed at a faster pace than 
otherwise.


If anyone really want to impliment your idea, at my first glance 
at the PEP 249 I had a feeling that this is work for time less 
than a 1-2 weeks. It can be a simple wrapper over dpq2, 
mysql-native, sqlite3, etc.




Re: short s, t; t = -s: no (longer) works: Deprecation: integral promotion not done for -s, use

2018-02-24 Thread kdevel via Digitalmars-d-learn
On Saturday, 24 February 2018 at 22:30:09 UTC, Steven 
Schveighoffer wrote:



The prime example is this:

byte b = -128;

int x = -b;

What would you expect x to be?

a) 128
b) -128


Neither nor. I would prefer the codomain of "-" be the range of 
byte

and hence an exception thrown in that case.


[Issue 18519] New: freebsd 11 + phobos + curl, timing out

2018-02-24 Thread d-bugmail--- via Digitalmars-d-bugs
https://issues.dlang.org/show_bug.cgi?id=18519

  Issue ID: 18519
   Summary: freebsd 11 + phobos + curl, timing out
   Product: D
   Version: D2
  Hardware: x86
OS: FreeBSD
Status: NEW
  Severity: critical
  Priority: P1
 Component: phobos
  Assignee: nob...@puremagic.com
  Reporter: bra...@puremagic.com

Freebsd 11, 32 bit, doesn't come with 32 bit curl libraries, but does 64 bit.

The phobos tests seem to not fast-fail, timing out:

timelimit: sending warning signal 15
gmake[1]: *** [posix.mak:377: unittest/std/net/curl.run] Error 143
gmake[1]: Leaving directory
'/media/ephemeral0/sandbox/at-client/pull-3048038-FreeBSD_32/phobos'
gmake: *** [posix.mak:297: unittest-debug] Error 2
gmake: *** Waiting for unfinished jobs
timelimit: sending warning signal 15
gmake[1]: *** [posix.mak:377: unittest/std/net/curl.run] Error 143
gmake[1]: Leaving directory
'/media/ephemeral0/sandbox/at-client/pull-3048038-FreeBSD_32/phobos'
gmake: *** [posix.mak:297: unittest-release] Error 2

Issues:
1) how to get 32 bit libs installed on freebsd 11
2) why are the tests timing out rather than fast failing
3) why isn't it a clear failure

--


Aedi, v0.4.0 release

2018-02-24 Thread Alexandru Ermicioi via Digitalmars-d-announce

Hello everyone,

There is new release of Aedi, a dependency injection framework 
v0.4.0.


The new release contains changes below, of which the most notable 
is manual memory management for components using 
std.experimental.allocators.


Changelog:
- Added manual memory management mechanisms to component 
factories allowing to chose allocation mechanism for created 
components using std.experimental.allocator


- Added castable wrapper that allows seamless cast from D scalar 
types.
- Added preferred reference, that will fallback to default 
dependency when preferred one is not available.

- Added circular dependency resolution for setter injection.
- Added gc registering container responsible to register for 
scanning components not allocated with gc.
- Refactored annotation based configuration into policy driven 
manner, allowing easy configuration of component scanning 
capabilities.

- Deprecated old code and annotation api.
- Refactored getters to be inout or const compatible.
- Component locator is automatically updated in property 
configurers and instance factories from generic factory.


package - http://code.dlang.org/packages/aedi
docs - https://aermicioi.github.io/aedi/
examples - https://aermicioi.github.io/aedi/examples/examples

Cheers,
Alexandru.


Re: short s, t; t = -s: no (longer) works: Deprecation: integral promotion not done for -s, use

2018-02-24 Thread Steven Schveighoffer via Digitalmars-d-learn

On 2/24/18 4:42 PM, kdevel wrote:

On Saturday, 24 February 2018 at 20:17:12 UTC, Steven Schveighoffer wrote:

https://dlang.org/changelog/2.078.0.html#fix16997


My goodness! So there is currently no negation operator defined on short 
and some other types?


No, that's not the case. It's simply defined incorrectly.

The prime example is this:

byte b = -128;

int x = -b;

What would you expect x to be?

a) 128
b) -128

Currently, the answer is b. In C, the answer is a. With the 
-transition=intpromote switch, the answer is changed to a.


The reason it's so annoying is because we can't break code without first 
warning about it. This will change behavior in some cases. But chances 
are in most cases, you really wanted what C did, or your code would 
never hit the corner cases anyway (byte.min and short.min are so rare in 
the wild).


Eventually, the intpromote switch will go away, and a will be the 
permanent answer.



Any objections against leaving out the compiler switch and using

    b[i] = cast (T) (0 - b[i]);

instead?


You can do that too, seems like a good workaround. The current 
requirement that you first have to cast to int, and then cast back, is a 
bit over the top. See here: https://issues.dlang.org/show_bug.cgi?id=18380


-Steve


Re: Postgres and other database interfaces

2018-02-24 Thread bachmeier via Digitalmars-d

On Saturday, 24 February 2018 at 18:41:21 UTC, Denis F wrote:


Hi! Here is dpq2 and vibe-d-postgresql developer.

The problem is that I do not know English very well. So,I think 
it's better not to write any documentation than to write the 
wrong one.


There are still some steps you can take:

1. Put a statement on the project page encouraging people to 
create an issue if there is something not documented. Even 
better, have a Gitter community where they can post questions. 
You can create an example to show how it's done. Those examples 
can then be added to the project.


2. Decide on the common use cases for your library. Provide 
examples useful to someone getting started for each of the common 
use cases.


3. Looking at the source code, you have already written a bunch 
of comments. Those are documentation once you turn them into html.


Re: Where can get the strsafe.d by strsafe.h ? Thanks.

2018-02-24 Thread bauss via Digitalmars-d-learn

On Saturday, 24 February 2018 at 14:58:52 UTC, FrankLike wrote:

Hi,everyone,
Now,I use some code in strsafe.h,but where can get the 
strsafe.d ?


Thanks.


Basically nowhere.

strsafe.h is non-standard.

What you have to do is create the binding yourself.


[Issue 18515] freebsd 11 ships with gcc unable to link 32 bit binaries, dmd uses it by default

2018-02-24 Thread d-bugmail--- via Digitalmars-d-bugs
https://issues.dlang.org/show_bug.cgi?id=18515

--- Comment #6 from Brad Roberts  ---
I wasn't thinking about this last night, but the behavior that's in question
isn't master or stable branch, but rather 2.068.2.  That compiler's behavior is
where things are going wrong.  The problem, as far as the auto-tester is
concerned, has been worked around sufficiently.  I'm not sure if there's any
remaining issues with the tip of tree builds.

--


[Issue 18515] freebsd 11 ships with gcc unable to link 32 bit binaries, dmd uses it by default

2018-02-24 Thread d-bugmail--- via Digitalmars-d-bugs
https://issues.dlang.org/show_bug.cgi?id=18515

--- Comment #5 from github-bugzi...@puremagic.com ---
Commits pushed to master at https://github.com/dlang/dmd

https://github.com/dlang/dmd/commit/0527f4eef35b56afd67c65382a0e395d86db93f4
issue 18515: Fix it so that neither g++ nor CC is required.

It was previously fixed so that cc is used if CC isn't set when
compiling dmd, but the test suite still had g++ hardcoded, so if the
system was set up with clang and not gcc, the dmd test suite barfed
midway through. This fixes it so that it uses c++ if CC isn't set
instead of using g++.

https://github.com/dlang/dmd/commit/bd2465510a172414cc626f7d7ebc3d0db8aece3f
Merge pull request #7949 from jmdavis/issue_18515

issue 18515: Fix it so that neither g++ nor CC is required.

--


[Issue 5570] 64 bit C ABI not followed for passing structs and complex numbers as function parameters

2018-02-24 Thread d-bugmail--- via Digitalmars-d-bugs
https://issues.dlang.org/show_bug.cgi?id=5570

Timothee Cour  changed:

   What|Removed |Added

 CC||timothee.co...@gmail.com

--- Comment #50 from Timothee Cour  ---
is this still being worked on ? IIRC calypso handles return by value of C/C++
correctly (via llvm), maybe some of implementation can be reused?

--


Re: short s, t; t = -s: no (longer) works: Deprecation: integral promotion not done for -s, use

2018-02-24 Thread kdevel via Digitalmars-d-learn
On Saturday, 24 February 2018 at 20:17:12 UTC, Steven 
Schveighoffer wrote:

On 2/24/18 3:07 PM, kdevel wrote:

I don't get the point of the deprecation message:

--- intprom.d
import std.stdio;

void main ()
{
    short s, t;
    t = -s;
}
---


https://dlang.org/changelog/2.078.0.html#fix16997


My goodness! So there is currently no negation operator defined 
on short and some other types?



$ dmd intprom.d
intprom.d(6): Deprecation: integral promotion not done for -s, 
use '-transition=intpromote' switch or -cast(int)(s)


What shall I do in order to get my template code

void mymain (T) ()
{
    :
   b[i] = -b [i];
    :
}

compiled for any type for which negation is defined?


b[i] = cast(typeof(b[i]))-b[i];

And then use -transition=intpromote.

Note, your function wasn't real code, so maybe if you have the 
type of b[i] somewhere it might look better than what I wrote 
(like maybe cast(T)-b[i]).


Any objections against leaving out the compiler switch and using

   b[i] = cast (T) (0 - b[i]);

instead?






[Issue 16243] wrong C++ argument passing with empty struct when interfacing with Clang

2018-02-24 Thread d-bugmail--- via Digitalmars-d-bugs
https://issues.dlang.org/show_bug.cgi?id=16243

--- Comment #20 from github-bugzi...@puremagic.com ---
Commits pushed to master at https://github.com/dlang/dmd

https://github.com/dlang/dmd/commit/6966e6e0a9bf4ddf2760a46619e0c247ae8405ff
Temporary workaround for Issue 16243

https://github.com/dlang/dmd/commit/7969814467287d19726c81886c27e0692581092f
Merge pull request #7952 from WalterBright/workaround16243

Temporary workaround for Issue 16243

--


formattedRead string without allocation?

2018-02-24 Thread Steven Schveighoffer via Digitalmars-d-learn
I want to use formattedRead to enforce a certain format, and easily 
parse out the data from a string.


But if I do:

string s = "123:abc:123";

string y;
assert(s.formattedRead!"123:%s:123"(y) == 1);

y is now a newly-allocated string, not a slice of the input. In the case 
of parsing strings out of strings that aren't going away, it would be 
much more advantageous to simply slice the input. Is there something 
that does this?


-Steve


Re: Postgres and other database interfaces

2018-02-24 Thread Joe via Digitalmars-d

On Saturday, 24 February 2018 at 18:56:23 UTC, Denis F wrote:
It seems to me that this is a common misconception that it is 
possible to create a good universal tool for accessing the 
database in place of the many existing ones.


I don't think what is needed a "good universal tool" but a good 
enough common interface. Python PEP 249 is very similar to what 
I've seen in the D libraries I've looked at: there is a 
Connection class of some kind, and a Cursor (or command or query) 
class, each with a set of well-defined (and generally not 
unexpected) methods: commit/rollback on the connection, 
execute/fetch/etc. on the cursor). PEP 249 also standardizes the 
exceptions and some datatypes.


It's not perfect, or universal enough, but I believe it allowed 
db development under Python to proceed at a faster pace than 
otherwise. There's a similar story on the web side. When Django 
first came out, IIRC it had its own interface, but then the WSGI 
standard came out (PEP 333) and every Python web framework 
including Django moved to it (it also resulted in a proliferation 
of frameworks, but that's another story). And WSGI even 
influenced Ruby's Rack and other such interfaces.


Joe


[Issue 16243] wrong C++ argument passing with empty struct when interfacing with Clang

2018-02-24 Thread d-bugmail--- via Digitalmars-d-bugs
https://issues.dlang.org/show_bug.cgi?id=16243

--- Comment #19 from Walter Bright  ---
(In reply to Walter Bright from comment #18)
> Temporary workaround

https://github.com/dlang/dmd/pull/7952

--


[Issue 16243] wrong C++ argument passing with empty struct when interfacing with Clang

2018-02-24 Thread d-bugmail--- via Digitalmars-d-bugs
https://issues.dlang.org/show_bug.cgi?id=16243

Walter Bright  changed:

   What|Removed |Added

Summary|wrong C++ argument passing  |wrong C++ argument passing
   |with empty struct and 6 |with empty struct when
   |integers|interfacing with Clang

--


[Issue 16243] wrong C++ argument passing with empty struct and 6 integers

2018-02-24 Thread d-bugmail--- via Digitalmars-d-bugs
https://issues.dlang.org/show_bug.cgi?id=16243

--- Comment #18 from Walter Bright  ---
Temporary workaround

--


Re: How do you get comfortable with Dlang.org's Forum?

2018-02-24 Thread Walter Bright via Digitalmars-d

On 2/23/2018 8:41 PM, H. S. Teoh wrote:

+1. In the old days, it was called "bait and switch". After people reply
to an initial post, edit it and change it into something else
completely. It was one of the trolls' favorite tools.


Yeah, the immutability of NNTP posts is a feature, not a bug.

It also has the effect of encouraging people to pause a moment before hitting 
[Send], which is definitely a good thing.




Re: short s, t; t = -s: no (longer) works: Deprecation: integral promotion not done for -s, use

2018-02-24 Thread Steven Schveighoffer via Digitalmars-d-learn

On 2/24/18 3:07 PM, kdevel wrote:

I don't get the point of the deprecation message:

--- intprom.d
import std.stdio;

void main ()
{
    short s, t;
    t = -s;
}
---


https://dlang.org/changelog/2.078.0.html#fix16997



$ dmd intprom.d
intprom.d(6): Deprecation: integral promotion not done for -s, use 
'-transition=intpromote' switch or -cast(int)(s)


What shall I do in order to get my template code

void mymain (T) ()
{
    :
   b[i] = -b [i];
    :
}

compiled for any type for which negation is defined?


b[i] = cast(typeof(b[i]))-b[i];

And then use -transition=intpromote.

Note, your function wasn't real code, so maybe if you have the type of 
b[i] somewhere it might look better than what I wrote (like maybe 
cast(T)-b[i]).


-Steve


Re: Postgres and other database interfaces

2018-02-24 Thread Joe via Digitalmars-d

On Saturday, 24 February 2018 at 18:41:21 UTC, Denis F wrote:

On Saturday, 24 February 2018 at 05:33:56 UTC, Joe wrote:

2. dpq2. Second most downloaded and built on top of 
derelict-pq. The "documentation" consists of a README listing 
the features and a single example, which appears to focus on 
support for JSON/BSON.


Hi! Here is dpq2 and vibe-d-postgresql developer.

The problem is that I do not know English very well. So,I think 
it's better not to write any documentation than to write the 
wrong one.


PRs are welcomed!

3. vibe-d-postgresql. Third most downloaded and built on top 
of dpq2. Docs consist of a single example program.


Well Denis, you may get your PR wish (but I don't have a 
timeframe). My interest is to develop something using Vibe.d, so 
I'll be delving more into these two first.


Joe


short s, t; t = -s: no (longer) works: Deprecation: integral promotion not done for -s, use

2018-02-24 Thread kdevel via Digitalmars-d-learn

I don't get the point of the deprecation message:

--- intprom.d
import std.stdio;

void main ()
{
   short s, t;
   t = -s;
}
---

$ dmd intprom.d
intprom.d(6): Deprecation: integral promotion not done for -s, 
use '-transition=intpromote' switch or -cast(int)(s)


What shall I do in order to get my template code

void mymain (T) ()
{
   :
  b[i] = -b [i];
   :
}

compiled for any type for which negation is defined?


Re: Postgres and other database interfaces

2018-02-24 Thread Erik Smith via Digitalmars-d

On Saturday, 24 February 2018 at 18:56:23 UTC, Denis F wrote:
On Saturday, 24 February 2018 at 05:45:45 UTC, rikki cattermole 
wrote:
There is plenty of desire to build a generalized SQL interface 
for Phobos.


But somebody needs to do it and it won't be all that much fun 
to do.


I want to dwell on this.

It seems to me that this is a common misconception that it is 
possible to create a good universal tool for accessing the 
database in place of the many existing ones.


SQL is something like BASIC from the 70-80s: there is no single 
standard, there are many dialects. And the differences are both 
syntactic and deep, for example, Postgres and Oracle 
differently interpret the ANSI standard concerning 
transactions. The same applies to the connection layer: some of 
the databases allow you to organize a gradual download of the 
results, some - feedback in the form of something like 
"events", etc. Also, Postgres quarantiees that result of query 
will be immutable and this is very useful, but some one another 
DB maybe not.


At best, such a tool will be suitable for simple trivial things.

On the other hand, needing  for this is also not obvious - 
databases in real projects isn't switched usually every 
week/month because they are not interchangeable, except for 
some very simple cases. Usually RDBMS engine should be elected 
based on your requiriments before you start to use it.



I agree that the differences in both the client interface and the 
underlying SQL support are complicated issues.  However, it seems 
pretty clear that languages have some level of standardized db 
interface have benefited enormously in terms of adoption for 
building real word applications (JDBC for instance).  I think it 
is true people don't switch databases that much, but having a 
standard interface (especially one that is easy to use) that 
covers the most common uses cases does make the use of the 
platform itself that much more approachable.


Some of the differences can be hidden internally for the basic 
use case (such as gradual downloads) and optionally available as 
a introspective capability when the underlying driver supports it 
for more advanced usage.   The goal is to expose as much 
capability without overly complicating the interface.  This is 
easier to do now with modern abstractions then it was with ODBC 
in the 90's.


It would be good, however, to keep track of the specific problem 
areas that you mentioned to ensure that they are addressed well.


If one thing is clear from this thread, documentation is 
critical. I'm also aware that vibed support, for the databases 
that can most readily support it, is also a high priority.


erik



Re: How do you get comfortable with Dlang.org's Forum?

2018-02-24 Thread Patrick Schluter via Digitalmars-d
On Saturday, 24 February 2018 at 18:46:50 UTC, Steven 
Schveighoffer wrote:

On 2/24/18 7:00 AM, Patrick Schluter wrote:
On Saturday, 24 February 2018 at 04:41:44 UTC, H. S. Teoh 
wrote:

[...]


Last week I saw a video showing how a forum was shutdown 
because it was alledgedly full of racists. The thread where 
there were "racist comments" was in fact one where the initial 
question was ok, the answers absolutely nice but then the 
troll changed the initial post to something sinister and all 
the positive answers looked like agreement to the racist slur 
of the first comment. It was then demonstrated that the troll 
was a journalist from a big mainstream media. If I find the 
article again I will give a link (it's in french though, might 
not interest that much).





Wow, that's insane. I would be interested in seeing it.

It's in the history of my work PC, may be I will find it on 
monday.




Re: Vibe.d no more using static this() {}

2018-02-24 Thread bauss via Digitalmars-d-learn

On Friday, 23 February 2018 at 23:11:13 UTC, aberba wrote:
I recently noticed vibe.d now using main loop which call the 
vibe.d event loop. Why that change?


I can only assume it's because static constructors are a pain in 
the ass.


https://dlang.org/spec/module.html#order_of_static_ctor


Re: Postgres and other database interfaces

2018-02-24 Thread Denis F via Digitalmars-d

On Saturday, 24 February 2018 at 18:56:23 UTC, Denis F wrote:

Postgres quarantiees that result of query will be immutable


libpq, of course, not Postgres itself.


Re: Postgres and other database interfaces

2018-02-24 Thread Denis F via Digitalmars-d
On Saturday, 24 February 2018 at 05:45:45 UTC, rikki cattermole 
wrote:
There is plenty of desire to build a generalized SQL interface 
for Phobos.


But somebody needs to do it and it won't be all that much fun 
to do.


I want to dwell on this.

It seems to me that this is a common misconception that it is 
possible to create a good universal tool for accessing the 
database in place of the many existing ones.


SQL is something like BASIC from the 70-80s: there is no single 
standard, there are many dialects. And the differences are both 
syntactic and deep, for example, Postgres and Oracle differently 
interpret the ANSI standard concerning transactions. The same 
applies to the connection layer: some of the databases allow you 
to organize a gradual download of the results, some - feedback in 
the form of something like "events", etc. Also, Postgres 
quarantiees that result of query will be immutable and this is 
very useful, but some one another DB maybe not.


At best, such a tool will be suitable for simple trivial things.

On the other hand, needing  for this is also not obvious - 
databases in real projects isn't switched usually every 
week/month because they are not interchangeable, except for some 
very simple cases. Usually RDBMS engine should be elected based 
on your requiriments before you start to use it.




[Issue 13855] Allow multiple selective imports from different modules in a single import statement

2018-02-24 Thread d-bugmail--- via Digitalmars-d-bugs
https://issues.dlang.org/show_bug.cgi?id=13855

Steven Schveighoffer  changed:

   What|Removed |Added

 Status|RESOLVED|REOPENED
 CC||schvei...@yahoo.com
 Resolution|FIXED   |---

--- Comment #11 from Steven Schveighoffer  ---
Reverted (for now).

--


Re: How do you get comfortable with Dlang.org's Forum?

2018-02-24 Thread Steven Schveighoffer via Digitalmars-d

On 2/24/18 7:00 AM, Patrick Schluter wrote:

On Saturday, 24 February 2018 at 04:41:44 UTC, H. S. Teoh wrote:
On Sat, Feb 24, 2018 at 04:18:29AM +, MattCoder via Digitalmars-d 
wrote:

On Friday, 23 February 2018 at 13:47:16 UTC, biocyberman wrote:
> 1. No post editing...

You should be grateful for this, because I hate systems like: Forums, 
Reddit and whatever, where people can edit/delete posts changing the 
context of things.

[...]

+1. In the old days, it was called "bait and switch". After people 
reply to an initial post, edit it and change it into something else 
completely. It was one of the trolls' favorite tools.


Last week I saw a video showing how a forum was shutdown because it was 
alledgedly full of racists. The thread where there were "racist 
comments" was in fact one where the initial question was ok, the answers 
absolutely nice but then the troll changed the initial post to something 
sinister and all the positive answers looked like agreement to the 
racist slur of the first comment. It was then demonstrated that the 
troll was a journalist from a big mainstream media. If I find the 
article again I will give a link (it's in french though, might not 
interest that much).





Wow, that's insane. I would be interested in seeing it.

-Steve


[Issue 1839] Give D a modern varargs system that allows forwarding

2018-02-24 Thread d-bugmail--- via Digitalmars-d-bugs
https://issues.dlang.org/show_bug.cgi?id=1839

Martin Nowak  changed:

   What|Removed |Added

 Status|ASSIGNED|RESOLVED
 CC||c...@dawg.eu
 Resolution|--- |WONTFIX

--- Comment #16 from Martin Nowak  ---
This won't work due to ABI specialities, things need to be setup for another
call and it's unreasonable that other backends would support our special D
vararg forward. Just get a va_list and forward that indead, it contains
pointers to all the original arguments.

--


Re: Postgres and other database interfaces

2018-02-24 Thread Denis F via Digitalmars-d

On Saturday, 24 February 2018 at 05:33:56 UTC, Joe wrote:

2. dpq2. Second most downloaded and built on top of 
derelict-pq. The "documentation" consists of a README listing 
the features and a single example, which appears to focus on 
support for JSON/BSON.


Hi! Here is dpq2 and vibe-d-postgresql developer.

The problem is that I do not know English very well. So,I think 
it's better not to write any documentation than to write the 
wrong one.


PRs are welcomed!

3. vibe-d-postgresql. Third most downloaded and built on top of 
dpq2. Docs consist of a single example program.





Re: How do you get comfortable with Dlang.org's Forum?

2018-02-24 Thread Steven Schveighoffer via Digitalmars-d

On 2/24/18 1:18 AM, Nick Sabalausky (Abscissa) wrote:

On 02/23/2018 10:18 AM, Steven Schveighoffer wrote:


TB has these, though I prefer plain text. It supports a crude form of 
markdown, so *bold*, _underline_ all are enhanced by TB. Emoticons 
turn into graphics too ;)




I turned those off in my TB installation. I hate having my software 
messing with my content.


But the cool thing is, you can do that for you, and I can do the 
opposite for me. Hard to do that as easily in a web forum ;)


-Steve


[Issue 18518] New: use stable names for multilib object files (to enable incremental update of archives)

2018-02-24 Thread d-bugmail--- via Digitalmars-d-bugs
https://issues.dlang.org/show_bug.cgi?id=18518

  Issue ID: 18518
   Summary: use stable names for multilib object files (to enable
incremental update of archives)
   Product: D
   Version: D2
  Hardware: All
OS: All
Status: NEW
  Severity: enhancement
  Priority: P2
 Component: dmd
  Assignee: nob...@puremagic.com
  Reporter: c...@dawg.eu

At the moment the names for multilib objects are created based on a count.
https://github.com/dlang/dmd/blob/9691eba9441f7f165359716f80f46486ea09fb46/src/dmd/glue.d#L167

unicode_tables.o
unicode_tables_3a86_5f8.o
unicode_tables_3a87_521.o
unicode_tables_3a88_3a1.o
unicode_tables_3a89_62c.o

This means those names are not stable when using a different command line.
If we made the names unique based only on the primary symbol of that multilib
object, then we had a stable order that is invariant to modules order on the
command line.
This could then be used to incrementally update a multilib archive by
recompiling only modified modules.

--


Re: Postgres and other database interfaces

2018-02-24 Thread Joe via Digitalmars-d
On Saturday, 24 February 2018 at 15:44:49 UTC, Paolo Invernizzi 
wrote:
Joe: I think this is also a terrific 'welcome aboard' about how 
fast and quickly things can be done in D!


I'm a bit overwhelmed by all the replies and "goodies" but I'd 
like to say thanks to Adam while I digest it all.


Joe


Re: Postgres and other database interfaces

2018-02-24 Thread Adam D. Ruppe via Digitalmars-d
On Saturday, 24 February 2018 at 16:42:26 UTC, Adam D. Ruppe 
wrote:

source viewer


This now works:
http://dpq.dpldocs.info/source/dpq.query.d.html#L29

the "see implementation" links lead to pages like that. You'll 
notice in the source view that many names are links. You can 
click on them to go to their definition too. The sidebar has docs 
links, if applicable.


Note that the main dpldocs.info site has this for Phobos too 
http://dpldocs.info/experimental-docs/source/std.socket.d.html#L2593 thought I don't update the source often there so it can get out of sync (Phobos is a bit big to rebuild frequently)


Re: Postgres and other database interfaces

2018-02-24 Thread Adam D. Ruppe via Digitalmars-d

On Saturday, 24 February 2018 at 05:33:56 UTC, Joe wrote:
The main issue is that, other than derelict-pq, using any of 
these libraries involves reading the library code and 
understanding the sui generis interfaces implemented by each.


So often in threads like this I chime in to point out my lib 
too... but ironically, it is poorly documented :P


http://dpldocs.info/experimental-docs/arsd.postgres.PostgreSql.html

Of course, my lib is so thin that there isn't much to document 
anyway (the source code is ~200 lines)


Re: Postgres and other database interfaces

2018-02-24 Thread Adam D. Ruppe via Digitalmars-d
On Saturday, 24 February 2018 at 16:41:09 UTC, Martin 
Tschierschke wrote:
Please make a post to announce and place the direct link to it 
inside code.dlang.org :-)


Well, I forgot to log errors on the server so I see a few 
generation failures and I'm not sure if it is because the code is 
missing docs or if one of my components failed! I'll have to look 
at the packages in question.


But yeah, I'd like to have the link on code.dlang.org so people 
can discover it. Let's set a goal of having it ready for that 
next week.


Would it be possible to use it for calculating/evaluating a 
measure for inlined documentation?


Yes, certainly it can tell if it is there or not at least really 
easily. But if it is not there because it is an internal module 
and supposed to be not publicly documented or poorly done is 
harder to tell without some kind of user intervention.


Ideally, of course, I would ascend to godhood and force all 
packages to explicitly declare internal stuff so it can be 
automatically analyzed...


Re: Postgres and other database interfaces

2018-02-24 Thread Martin Tschierschke via Digitalmars-d
On Saturday, 24 February 2018 at 15:44:49 UTC, Paolo Invernizzi 
wrote:
On Saturday, 24 February 2018 at 15:32:32 UTC, Adam D. Ruppe 
wrote:

On Saturday, 24 February 2018 at 14:13:18 UTC, Joe wrote:

[...]

You can try going to

http://any-dub-package.dpldocs.info

[...]


:-O

Adam, you are the man!
I'll never stop of being surprised by your way of coding!

Great Job!

+1
Fascinating!

Please make a post to announce and place the direct link to it 
inside code.dlang.org :-)


Would it be possible to use it for calculating/evaluating a 
measure for inlined documentation?





Re: Postgres and other database interfaces

2018-02-24 Thread Adam D. Ruppe via Digitalmars-d
On Saturday, 24 February 2018 at 15:44:49 UTC, Paolo Invernizzi 
wrote:

:-O

Adam, you are the man!


worship me!


So I'm gonna tell you guys a dirty little secret: I intend to 
take the documentation throne by means of subterfuge. I've been 
generating docs for popular packages already but it has been a 
manual process (I, last night, did some hacks to better support 
gtkd than anyone else I have see: 
http://dpldocs.info/experimental-docs/gtk.ApplicationWindow.ApplicationWindow.html i'm about 80% happy with it.)


The new thing here is just a little program to automate that 
process when the URL is fetched. But it doesn't do versioning or 
cross-package referencing or a few of the other things I have 
planned notably, it also ignores the examples/ folders, which 
are a really useful source (and btw my doc gen web source viewer 
has go-to-definition omg!)



Still, it is fairly usable as-is and I hope it encourages people 
to do more dox. And I hope it gets them to use my syntax and 
features: 
http://dpldocs.info/experimental-docs/adrdox.syntax.html that i 
may finally take the crown and rule the D-language area11 
muahhahah


Re: countUntil to print all the index of a given string.

2018-02-24 Thread Vino via Digitalmars-d-learn
On Tuesday, 20 February 2018 at 08:50:27 UTC, Jonathan M Davis 
wrote:
On Tuesday, February 20, 2018 08:44:37 aberba via 
Digitalmars-d-learn wrote:

On Sunday, 18 February 2018 at 15:23:14 UTC, Cym13 wrote:
> On Sunday, 18 February 2018 at 14:48:59 UTC, Cym13 wrote:
>> [...]
>
> Just thought of a much better/simpler solution for that last 
> case that also doesn't force you to read all data (which 
> might

>
> be impossible when dealing with infinite ranges):
> import std.range;
> import std.algorithm;
>
> a[]
>
>  .enumerate   // get tuples (index,
>
> value)
>
>  .filter!(t => t[1] == "Test2")   // keep only if value 
> ==

>
> "Test2"
>
>  .map!(t => t[0]) // keep only the index
>
> part
>
>  .writeln;
>
> Completely lazy.

How does one detect an operation as lazy or not?  Is the some 
compile-time or runtime check for that?


My guess is by referring to the docs function signature.


You have to read the docs or read the source code, though in 
general, functions that return a range type that wraps the 
original range tend to be lazy, whereas if a function returns 
the original range type or an array, then it's clearly not lazy.


- Jonathan M Davis


Hi All,

 Thank you very much, the provide solution work's for the given 
example, so how can we achieve the same for the below code



import std.stdio;
import std.container;
import std.algorithm;

void main () {
auto a = Array!string("Test1", "Test2", "Test3", "Test1", 
"Test2");

auto b = Array!string("Test1", "Test2", "Test3");

foreach(i; b[]) {
writeln(SList!int(a[].countUntil(i))[]); }
}

Output
[0]
[1]
[2]

Required
[0,3]
[1,4]
[2]

From,
Vino.B


Re: PackedAliasSeq?

2018-02-24 Thread John Colvin via Digitalmars-d
On Thursday, 22 February 2018 at 19:26:54 UTC, Andrei 
Alexandrescu wrote:
After coding https://github.com/dlang/phobos/pull/6192 with 
AliasSeq, the experience has been quite pleasurable. However, 
in places the AliasSeq tends to expand too eagerly, leading to 
a need to "keep it together" e.g. when you need to pass two of 
those to a template.


I worked around the issue by nesting templates like this:

template Merge(T...)
{
template With(U...)
{
static if (T.length == 0)
alias With = U;
else static if (U.length == 0)
alias With = T;
else static if (T[0] < U[0]
 || T[0] == U[0] && T[1].stringof <= 
U[1].stringof)

alias With =
AliasSeq!(T[0], T[1], Merge!(T[2 .. $]).With!U);
   else
alias With =
AliasSeq!(U[0], U[1], Merge!T.With!(U[2 .. $]));
}
}

So instead of the unworkable Merge!(AliasSeq!(...), 
AliasSeq!(...)), one would write 
Merge!(AliasSeq!(...)).With!(AliasSeq!(...)).


The problem remains for other use cases, so I was thinking of 
adding to std.meta this simple artifact:


template PackedAliasSeq!(T...)
{
alias expand = AliasSeq!T;
}

That way, everything stays together and can be expanded on 
demand.



Andrei


Yes, I love this stuff, lots of possibilities.

E.g.

import std.traits : isInstanceOf;
import std.meta : allSatisfy, AliasSeq, staticMap, Alias;

template Pack(T ...)
{
alias expand = T;
enum length = expand.length;
}

enum isPack(alias T) = isInstanceOf!(Pack, T);

template Head(alias P)
if (isPack!P)
{
alias Head = Alias!(P.expand[0]);
}

template Tail(alias P)
if (isPack!P)
{
alias Tail = Pack!(P.expand[1 .. $]);
}

template staticZip(Seqs ...)
if (Seqs.length >= 2 && allSatisfy!(isPack, Seqs))
{
enum len = Seqs[0].length;
static foreach (Seq; Seqs[1 .. $])
static assert(Seq.length == len,
"All arguments to staticZip must have the same 
length");


static if (len == 0)
alias staticZip = AliasSeq!();
else
alias staticZip = AliasSeq!(Pack!(staticMap!(Head, Seqs)),
staticZip!(staticMap!(Tail, 
Seqs)));

}


[Issue 18517] New: Import order is not invariant

2018-02-24 Thread d-bugmail--- via Digitalmars-d-bugs
https://issues.dlang.org/show_bug.cgi?id=18517

  Issue ID: 18517
   Summary: Import order is not invariant
   Product: D
   Version: D2
  Hardware: All
OS: All
Status: NEW
  Severity: enhancement
  Priority: P1
 Component: dmd
  Assignee: nob...@puremagic.com
  Reporter: johnnymar...@gmail.com

Currently, compilation will change depending on the order that imports are
processed.  This order is determined by the order that modules are passed to
the compiler on the command line, and also the order they appear in each
individual file.  Here are some examples:

Import order in file changes output:

--- foo.d
version (A)
{
static import baz;
static import bar;
}
version (B)
{
static import bar;
static import baz;
}
void main()
{
import std.stdio;
writeln(bar.thing);
writeln(baz.thing);
}
--- bar.d
module baz;
enum thing = "this is baz from bar.d";
--- baz.d
module bar;
enum thing = "this is bar from baz.d";


dmd -version=A -run foo.d

this is bar from baz.d
this is bar from baz.d


dmd -version=B -run foo.d

this is baz from bar.d
this is baz from bar.d


Output changes depending on order of modules passed on the command line:

--- main.d
import ibar, ibaz;
void main()
{
ibarfunc();
ibazfunc();
}

--- ibar.d
import bar, std.stdio;
void ibarfunc()
{
writeln(thing);
}

--- ibaz.d
import baz, std.stdio;
void ibazfunc()
{
writeln(thing);
}

--- bar.d
module baz;
enum thing = "this is baz from bar.d";

--- baz.d
module bar;
enum thing = "this is bar from baz.d";


dmd ibar.d ibaz.d -run main.d
OUTPUT:
this is baz from bar.d
this is baz from bar.d

dmd ibaz.d ibar.d -run main.d
OUTPUT:
this is bar from baz.d
this is bar from baz.d

A PR to fix this has been submitted: https://github.com/dlang/dmd/pull/7900

--


Re: Postgres and other database interfaces

2018-02-24 Thread Paolo Invernizzi via Digitalmars-d
On Saturday, 24 February 2018 at 15:32:32 UTC, Adam D. Ruppe 
wrote:

On Saturday, 24 February 2018 at 14:13:18 UTC, Joe wrote:

Again, coming from Python, I'm familiar with RTD


So I actually just made this extension to my dpldocs website:

http://ddb.dpldocs.info/ddb.postgres.html


You can try going to

http://any-dub-package.dpldocs.info

and it will try to build the docs on demand.

for example:
http://dpq.dpldocs.info/dpq.html



If you're the first user to hit a page, it might take some time 
to load and send you to a random page once generation is 
complete, but then you can navigate with the sidebar to see the 
rest.



I literally just slapped this together now, so I expect it 
won't be perfect, but this has been on my todo list for a year 
(I even bought a VPS to host it on... 6 months ago and have 
been paying for it without even using it!), so it was time to 
do.


:-O

Adam, you are the man!
I'll never stop of being surprised by your way of coding!

Great Job!

Joe: I think this is also a terrific 'welcome aboard' about how 
fast and quickly things can be done in D!


:-P

/Paolo





[Issue 18244] Generic functions in std.math cannot be overloaded

2018-02-24 Thread d-bugmail--- via Digitalmars-d-bugs
https://issues.dlang.org/show_bug.cgi?id=18244

hst...@quickfur.ath.cx changed:

   What|Removed |Added

 Status|RESOLVED|REOPENED
 Resolution|FIXED   |---

--


Re: Postgres and other database interfaces

2018-02-24 Thread Adam D. Ruppe via Digitalmars-d

On Saturday, 24 February 2018 at 14:13:18 UTC, Joe wrote:

Again, coming from Python, I'm familiar with RTD


So I actually just made this extension to my dpldocs website:

http://ddb.dpldocs.info/ddb.postgres.html


You can try going to

http://any-dub-package.dpldocs.info

and it will try to build the docs on demand.

for example:
http://dpq.dpldocs.info/dpq.html



If you're the first user to hit a page, it might take some time 
to load and send you to a random page once generation is 
complete, but then you can navigate with the sidebar to see the 
rest.



I literally just slapped this together now, so I expect it won't 
be perfect, but this has been on my todo list for a year (I even 
bought a VPS to host it on... 6 months ago and have been paying 
for it without even using it!), so it was time to do.


Re: Postgres and other database interfaces

2018-02-24 Thread bachmeier via Digitalmars-d
On Saturday, 24 February 2018 at 14:54:21 UTC, Martin 
Tschierschke wrote:


I would even go so far 'force' people publishing to dub, to 
provide documentation.
If no docs, present, than the libs should be marked as *docs 
missing*. (Beside the number of Github stars)


If there's no documentation, the project has no business 
cluttering up the website, and should not be published on Dub.


Where can get the strsafe.d by strsafe.h ? Thanks.

2018-02-24 Thread FrankLike via Digitalmars-d-learn

Hi,everyone,
Now,I use some code in strsafe.h,but where can get the strsafe.d ?

Thanks.


Re: Postgres and other database interfaces

2018-02-24 Thread Martin Tschierschke via Digitalmars-d

On Saturday, 24 February 2018 at 14:13:18 UTC, Joe wrote:

On Saturday, 24 February 2018 at 10:13:35 UTC, Paolo Invernizzi

[...]


As I said, I'm new and still not familiar with those facilities 
although I saw those things and they looked like embedded HTML 
and was wondering what they were for.


Again, coming from Python, I'm familiar with RTD 
(https://readthedocs.org, my own open source Python/Postgres 
project is hosted there) and Sphinx 
(http://www.sphinx-doc.org/en/master/). Although it started 
with Python, RTD now hosts many other kinds of projects 
(Javascript, PHP, Ruby, etc.). There's even a project named 
'dlang' (it's not what you expect!), but I did find "D Tips" 
and "Quick Start with D" which appear to be standalone 
Markdown. In any case, it would be nice to have such 
automatically generated docs available in a public site/repo of 
some kind, like RTD, so a potential user doesn't have to clone 
the code and run the compiler to see it.

+1
I would even go so far 'force' people publishing to dub, to 
provide documentation.
If no docs, present, than the libs should be marked as *docs 
missing*. (Beside the number of Github stars)




Re: Double link list

2018-02-24 Thread ag0aep6g via Digitalmars-d-learn

On 02/24/2018 11:26 AM, TheFlyingFiddle wrote:

On Saturday, 24 February 2018 at 09:48:13 UTC, Joel wrote:

[...]
void popFront() { head = head.next;  if (head !is null) head.prev = 
null; }

void popBack() { tail = tail.prev; if (tail !is null) tail.next = null; }


Head and tail will point to the same nodes and you are setting the 
head.prev to null. Which would make the tail.prev null when iterating it 
backwards. Similarly if you started iterating it backwards and then 
iterating it forward it would not work.


To expand on this:

The goal of this was apparently to have `popBack` stop before reaching 
nodes that have already been `popFront`ed. I.e., `retro` should respect 
the earlier `dropOne`.


To do that properly, you can look for `head is tail`. If `head is tail`, 
the range is at its last element. Doesn't matter if there is another 
`next` or `prev`. `popFront` and `popBack` can just declare the range as 
empty then, e.g. by setting `head = null; tail = null;`.


So:


void popFront()
{
if (head is tail) { head = null; tail = null; }
else head = head.next;
}
void popBack()
{
if (head is tail) { head = null; tail = null; }
else tail = tail.prev;
}


Generally, don't change the data's structure in a range. In a range over 
a linked list, don't touch the links.


Also, the `List` here functions both as a container (adding/removing 
links) and as a range (traversing the links). Separating the two into 
different types might make it easier to see what a method should be 
allowed to do.


Re: How to convert C macro to D? Thanks.

2018-02-24 Thread FrankLike via Digitalmars-d-learn
On Saturday, 24 February 2018 at 13:57:27 UTC, Adam D. Ruppe 
wrote:

On Saturday, 24 February 2018 at 13:50:16 UTC, FrankLike wrote:
#define IOCTL_NDIS_QUERY_GLOBAL_STATS   _NDIS_CONTROL_CODE(0, 
METHOD_OUT_DIRECT)



auto IOCTL_NDIS_QUERY_GLOBAL_STATS () {
  return _NDIS_CONTROL_CODE(0, METHOD_OUT_DIRECT);
}


Sorry.

I look for 'IOCTL_DISK_GET_DRIVE_GEOMETRY' in 
core.sys.windows.winioctl.d,then I know :


enum :DWORD IOCTL_NDIS_QUERY_GLOBAL_STATS = 
CTL_CODE_T!(FILE_DEVICE_PHYSICAL_NETCARD, 0, METHOD_OUT_DIRECT, 
FILE_ANY_ACCESS);


It's ok.

Thank you.


Re: Postgres and other database interfaces

2018-02-24 Thread Joe via Digitalmars-d
On Saturday, 24 February 2018 at 10:13:35 UTC, Paolo Invernizzi 
wrote:


Have you tried to generate the documentation?

Look for example inside the source files...

https://github.com/pszturmaj/ddb/blob/bd55beea0df6e5da86a71535ff6d9800c0711c7c/source/ddb/postgres.d#L2

https://github.com/pszturmaj/ddb/blob/bd55beea0df6e5da86a71535ff6d9800c0711c7c/source/ddb/db.d#L19



I think no...

The documentation on how to use the package is present, it's 
just inside the modules as Ddoc documentation.


Joe, you can easily 'extract' it using the proper -D compiler 
switch


As I said, I'm new and still not familiar with those facilities 
although I saw those things and they looked like embedded HTML 
and was wondering what they were for.


Again, coming from Python, I'm familiar with RTD 
(https://readthedocs.org, my own open source Python/Postgres 
project is hosted there) and Sphinx 
(http://www.sphinx-doc.org/en/master/). Although it started with 
Python, RTD now hosts many other kinds of projects (Javascript, 
PHP, Ruby, etc.). There's even a project named 'dlang' (it's not 
what you expect!), but I did find "D Tips" and "Quick Start with 
D" which appear to be standalone Markdown. In any case, it would 
be nice to have such automatically generated docs available in a 
public site/repo of some kind, like RTD, so a potential user 
doesn't have to clone the code and run the compiler to see it.


Re: How do you get comfortable with Dlang.org's Forum?

2018-02-24 Thread number via Digitalmars-d
On Friday, 23 February 2018 at 14:25:55 UTC, psychoticRabbit 
wrote:

If there is one change that I would really like, it's dark theme


I used to use Firefox Addon 'Colour That Site!' but its not 
available for current Firefox version. Today the built-in Reader 
Mode might just do it (click the little 'paper sheet' in address 
bar, if it's available for the site). It has a white-on-black 
mode too (click 'Aa' ..).


[Issue 18509] [Beta 2.079] lld-link.exe needs msvcp140.dll

2018-02-24 Thread d-bugmail--- via Digitalmars-d-bugs
https://issues.dlang.org/show_bug.cgi?id=18509

Martin Nowak  changed:

   What|Removed |Added

 Status|NEW |RESOLVED
 Resolution|--- |FIXED

--- Comment #4 from Martin Nowak  ---
Fixed by
https://github.com/dlang/installer/commit/d713fe32d9d031961d9cdaa23b8469b86a231117

--


Re: How to convert C macro to D? Thanks.

2018-02-24 Thread Adam D. Ruppe via Digitalmars-d-learn

On Saturday, 24 February 2018 at 13:50:16 UTC, FrankLike wrote:
#define IOCTL_NDIS_QUERY_GLOBAL_STATS   _NDIS_CONTROL_CODE(0, 
METHOD_OUT_DIRECT)


use alias or enum,how to do?


neither. those are little functions.

auto IOCTL_NDIS_QUERY_GLOBAL_STATS () {
  return _NDIS_CONTROL_CODE(0, METHOD_OUT_DIRECT);
}


How to convert C macro to D? Thanks.

2018-02-24 Thread FrankLike via Digitalmars-d-learn

Hi,everyone,

I can convert some simple C macros, but a bit more complicated 
will need your help.

For example:

#define _NDIS_CONTROL_CODE(request,method) \
CTL_CODE(FILE_DEVICE_PHYSICAL_NETCARD, request, 
method, FILE_ANY_ACCESS)


#define IOCTL_NDIS_QUERY_GLOBAL_STATS   _NDIS_CONTROL_CODE(0, 
METHOD_OUT_DIRECT)


use alias or enum,how to do?

Thanks.


Re: Postgres and other database interfaces

2018-02-24 Thread Kagamin via Digitalmars-d

On Saturday, 24 February 2018 at 05:33:56 UTC, Joe wrote:
3. vibe-d-postgresql. Third most downloaded and built on top of 
dpq2. Docs consist of a single example program.


If you write docs and examples, I'd expect vibe to accept them, 
but ask them anyway.


2.079.0-beta.2 [Re: Beta 2.079.0]

2018-02-24 Thread Martin Nowak via Digitalmars-d-announce

On Monday, 19 February 2018 at 10:49:03 UTC, Martin Nowak wrote:
http://dlang.org/download.html#dmd_beta 
http://dlang.org/changelog/2.079.0.html


Second beta is published now. The website build server has some 
issues, so the website update is still stuck for a while.


You can see a changelog preview here
  
http://dtest.dlang.io/artifact/website-e5f8ee1211cb48bf97e0502f958179f8c82c9b35-ea6717f0f487cd7258756895d14da33f/web/changelog/2.079.0.html

until it will be updated on
  http://dlang.org/changelog/2.079.0.html
.

Downloads can be found under
  http://downloads.dlang.org/pre-releases/2.x/2.079.0/
until they are linked on
  http://dlang.org/download.html#dmd_beta
.

Changes:

https://github.com/dlang/dmd/compare/v2.079.0-beta.1...v2.079.0-beta.2
https://github.com/dlang/druntime/compare/v2.079.0-beta.1...v2.079.0-beta.2
https://github.com/dlang/phobos/compare/v2.079.0-beta.1...v2.079.0-beta.2
https://github.com/dlang/installer/compare/v2.079.0-beta.1...v2.079.0-beta.2
https://github.com/dlang/tools/compare/v2.079.0-beta.1...v2.079.0-beta.2
https://github.com/dlang/dlang.org/compare/v2.079.0-beta.1...v2.079.0-beta.2
https://github.com/dlang/dub/compare/v1.8.0-beta.1...v1.8.0-beta.2



Re: d.godbolt.org now supports DMD

2018-02-24 Thread Martin Nowak via Digitalmars-d-announce

On Friday, 23 February 2018 at 18:11:58 UTC, Seb wrote:

https://godbolt.org/g/EQCTNy

[1] https://github.com/mattgodbolt/compiler-explorer/issues/306


Great news, bad code ;).


Re: Anybody still using the chm docs

2018-02-24 Thread Seb via Digitalmars-d

On Saturday, 24 February 2018 at 11:23:17 UTC, notna wrote:

On Thursday, 16 June 2016 at 02:32:05 UTC, Jack Stouffer wrote:

On Wednesday, 15 June 2016 at 10:58:04 UTC, Martin Nowak wrote:
So I'm wondering if in 2016 someone really needs an offline 
copy of a website shipped with a binary release?


For offline browsing, Windows and Linux users can use Zeal [1] 
which is FOSS, and macOS users can use Dash[2], which is free 
as in beer. Both of which can use this D docset [3].


So no, there's no reason to maintain the chm docs.

[1] https://zealdocs.org/
[2] https://kapeli.com/dash
[3] 
https://github.com/Kapeli/Dash-User-Contributions/tree/master/docsets/D#readme


thanks... great community... everyday something new to learn... 
even in 2+ years old posts ;)


FYI: devdocs.io (works in every browser + offers optional offline 
access via HTML5 localStorage) supports D too:


http://devdocs.io/d/


Re: How to split a string to a 2D array

2018-02-24 Thread Seb via Digitalmars-d-learn

On Saturday, 24 February 2018 at 09:06:09 UTC, Domain wrote:

On Saturday, 24 February 2018 at 08:59:46 UTC, Domain wrote:

On Saturday, 24 February 2018 at 07:51:27 UTC, Domain wrote:

[...]


And why this not compile:

rows.each!(a => data ~= a.split(",").map!(b => 
b.strip).padRight("", 2));



Error: cannot deduce function from argument types 
!()(string[]), candidates are:

C:\D\dmd2\windows\bin\..\..\src\phobos\std\algorithm\iteration.d(899): 
C:\D\dmd2\windows\bin\..\..\src\phobos\std\algorithm\iteration.d(934):


OK, this compile:
rows.each!(a => data ~= a.split(",").map!(b => 
b.strip).padRight("", 2).array);


FYI: Idiomatic D would be to avoid allocations (faster!).
An example:

```
auto html = " a,b1, 23 ";
auto rows = 
html.strip.splitter("").filter!(not!empty).map!(a => 
a.splitter(","));

rows.writeln;
```

https://run.dlang.io/is/LC7Sog

If you really, really need a 2d array you can always do so if 
required at the end:


```
auto arr2d = rows.map!array.array;
```

But please keep in mind that you ideally avoid the allocations in 
the first place.


  1   2   >