Re: Visual D 0.47.0 released

2018-06-26 Thread Rainer Schuetze via Digitalmars-d-learn




On 26/06/2018 16:25, Robert M. Münch wrote:

On 2018-06-24 13:08:53 +, Rainer Schuetze said:


a new release of Visual D has just been uploaded. Major changes are

* improved Visual C++ project integration: better dependencies,
   automatic libraries, name demangling
* new project wizard
* mago debugger: show vtable, dynamic type of interfaces,
   symbol names of pointer address


As soon as I use the Mago debugger, it's impossible to start a debugging 
session. Any idea how to track down such a problem?




Works for me, can you give more details? VS version, platform, etc.

Please note that there is no need to select the Mago debug engine in 
VS2013 or later. Since a couple of versions of Visual D, the VS debugger 
is equipped with an extension based on Mago that can evaluate D expressions.


Re: Catching std.conv.ConvException in readf causes a buffer overrun

2018-06-26 Thread Shigeki Karita via Digitalmars-d-learn

On Wednesday, 27 June 2018 at 02:39:49 UTC, Shigeki Karita wrote:

import std.stdio;
import std.conv;

void main() {
int i;
try {
readf("%d\n", &i); // "a"
} catch (ConvException e) {
auto s = readln();
writeln(s); // "aa", "aaa" or SEGV ???
}
}

https://wandbox.org/permlink/NMYNjpOgQtfUprBQ

I just want to retry reading if input was invalid. How can I do 
it?



I found that formattedRead!"%d\n"(readln(), i) can avoid the 
buffer overrun why readf cannot do this?


---

import std.stdio;
import std.format;

import std.stdio;
import std.format;

void main() {
int i;
try {
formattedRead!"%d\n"(readln(), i);
} catch (Exception e) {
// writeln(e);
auto s = readln();
writeln(s); // ""
}
}


Catching std.conv.ConvException in readf causes a buffer overrun

2018-06-26 Thread Shigeki Karita via Digitalmars-d-learn

import std.stdio;
import std.conv;

void main() {
int i;
try {
readf("%d\n", &i); // "a"
} catch (ConvException e) {
auto s = readln();
writeln(s); // "aa", "aaa" or SEGV ???
}
}

https://wandbox.org/permlink/NMYNjpOgQtfUprBQ

I just want to retry reading if input was invalid. How can I do 
it?


Re: CustomString and string constraints

2018-06-26 Thread SrMordred via Digitalmars-d-learn

On Tuesday, 26 June 2018 at 22:16:28 UTC, Jonathan M Davis wrote:


If what you're asking is whether it's possible for a template 
constraint that uses something like isSomeString will ever 
match a user-defined type, then the answer is no.


Thats exactly what I wanted xD.
My idea was that if you can make custom array types that operate 
with phobos lib(via some implicit conversions) then there 
"should" have a way to do that with strings, but I understood the 
issues that you explained. Thanks!


Re: CustomString and string constraints

2018-06-26 Thread Jonathan M Davis via Digitalmars-d-learn
n Tuesday, June 26, 2018 17:14:08 SrMordred via Digitalmars-d-learn wrote:
> Is possible to make a Custom Struct String work for D string
> constraints?
>
> eg:
>
> struct MyString
> {
>  char[] arr;
>  alias arr this;
> }
>
> void getString( char[] str ){}
>
> MyString().split(";"); //oops, type mismatch
>
> getString( MyString() ); //fine, implicit conversion
>
> isSomeString!(char[]).writeln; //true
> isSomeString!(MyString).writeln; //false

If what you're asking is whether it's possible for a template constraint
that uses something like isSomeString will ever match a user-defined type,
then the answer is no. isSomeString specifically requires that the type be a
string. And it actually would be fairly error-prone if it accepted anything
else.

If a template is written with the assumption that it's going to be operating
on arrays of characters, and it accepts anything that implicitly converts to
an array of characters, then you easily get subtle bugs (e.g. some parts of
the code could use the actual type and others would do the implicit
conversion rather than the code consistently using the same type). Any
template that accepts an implicit conversion really needs to force that
conversion rather than trying to operate on a type that implicitly converts
to a particular type as if it were that type. But in general, it's just far
less error-prone to require that the caller do the conversion.

And implicit conversions to dynamic arrays (strings included) are
particularly dangerous to allow. For instance, if you have a function that
does something like

T[] foo(T[] arr)
{
...
return arr[i .. j];
}

and you pass it a T[42], then the implicit conversion is done at the call
site, and the slice that is returned is valid and will continue to be valid
so long as the static array has not been destroyed. However, if you do
something like

T[] foo(U)(U arr)
if(is(U : T[]))
{
...
return arr[i .. j];
}

or

T[] foo(U)(U arr)
if(is(U : T[]))
{
T[] retval = arr;
...
return retval[i .. j];
}

then the implicit conversion is done inside the function. And because static
arrays are value types, the slice that's returned is a slice of local memory
and is therefore invalid, causing @safety-related problems.

So, while your particular type might be able to safely convert inside such a
function and still be @safe, that's not true in the general case. As such,
templated code that wants to accept implicit conversions to dynamic arrays
really needs to be templated on the element type and not the whole type.
e.g.

T[] foo(T)(T[] arr)
{
...
return arr[i .. j];
}

can @safely return a slice, because the implicit conversion was forced at
the call site just like it was with the non-templated function.

In general, Phobos only accepts implicit conversions with template
constraints when the function was originally not a template but was later
turned into a template, and the implicit conversion had to be kept in order
to avoid breaking code. And to do that @safely, the conversion to a template
must be done very carefully, and there are actually some cases in Phobos
which still need to be fixed, because it was done incorrectly. All in all,
while it might be annoying sometimes, it's just safer to have templates
require that all conversions be done before making the call rather than
allowing implicit conversions.

- Jonathan M Davis



Re: Nullable!T with T of class type

2018-06-26 Thread Jonathan M Davis via Digitalmars-d-learn
On Tuesday, June 26, 2018 19:03:20 kdevel via Digitalmars-d-learn wrote:
> On Monday, 25 June 2018 at 22:58:41 UTC, Jonathan M Davis wrote:
> > On Monday, June 25, 2018 19:40:30 kdevel via
> >
> > Digitalmars-d-learn wrote:
> >> R r;
> >>
> >> if (r.s is null)
> >>
> >>throw new Exception ("some error message");
>
> [...]
>
> >> Why can't this programming error be detected at compile time?
> >
> > If you have a function that accepts Nullable!T, when that
> > function is called, how on earth is it going to know whether
> > the argument it received was null at compile time?
>
> That was not the error. The error was that I used is null instead
> of .isNull() which lead to a different Exception (Error).

Well, get checks whether the Nullable isNull, and throws an Error if it is,
which is what you showed in your original post. If you want a Nullable to
have the value of null, then you have to explicitly set it to null. Nullable
really doesn't have anything to do with the null value for pointers or
references beyond the fact that it allows a way to emulate that behavior for
non-nullable types by using a bool.

isNull returns whether the Nullable has been given a value or not, whereas
checking the value with is null means checking whether it has a value and
whether that value is null. If that behavior is not what you want, then you
will have to find a different solution, though honestly, I don't understand
why folks keep trying to put nullable types in Nullable in non-generic code.

- Jonathan M Davis



Re: template recursion

2018-06-26 Thread Nathan S. via Digitalmars-d-learn
On Tuesday, 26 June 2018 at 20:47:27 UTC, Steven Schveighoffer 
wrote:
Naming the hook for `put` the same thing as the global function 
was one of the biggest mistakes in the range library. I almost 
think we would be better off to deprecate that and pick another 
hook name.


If you ever do that it would also be nice to use separate names 
for "put a single X into Y" and "put everything from container X 
into Y".


Re: template recursion

2018-06-26 Thread Steven Schveighoffer via Digitalmars-d-learn

On 6/26/18 6:01 AM, ag0aep6g wrote:

On line 23, you're apparently trying to call std.range.put (which would 
in turn call tarr[t].put). But being in a method that is itself called 
"put", that line is instead interpreted as a recursive call (which 
fails). To refer to std.range.put, you have to prepend a dot (the 
"module scope operator"):


     .put(tarr[t], t); // line 23

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


Naming the hook for `put` the same thing as the global function was one 
of the biggest mistakes in the range library. I almost think we would be 
better off to deprecate that and pick another hook name.


-Steve


Re: Nullable!T with T of class type

2018-06-26 Thread kdevel via Digitalmars-d-learn

On Tuesday, 26 June 2018 at 14:32:59 UTC, Nathan S. wrote:

On Monday, 25 June 2018 at 19:40:30 UTC, kdevel wrote:

Is it possible
to "lower" the Nullable operations if T is a class type such 
that there

is only one level of nullification?


Yes: https://run.dlang.io/is/hPxbyf


template Nullable(S)


[...]





Works nicely. Thanks!


Re: Nullable!T with T of class type

2018-06-26 Thread kdevel via Digitalmars-d-learn

On Monday, 25 June 2018 at 22:58:41 UTC, Jonathan M Davis wrote:
On Monday, June 25, 2018 19:40:30 kdevel via 
Digitalmars-d-learn wrote:

R r;

if (r.s is null)
   throw new Exception ("some error message");


[...]


Why can't this programming error be detected at compile time?


If you have a function that accepts Nullable!T, when that 
function is called, how on earth is it going to know whether 
the argument it received was null at compile time?


That was not the error. The error was that I used is null instead 
of .isNull() which lead to a different Exception (Error).


[...]

If you really don't want the extra bool, then just don't use 
Nullable. Class references are already naturally nullable.


Sure.


Re: First run after build on Windows is slow

2018-06-26 Thread Patrick Schluter via Digitalmars-d-learn

On Tuesday, 26 June 2018 at 12:58:29 UTC, Adam D. Ruppe wrote:

On Tuesday, 26 June 2018 at 12:40:05 UTC, phs wrote:
Although, it's a little bit strange because I have never had 
this issue with my C++ development.


The c++ compiler and runtime libraries are common enough that 
the antivirus realizes it is nothing special, but since D is 
more obscure it just flags it as abnormal and does further 
checks. (more obscure C++ compilers can do the same thing).


Walter has written Microsoft and they have OK'd it before, but 
then one side or the other updates and then they are out of 
whack again :(


Yes, the anti-virus situation is really annoying on windows. I 
couldn't install dmd 2.080 on the work PC as the AV always 
quarantained some of the installed tools which made the install 
routine fail. The blame lies on our work PC's which are 
incredibly misconfigured and limited (proxy that Microsoft VS 
installer can not overcome even if any other program can, extra 
small system SSD, eager anti-virus that cannot be instructed of 
anything, profiles with read/write desktop but no delete (this 
means that a shortcut can be copied on the desktop but can never 
be removed), etc. etc.)
Just had to vent my frustration. I love D but the elements are 
against me to be able to enjoy it to the fullest...


Re: How do I call this tamplte function?

2018-06-26 Thread Ali Çehreli via Digitalmars-d-learn

On 06/26/2018 10:37 AM, Rib wrote:
to get get() from std.net.curl return a ubyte[] and use my http 
instance, all those failed:


string link = "http://...";;
auto client = HTTP();
// set some client attributes...
auto fileContents = get!(AutoProtocol, ubyte)(link, client);
auto fileContents = get!(ubyte)(link, client);
auto fileContents = get!(client, ubyte)(link, client);

  I still didn't "get" D templates.


This worked for me:


import std.net.curl;
import std.stdio;
import std.functional;

void myHeaderReceivingFunction(const(char[]) key, const(char[]) value) {
writefln("Received header: %s = %s", key, value);
}

size_t myDataReceivingFunction(ubyte[] data) {
writefln("Received data; first part: %s", data[0..10]);
return data.length;
}

void main() {
auto client = HTTP("http://dlang.org";);

// If you don't have an actual delegate, you can use 
std.functional.toDelegate:

client.onReceiveHeader = (&myHeaderReceivingFunction).toDelegate;

// ... or you can create a delegate with a lambda on the fly:
client.onReceive = (ubyte[] data) { return 
myDataReceivingFunction(data); };


client.perform();
}

Ali


How do I call this tamplte function?

2018-06-26 Thread Rib via Digitalmars-d-learn
to get get() from std.net.curl return a ubyte[] and use my http 
instance, all those failed:


string link = "http://...";;
auto client = HTTP();
// set some client attributes...
auto fileContents = get!(AutoProtocol, ubyte)(link, client);
auto fileContents = get!(ubyte)(link, client);
auto fileContents = get!(client, ubyte)(link, client);

 I still didn't "get" D templates.


CustomString and string constraints

2018-06-26 Thread SrMordred via Digitalmars-d-learn
Is possible to make a Custom Struct String work for D string 
constraints?


eg:

struct MyString
{
char[] arr;
alias arr this;
}

void getString( char[] str ){}

MyString().split(";"); //oops, type mismatch

getString( MyString() ); //fine, implicit conversion

isSomeString!(char[]).writeln; //true
isSomeString!(MyString).writeln; //false



Re: Nullable!T with T of class type

2018-06-26 Thread Nathan S. via Digitalmars-d-learn

On Monday, 25 June 2018 at 22:58:41 UTC, Jonathan M Davis wrote:
Java does try to force you to initialize stuff (resulting in 
annoying false positives at times), but in general, it still 
can't guarantee when a variable is null or not and is forced to 
insert runtime null checks.


Java can be somewhat clever about this though. Often it just 
needs to perform a single null check in a method body and 
thereafter knows the pointer can't be null and elides the check.


Re: Nullable!T with T of class type

2018-06-26 Thread Nathan S. via Digitalmars-d-learn

On Monday, 25 June 2018 at 19:40:30 UTC, kdevel wrote:

Is it possible
to "lower" the Nullable operations if T is a class type such 
that there

is only one level of nullification?


Yes: https://run.dlang.io/is/hPxbyf


template Nullable(S)
{
import std.traits : isPointer, isDynamicArray;
static if (is(S == class) || is(S == interface)
   || is(S == function) || is(S == delegate)
   || isPointer!S || isDynamicArray!S)
{
alias Nullable = S;
}
else
{
static import std.typecons;
alias Nullable = std.typecons.Nullable!S;
}
}




Re: Visual D 0.47.0 released

2018-06-26 Thread Robert M. Münch via Digitalmars-d-learn

On 2018-06-24 13:08:53 +, Rainer Schuetze said:


a new release of Visual D has just been uploaded. Major changes are

* improved Visual C++ project integration: better dependencies,
   automatic libraries, name demangling
* new project wizard
* mago debugger: show vtable, dynamic type of interfaces,
   symbol names of pointer address


As soon as I use the Mago debugger, it's impossible to start a 
debugging session. Any idea how to track down such a problem?


--
Robert M. Münch
http://www.saphirion.com
smarter | better | faster



Re: alias symbol name

2018-06-26 Thread Radu via Digitalmars-d-learn

On Tuesday, 26 June 2018 at 12:19:16 UTC, Jonathan M Davis wrote:
On Tuesday, June 26, 2018 11:28:11 Radu via Digitalmars-d-learn 
wrote:

> [...]

Ha! :) yeah I was pretty sure this will not work.

I'm looking to generate some custom wrappers and knowing when 
something is really `size_t` is important, I have a backup 
plan, but having a compiler trait to get an alias symbol name 
would be great. Maybe this is worthy an enhancement request?


Feel free. I have no idea how likely it is to ever be 
implemented.


However, if your custom wrappers are generated at compilation 
time rather than generated as files to be compiled later, then 
it's unnecessary to know whether an alias was used, since then 
you'd just use the exact type being used for that particular 
compilation.


- Jonathan M Davis


Code generation is at compile time and the target is C code, so 
it is important to keep the type `size_t` rather than `uint` or 
`ulong` for obvious reasons.


I will submit and issue for a new trait.


Re: First run after build on Windows is slow

2018-06-26 Thread Adam D. Ruppe via Digitalmars-d-learn

On Tuesday, 26 June 2018 at 12:40:05 UTC, phs wrote:
Although, it's a little bit strange because I have never had 
this issue with my C++ development.


The c++ compiler and runtime libraries are common enough that the 
antivirus realizes it is nothing special, but since D is more 
obscure it just flags it as abnormal and does further checks. 
(more obscure C++ compilers can do the same thing).


Walter has written Microsoft and they have OK'd it before, but 
then one side or the other updates and then they are out of whack 
again :(


Re: First run after build on Windows is slow

2018-06-26 Thread phs via Digitalmars-d-learn

On Tuesday, 26 June 2018 at 12:26:45 UTC, rikki cattermole wrote:

On 27/06/2018 12:25 AM, phs wrote:
Hello. I've made a simple hello world program using dub and 
dmd for Windows. Everything works well, except that every 
first run after each rebuild takes around 3 seconds just to 
start up. Is it normal at all?


Its normal if you don't add an exclusion for that directory in 
your anti-virus.


Thank you for the hint. Disabling the Windows Defender helped to 
resolve this issue. Although, it's a little bit strange because I 
have never had this issue with my C++ development.


First run after build on Windows is slow

2018-06-26 Thread phs via Digitalmars-d-learn
Hello. I've made a simple hello world program using dub and dmd 
for Windows. Everything works well, except that every first run 
after each rebuild takes around 3 seconds just to start up. Is it 
normal at all?


Re: First run after build on Windows is slow

2018-06-26 Thread rikki cattermole via Digitalmars-d-learn

On 27/06/2018 12:25 AM, phs wrote:
Hello. I've made a simple hello world program using dub and dmd for 
Windows. Everything works well, except that every first run after each 
rebuild takes around 3 seconds just to start up. Is it normal at all?


Its normal if you don't add an exclusion for that directory in your 
anti-virus.


Re: alias symbol name

2018-06-26 Thread Jonathan M Davis via Digitalmars-d-learn
On Tuesday, June 26, 2018 11:28:11 Radu via Digitalmars-d-learn wrote:
> > I'm pretty sure that that's impossible. As I understand it, the
> > compiler basically just replaces aliases with what they refer
> > to and doesn't care what the original type was. And they
> > _definitely_ don't affect mangling. If you're looking to treat
> > an alias as anything different from what it refers to, you're
> > going to be disappointed.
> >
> > - Jonathan M Davis
>
> Ha! :) yeah I was pretty sure this will not work.
>
> I'm looking to generate some custom wrappers and knowing when
> something is really `size_t` is important, I have a backup plan,
> but having a compiler trait to get an alias symbol name would be
> great. Maybe this is worthy an enhancement request?

Feel free. I have no idea how likely it is to ever be implemented.

However, if your custom wrappers are generated at compilation time rather
than generated as files to be compiled later, then it's unnecessary to know
whether an alias was used, since then you'd just use the exact type being
used for that particular compilation.

- Jonathan M Davis



Re: alias symbol name

2018-06-26 Thread Radu via Digitalmars-d-learn

On Tuesday, 26 June 2018 at 10:19:44 UTC, Jonathan M Davis wrote:
On Tuesday, June 26, 2018 09:47:44 Radu via Digitalmars-d-learn 
wrote:

On Tuesday, 26 June 2018 at 09:24:15 UTC, Stefan Koch wrote:
> On Tuesday, 26 June 2018 at 09:14:11 UTC, Radu wrote:
>> Consider this https://run.dlang.io/is/HyY2qG
>>
>> ---
>> void main()
>> {
>>
>> import std.traits;
>> size_t s;
>>
>> pragma(msg, typeof(s).stringof);
>> pragma(msg, mangledName!(typeof(s)));
>> pragma(msg, mangledName!s);
>>
>> }
>> ---
>>
>> It outputs:
>> ---
>> ulong
>> m
>> _D9onlineapp4mainFZ1sm
>> ---
>>
>> I'm looking for a way to get the `s` type symbol name 
>> (size_t)

>> not whatever the alias is pointing to (ulong in this case).
>>
>> Is there a way to obtain the alias symbol name?
>
> __traits(identifier, sym);

Him, that will print the symbol name, in my case `s`.

To cut to chase - I'm looking something that will print 
`size_t` for the symbol `s`.


I'm pretty sure that that's impossible. As I understand it, the 
compiler basically just replaces aliases with what they refer 
to and doesn't care what the original type was. And they 
_definitely_ don't affect mangling. If you're looking to treat 
an alias as anything different from what it refers to, you're 
going to be disappointed.


- Jonathan M Davis


Ha! :) yeah I was pretty sure this will not work.

I'm looking to generate some custom wrappers and knowing when 
something is really `size_t` is important, I have a backup plan, 
but having a compiler trait to get an alias symbol name would be 
great. Maybe this is worthy an enhancement request?


Re: alias symbol name

2018-06-26 Thread Jonathan M Davis via Digitalmars-d-learn
On Tuesday, June 26, 2018 09:47:44 Radu via Digitalmars-d-learn wrote:
> On Tuesday, 26 June 2018 at 09:24:15 UTC, Stefan Koch wrote:
> > On Tuesday, 26 June 2018 at 09:14:11 UTC, Radu wrote:
> >> Consider this https://run.dlang.io/is/HyY2qG
> >>
> >> ---
> >> void main()
> >> {
> >>
> >> import std.traits;
> >> size_t s;
> >>
> >> pragma(msg, typeof(s).stringof);
> >> pragma(msg, mangledName!(typeof(s)));
> >> pragma(msg, mangledName!s);
> >>
> >> }
> >> ---
> >>
> >> It outputs:
> >> ---
> >> ulong
> >> m
> >> _D9onlineapp4mainFZ1sm
> >> ---
> >>
> >> I'm looking for a way to get the `s` type symbol name (size_t)
> >> not whatever the alias is pointing to (ulong in this case).
> >>
> >> Is there a way to obtain the alias symbol name?
> >
> > __traits(identifier, sym);
>
> Him, that will print the symbol name, in my case `s`.
>
> To cut to chase - I'm looking something that will print `size_t`
> for the symbol `s`.

I'm pretty sure that that's impossible. As I understand it, the compiler
basically just replaces aliases with what they refer to and doesn't care
what the original type was. And they _definitely_ don't affect mangling. If
you're looking to treat an alias as anything different from what it refers
to, you're going to be disappointed.

- Jonathan M Davis



Re: template recursion

2018-06-26 Thread Alex via Digitalmars-d-learn

On Tuesday, 26 June 2018 at 10:01:06 UTC, ag0aep6g wrote:
On line 23, you're apparently trying to call std.range.put 
(which would in turn call tarr[t].put). But being in a method 
that is itself called "put", that line is instead interpreted 
as a recursive call (which fails). To refer to std.range.put, 
you have to prepend a dot (the "module scope operator"):


.put(tarr[t], t); // line 23

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


Ah... that's cool :)
Thanks a lot!


Re: template recursion

2018-06-26 Thread ag0aep6g via Digitalmars-d-learn

On 06/26/2018 11:35 AM, Alex wrote:

´´´
import std.range;

void main()
{
 T.member.tarr.length = 42;
 //put(T.member, 4); // line 6
 T.member.put(4); // line 7
}


struct T
{
 void put(Type)(Type t){} // line 13

 static B member;
}

struct B
{
 T[] tarr;
 void put(Type)(Type t)
 {
     put(tarr[t], t); // line 23
 }
}
´´´

Line 7 complains about:
template app.B.put cannot deduce function from argument types !()(T, int)

So, I see, that the compiler tries to use the same put function in line 
23, as in line 7 and fails. Instead of this, I want to use the one in 
line 13.

But I don't see any mistake at line 23...


On line 23, you're apparently trying to call std.range.put (which would 
in turn call tarr[t].put). But being in a method that is itself called 
"put", that line is instead interpreted as a recursive call (which 
fails). To refer to std.range.put, you have to prepend a dot (the 
"module scope operator"):


.put(tarr[t], t); // line 23

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


Re: alias symbol name

2018-06-26 Thread Radu via Digitalmars-d-learn

On Tuesday, 26 June 2018 at 09:24:15 UTC, Stefan Koch wrote:

On Tuesday, 26 June 2018 at 09:14:11 UTC, Radu wrote:

Consider this https://run.dlang.io/is/HyY2qG

---
void main()
{
import std.traits;
size_t s;

pragma(msg, typeof(s).stringof);
pragma(msg, mangledName!(typeof(s)));
pragma(msg, mangledName!s);
}
---

It outputs:
---
ulong
m
_D9onlineapp4mainFZ1sm
---

I'm looking for a way to get the `s` type symbol name (size_t) 
not whatever the alias is pointing to (ulong in this case).


Is there a way to obtain the alias symbol name?


__traits(identifier, sym);


Him, that will print the symbol name, in my case `s`.

To cut to chase - I'm looking something that will print `size_t` 
for the symbol `s`.


template recursion

2018-06-26 Thread Alex via Digitalmars-d-learn

Hi all,
I have a strange case of template recursion, which I don't know 
how to solve:


´´´
import std.range;

void main()
{
T.member.tarr.length = 42;
//put(T.member, 4); // line 6
T.member.put(4); // line 7
}


struct T
{
void put(Type)(Type t){} // line 13

static B member;
}

struct B
{
T[] tarr;
void put(Type)(Type t)
{
put(tarr[t], t); // line 23
}
}
´´´

Line 7 complains about:
template app.B.put cannot deduce function from argument types 
!()(T, int)


So, I see, that the compiler tries to use the same put function 
in line 23, as in line 7 and fails. Instead of this, I want to 
use the one in line 13.

But I don't see any mistake at line 23...

Besides this, as a secondary question:
using line 6 does not yield any helpful debugging message. My put 
functions are templates and pretty long and branching, and I'm 
trying to debug them somehow, but using idiomatic writing all I 
get as a message is something like

"Cannot put a XX into a YY." :(




Re: alias symbol name

2018-06-26 Thread Stefan Koch via Digitalmars-d-learn

On Tuesday, 26 June 2018 at 09:14:11 UTC, Radu wrote:

Consider this https://run.dlang.io/is/HyY2qG

---
void main()
{
import std.traits;
size_t s;

pragma(msg, typeof(s).stringof);
pragma(msg, mangledName!(typeof(s)));
pragma(msg, mangledName!s);
}
---

It outputs:
---
ulong
m
_D9onlineapp4mainFZ1sm
---

I'm looking for a way to get the `s` type symbol name (size_t) 
not whatever the alias is pointing to (ulong in this case).


Is there a way to obtain the alias symbol name?


__traits(identifier, sym);


alias symbol name

2018-06-26 Thread Radu via Digitalmars-d-learn

Consider this https://run.dlang.io/is/HyY2qG

---
void main()
{
import std.traits;
size_t s;

pragma(msg, typeof(s).stringof);
pragma(msg, mangledName!(typeof(s)));
pragma(msg, mangledName!s);
}
---

It outputs:
---
ulong
m
_D9onlineapp4mainFZ1sm
---

I'm looking for a way to get the `s` type symbol name (size_t) 
not whatever the alias is pointing to (ulong in this case).


Is there a way to obtain the alias symbol name?



Re: Making sense of recursion

2018-06-26 Thread Timoses via Digitalmars-d-learn

On Monday, 25 June 2018 at 17:45:01 UTC, zbr wrote:
Hi, this question is not specifically D related but I'll just 
ask anyway. Consider the following snippet:


void mergeSort(int[] arr, int l, int r)
{
   if (l < r)   // 1
   {
  int m = l+(r-l)/2;// 2
  mergeSort(arr, l, m); // 3
  mergeSort(arr, m+1, r);   // 4
  merge(arr, l, m, r);  // 5
   }// 6
}   // 7

mergeSort(arr, 0, 4);

When I see this, I visualize the recursion to perform this way:

mergeSort(arr, 0, 4):
0 < 4 ? true: mergeSort(0, 2):
0 < 2 ? true: mergeSort(0, 1):
0 < 1 ? true: mergeSort(0, 0):
0 < 0 ? false: //reach the end of mergeSort / 
reach line 6 and then 7


I don't see the computer ever reaching line 4 and 5? Obviously 
I'm wrong but where is my mistake?


Thanks.


It's a stack (https://en.wikipedia.org/wiki/Call_stack).

When the program calls a function it is pushed onto the stack. If 
that function returns it pops from the stack and the previous 
function gets to continue execution from where it stopped before.