Re: Is it possible to avoid call to destructor for structs?

2017-09-27 Thread Elronnd via Digitalmars-d-learn
Here's a simple solution.  Just make Bar a pointer and free it 
before it can be destructed!



import std.stdio;

struct Bar {
~this() {
writeln("~bar");
}
}

struct Foo {
Bar *bar;
this(int why_the_fuck_dont_structs_have_default_constructors) 
{

bar = new Bar;
}
~this() {
writeln("~foo");
import core.memory;
GC.free(bar);
}
}


Re: Is it possible to avoid call to destructor for structs?

2017-09-27 Thread Elronnd via Digitalmars-d-learn
Here's a simple solution.  Just make Bar a pointer and free it 
before it can be destructed!



import std.stdio;

struct Bar {
~this() {
writeln("~bar");
}
}

struct Foo {
Bar *bar;
this(int why_the_fuck_dont_structs_have_default_constructors) 
{

bar = new Bar;
}
~this() {
writeln("~foo");
import core.memory;
GC.free(bar);
}
}


Re: Should we add `a * b` for vectors?

2017-09-27 Thread Walter Bright via Digitalmars-d

On 9/27/2017 4:21 PM, Manu wrote:

D does not have ADL,


Thank gawd! :-)


which will almost certainly lead to _very_ nasty surprises in behaviour.


ADL was always a hack to get around the wretched overloading symbol lookup 
behavior in C++. I see it has somehow morphed into a feature :-( but I see no 
advantage to it over D's approach (the reverse operand lookup scheme).




Re: std.reflection prototype

2017-09-27 Thread bitwise via Digitalmars-d
On Wednesday, 27 September 2017 at 20:38:51 UTC, Gheorghe Gabriel 
wrote:

On Monday, 30 March 2015 at 01:11:55 UTC, bitwise wrote:

[...]


Hi, your link is not working any more and I really need your 
implementation.

Gabriel


I took the code down because there were design flaws I had to 
work out. I've reworked the code significantly at this point. I 
can throw a copy up on github in a day or two if you need it.


There are still some issues to overcome though, which may or may 
not be a problem depending on what you're doing.


Re: Compile-time reflection and templates

2017-09-27 Thread jmh530 via Digitalmars-d
On Wednesday, 27 September 2017 at 21:18:54 UTC, Jean-Louis Leroy 
wrote:


I am aware of these but TemplateArgsOf takes a template 
*instantiation* and returns the arguments. I want to reflect 
the *template*.


Yeah, I had kind of realized the point about instantiate mid-post.


Re: Should we add `a * b` for vectors?

2017-09-27 Thread jmh530 via Digitalmars-d

On Wednesday, 27 September 2017 at 23:25:34 UTC, Manu wrote:


Again, sadly, D has no ADL, and this will be an unmitigated 
disaster as a

result!
Instantiations of templates will use the default elementwise 
operator
instead of the one you specified in your module, and nobody 
will understand

why.


Argument-dependent lookup? I'm not an expert on C++, but I read 
the wikipedia entry on it. It does seem like an issue worth 
thinking more about


One (hacky) solution is to not have default implementations for 
the all the operators (the focus so far has been on the multiple 
uses of * for element-wise multiply and dot product/matrix 
multiplication). So you have Slice in mir.ndslice.slice. Then 
make a mir.ndslice.operator.elementwise module that has the 
operator overloading for elementwise operations, then a module 
mir.ndslice.operator.linalg (or somewhere in lubeck) with the dot 
product or inverse implementations. The key to making this work 
is that you also need a mid.ndslice.arithmetic or something that 
allows the user to call these functions without operator 
overloading. This way they can put import their default, but if 
they have a function that mixes and matches dot and element-wise 
multiplication, they can do that too.


Re: Is it possible to specify the address returned by the address of operator?

2017-09-27 Thread DreadKyller via Digitalmars-d-learn

On Wednesday, 27 September 2017 at 23:24:58 UTC, user1234 wrote:
On Wednesday, 27 September 2017 at 21:01:36 UTC, Jesse Phillips 
wrote:
On Wednesday, 27 September 2017 at 16:35:54 UTC, DreadKyller 
wrote:
My question is about overloading, several operators can be 
overloaded in D, one of the ones that can't apparently is the 
address of operator (). My question is have I simply 
missed it or does it actually not exist, and if it's not 
overloadable, is there any reason why this was decided? 
Because there's been numerous times that it'd be useful to 
me, just recently with how much I use the operator because of 
OpenGL I decided to ask.


My answer is that & is a defined operation on all addressable 
memory. Unlike other operators which don't exist until you 
"overload" them.


Yes but the dereference operator can be overloaded. The 
reasoning doesn't stand, unless that's recognized as an 
inconsistency.


Except that no it actually doesn't. The Unary operator * doesn't 
overload the dereferencing of a pointer, take the following code:


class Test
{
Test opUnary(string s)() if (s == "*")
{
writeln("Overloaded operator called");
return this;
}
}
void testFunc()
{
Test test = new Test();
Test* test_ptr = 
writeln("== *test ==");
Test other = *test;
writeln("== *test_ptr ==");
other = *test_ptr;
writeln("== end ==");
}

This outputs:

== *test ==
Overloaded operator called
== *test_ptr ==
== end ==

Notice how dereferencing the pointer did not call the overloaded 
function, because a pointer to Test is not the same type as a 
Test.


Re: Should we add `a * b` for vectors?

2017-09-27 Thread Manu via Digitalmars-d
On 27 September 2017 at 17:41, Ilya Yaroshenko via Digitalmars-d <
digitalmars-d@puremagic.com> wrote:

> On Wednesday, 27 September 2017 at 04:59:10 UTC, Manu wrote:
>
>> On 26 September 2017 at 21:41, Atila Neves via Digitalmars-d <
>> digitalmars-d@puremagic.com> wrote:
>>
>> On Friday, 22 September 2017 at 17:11:56 UTC, Ilya Yaroshenko wrote:
>>>
>>> Should we add `a * b` to ndslice for 1d vectors?
 Discussion at https://github.com/libmir/mir-algorithm/issues/91


>>> I'd say yes.
>>>
>>> Atila
>>>
>>>
>>
>> Just remember, it's okay to vote no! Even if it makes you a bigoted dick
>> ;)
>> In this case, I think 'no' is the only reasonable choice.
>> If this is going to seriously be considered, then ndslice should
>> definitely
>> be renamed to 'matrix'.
>>
>> An alternative solution might be to introduce a wrapper of ndslice called
>> 'matrix' that supports matrix mul...?
>>
>
> I would prefer outer operator overloading be added to D instead of type
> wrappers. So a user can import a library for operations, rather then
> library of wrappers. --Ilya
>

I don't really think this will work in a reasonable way in D even if it
were added.
D does not have ADL, which will almost certainly lead to _very_ nasty
surprises in behaviour.


Re: Should we add `a * b` for vectors?

2017-09-27 Thread Manu via Digitalmars-d
On 27 September 2017 at 22:01, jmh530 via Digitalmars-d <
digitalmars-d@puremagic.com> wrote:

> On Wednesday, 27 September 2017 at 07:41:23 UTC, Ilya Yaroshenko wrote:
>
>>
>> I would prefer outer operator overloading be added to D instead of type
>> wrappers. So a user can import a library for operations, rather then
>> library of wrappers. --Ilya
>>
>
> This might be a step in the right direction. It doesn't need to be
> full-blown extension methods/partial classes. Just the ability to treat
> operator overloading like free-standing functions (with power of UFCS).
> Something like:
>
> struct Foo
> {
> int data;
> }
>
> Foo opBinary!(string op)(Foo x, Foo y)
> {
> return mixin("x.data" ~ op ~ "y.data");
> }
>
> That would mean you could also do something like:
> import lubeck : opBinary;
>

Again, sadly, D has no ADL, and this will be an unmitigated disaster as a
result!
Instantiations of templates will use the default elementwise operator
instead of the one you specified in your module, and nobody will understand
why.


Re: Silicon Valley D Meetup - September 28, 2017 - "Open Methods: From C++ to D" by Jean-Louis Leroy

2017-09-27 Thread Ali Çehreli via Digitalmars-d-announce

On 09/26/2017 09:27 PM, Ali Çehreli wrote:

> As always, I will post the Google Meet link here.

The Google Meet link is (will be)

  https://meet.google.com/zie-vuec-jao

but the meeting is in about 26 hours from this posting. You may want to 
make sure Google Meet works with your browser; I had to install Google 
Chrome.


Ali



Re: Is it possible to specify the address returned by the address of operator?

2017-09-27 Thread user1234 via Digitalmars-d-learn
On Wednesday, 27 September 2017 at 21:01:36 UTC, Jesse Phillips 
wrote:
On Wednesday, 27 September 2017 at 16:35:54 UTC, DreadKyller 
wrote:
My question is about overloading, several operators can be 
overloaded in D, one of the ones that can't apparently is the 
address of operator (). My question is have I simply 
missed it or does it actually not exist, and if it's not 
overloadable, is there any reason why this was decided? 
Because there's been numerous times that it'd be useful to me, 
just recently with how much I use the operator because of 
OpenGL I decided to ask.


My answer is that & is a defined operation on all addressable 
memory. Unlike other operators which don't exist until you 
"overload" them.


Yes but the dereference operator can be overloaded. The reasoning 
doesn't stand, unless that's recognized as an inconsistency.


[Issue 13568] Support compile-time format strings in std.format

2017-09-27 Thread d-bugmail--- via Digitalmars-d-bugs
https://issues.dlang.org/show_bug.cgi?id=13568

--- Comment #11 from b2.t...@gmx.com ---
There's https://issues.dlang.org/show_bug.cgi?id=17381 that could be handled
the day std.format will be refact.

The strategy used to check statically the specifier (call format() and look if
there's been an exception) makes it impossible to fix.

--


[Issue 17381] Checked format string is permissive after floating point argument

2017-09-27 Thread d-bugmail--- via Digitalmars-d-bugs
https://issues.dlang.org/show_bug.cgi?id=17381

b2.t...@gmx.com changed:

   What|Removed |Added

 CC||b2.t...@gmx.com
 OS|Linux   |All

--


Re: What does ! mean?

2017-09-27 Thread Arun Chandrasekaran via Digitalmars-d-learn
On Wednesday, 27 September 2017 at 14:34:06 UTC, Eugene Wissner 
wrote:
On Wednesday, 27 September 2017 at 14:23:01 UTC, Ky-Anh Huynh 
wrote:




See also the following chapter in Ali's book:
http://ddili.org/ders/d.en/templates.html


This chapter is what hooked me with D. Naming that chapter as 
"Templates for Human Beings" won't be an exaggeration.


[Issue 17857] T.alignof ignores explicit align(N) type alignment

2017-09-27 Thread d-bugmail--- via Digitalmars-d-bugs
https://issues.dlang.org/show_bug.cgi?id=17857

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

https://github.com/dlang/dmd/commit/9e3fad9ea3e955b10ec80439247e50fc9417f77d
T.alignof: Respect explicit align(N) type alignment

It was previously the natural type alignment, defined as the maximum of
the field alignments for an aggregate. Make sure an explicit `align(N)`
overrides it.

fix Issue 17857

https://github.com/dlang/dmd/commit/30f0fe23961a194c9789ab32368ef50b4257c0dd
Merge pull request #7164 from kinke/alignof

fix Issue 17857 - T.alignof ignores explicit align(N) type alignment

--


Re: I need runtime reflection

2017-09-27 Thread Jordan Wilson via Digitalmars-d
On Wednesday, 27 September 2017 at 20:03:27 UTC, Gheorghe Gabriel 
wrote:

Hi,

I have a 3D scene editor.
I need my scripts to be dynamically loaded in the scene.
In c# or java I can use reflections to do that.
How can I do that with D?
I know that std.traits only works in compile time.
Please, help me

Gabriel


I've used a reflection library called witchcraft which might be 
helpful to you.
For script execution, I like LuaD, might be worth checking out 
also.


Jordan



Re: What does ! mean?

2017-09-27 Thread Mengu via Digitalmars-d-learn
On Wednesday, 27 September 2017 at 17:58:27 UTC, Ali Çehreli 
wrote:

On 09/27/2017 08:33 AM, Ky-Anh Huynh wrote:
> [...]
Wissner wrote:
> [...]

The fact that such an important operator is explained so late 
in the book is due to the book's strong desire to have a linear 
flow.


[...]


ustad, guess you can still write the new ed. :-)



Re: What does ! mean?

2017-09-27 Thread Ali Çehreli via Digitalmars-d-learn

On 09/27/2017 03:06 PM, Mengu wrote:


ustad, guess you can still write the new ed. :-)


Since you're still around, one of these days... :)

Ali



Re: Is it possible to specify the address returned by the address of operator?

2017-09-27 Thread DreadKyller via Digitalmars-d-learn

On Wednesday, 27 September 2017 at 21:18:50 UTC, nkm1 wrote:
On Wednesday, 27 September 2017 at 20:24:24 UTC, DreadKyller 
wrote:
The attitude of "some people use this feature incorrectly, so 
let's ban it's use entirely" is honestly ridiculous to me, but 
oh well, that's apparently the modern philosophy.


Not even modern, see Java :) ("I left out operator overloading 
as a fairly personal choice because I had seen too many people 
abuse it in C++." - James Gosling)


Oh don't get me wrong, I'm not saying that not allowing operator 
overloading is new, and Java doesn't allow any, like at all, 
compared to D just not allowing a handful. And I wasn't referring 
to operator overloading specifically, I was talking in general 
about how it's become more common with modern languages to try 
being overly safe, in attempt to prevent users from making 
mistakes. It's not that it's particularly problematic, but it 
does tend to make some more recent languages far more verbose and 
tedious to type. This philosophy has existed since very early on, 
it's just become more common in the last decade or so. I just 
disagree with the concept, I just happen to feel that had the 
effort that was put into the philosophy and design of making 
things safer had been put into educating and developing better 
tools and resources then the need for such restrictions would be 
less essential. In general I feel D has a good balance of this, 
there are restrictions that I dislike, but can work around them 
because or the benefits of the language, despite what I see as 
several flaws in the design personally, it's still currently my 
favorite language.


Also off-topic slightly, but am I the only one with massive 
latency on this site? It took like almost 2 minutes from me 
hitting reply before this page showed up, and my last few posts 
took like a minute to post, and all other sites I've been to 
don't have that problem, is that a problem with the site or am I 
the only one with this issue?


Re: Allocating byte aligned array

2017-09-27 Thread timvol via Digitalmars-d-learn
On Wednesday, 27 September 2017 at 21:44:48 UTC, Ali Çehreli 
wrote:

On 09/27/2017 02:39 PM, timvol wrote:

[...]


void main() {
auto mem = new ubyte[1024+15];
auto ptr = cast(ubyte*)(cast(ulong)(mem.ptr + 15) & 
~0x0FUL);

auto arr = ptr[0..1024];
}

Ali


Works perfect. Thank you!


Re: Allocating byte aligned array

2017-09-27 Thread Ali Çehreli via Digitalmars-d-learn

On 09/27/2017 02:39 PM, timvol wrote:

Hi guys,
how can I allocate an (e.g. 16) byte aligned array?
In C I can do the following:

void *mem = malloc(1024+15);
void *ptr = ((uintptr_t)mem+15) & ~ (uintptr_t)0x0F;
memset_16aligned(ptr, 0, 1024);
free(mem);

I think in D it looks similar to this:

auto mem = new ubyte[1024+15];
auto ptr = (mem.ptr + 15) & ~ (...???...) 0x0F;

How to fill ...???... ?
Without a cast, the compiler tells me that I the types are incompatible
(ubyte* and int).

What's the correct syntax here?

PS: I don't want to use the experimental branch that provides
alignedAllocate().


void main() {
auto mem = new ubyte[1024+15];
auto ptr = cast(ubyte*)(cast(ulong)(mem.ptr + 15) & ~0x0FUL);
auto arr = ptr[0..1024];
}

Ali



Allocating byte aligned array

2017-09-27 Thread timvol via Digitalmars-d-learn

Hi guys,
how can I allocate an (e.g. 16) byte aligned array?
In C I can do the following:

void *mem = malloc(1024+15);
void *ptr = ((uintptr_t)mem+15) & ~ (uintptr_t)0x0F;
memset_16aligned(ptr, 0, 1024);
free(mem);

I think in D it looks similar to this:

auto mem = new ubyte[1024+15];
auto ptr = (mem.ptr + 15) & ~ (...???...) 0x0F;

How to fill ...???... ?
Without a cast, the compiler tells me that I the types are 
incompatible (ubyte* and int).


What's the correct syntax here?

PS: I don't want to use the experimental branch that provides 
alignedAllocate().


Re: Is it possible to specify the address returned by the address of operator?

2017-09-27 Thread nkm1 via Digitalmars-d-learn
On Wednesday, 27 September 2017 at 20:24:24 UTC, DreadKyller 
wrote:
The attitude of "some people use this feature incorrectly, so 
let's ban it's use entirely" is honestly ridiculous to me, but 
oh well, that's apparently the modern philosophy.


Not even modern, see Java :) ("I left out operator overloading as 
a fairly personal choice because I had seen too many people abuse 
it in C++." - James Gosling)


Re: Compile-time reflection and templates

2017-09-27 Thread Jean-Louis Leroy via Digitalmars-d

On Wednesday, 27 September 2017 at 20:04:42 UTC, jmh530 wrote:
On Wednesday, 27 September 2017 at 19:47:32 UTC, Jean-Louis 
Leroy wrote:


I'd like to go further: find the template arguments and the 
function arguments and return types. Looking at __traits and 
std.traits, it doesn't seem feasible, but maybe I overlooked 
something?


You can use TemplateArgsOf
https://dlang.org/phobos/std_traits.html#TemplateArgsOf
to get the template arguments.

For the stuff below, I think you can't just use foo, it has to 
be a specific foo!T.


You can test if it's a function
https://dlang.org/phobos/std_traits.html#isFunction

You can get the Parameter and Return types
https://dlang.org/phobos/std_traits.html#Parameters
https://dlang.org/phobos/std_traits.html#ReturnType

You can get the names of parameters
https://dlang.org/phobos/std_traits.html#ParameterIdentifierTuple


I am aware of these but TemplateArgsOf takes a template 
*instantiation* and returns the arguments. I want to reflect the 
*template*.


Here what I am trying to achieve (for openmethods). Given:

  Matrix!T times(T, virtual!(Matrix!T));

...inject, at compile time (in 'mixin(registerMethods)'), the 
following code:


  Matrix!T times(T)(T s, Matrix!T m) {
return Method!("times", "deallocator", Matrix!T, T, 
virtual!(Matrix!T)).dispatcher(s, m);

  }

  Method!("times", "deallocator", Matrix!T, T, 
virtual!(Matrix!T)) times(T)(MethodTag, T s, Matrix!T m);






Re: Is it possible to specify the address returned by the address of operator?

2017-09-27 Thread DreadKyller via Digitalmars-d-learn
On Wednesday, 27 September 2017 at 21:01:36 UTC, Jesse Phillips 
wrote:
For example, if you store your Matrix in a custom container it 
could try to store pointer rather than the struct itself, if & 
is overloaded the generic implementation would be broken 
because it would no longer be a pointer to Matrix but to the 
inner element.


Whereas generic code which utilizes addition or append can 
assume the type appropriately defined the behavior to 
semantically match the desired use, generic code would be 
broken if the type changed & to do something different from 
what the language defines it to do.


Alright, that makes sense, that's some valid reasoning, I can 
accept that.


[Issue 17085] Documentation for all traits under SomethingTypeOf missing

2017-09-27 Thread d-bugmail--- via Digitalmars-d-bugs
https://issues.dlang.org/show_bug.cgi?id=17085

b2.t...@gmx.com changed:

   What|Removed |Added

Summary|[std.traits] Documentation  |Documentation for all
   |for all traits under|traits under
   |SomethingTypeOf missing |SomethingTypeOf missing

--


Re: Is it possible to specify the address returned by the address of operator?

2017-09-27 Thread Jesse Phillips via Digitalmars-d-learn
On Wednesday, 27 September 2017 at 16:35:54 UTC, DreadKyller 
wrote:
My question is about overloading, several operators can be 
overloaded in D, one of the ones that can't apparently is the 
address of operator (). My question is have I simply 
missed it or does it actually not exist, and if it's not 
overloadable, is there any reason why this was decided? Because 
there's been numerous times that it'd be useful to me, just 
recently with how much I use the operator because of OpenGL I 
decided to ask.


My answer is that & is a defined operation on all addressable 
memory. Unlike other operators which don't exist until you 
"overload" them.


For example, if you store your Matrix in a custom container it 
could try to store pointer rather than the struct itself, if & is 
overloaded the generic implementation would be broken because it 
would no longer be a pointer to Matrix but to the inner element.


Whereas generic code which utilizes addition or append can assume 
the type appropriately defined the behavior to semantically match 
the desired use, generic code would be broken if the type changed 
& to do something different from what the language defines it to 
do.


Re: std.reflection prototype

2017-09-27 Thread Gheorghe Gabriel via Digitalmars-d

On Monday, 30 March 2015 at 01:11:55 UTC, bitwise wrote:
I came across this post a while back and decided to implement 
it:

http://forum.dlang.org/thread/juf7sk$16rl$1...@digitalmars.com

My implementation:
https://github.com/bitwise-github/D-Reflection

The above conversation seemed to stop abruptly, so I went on to 
assume that no one chose to champion the task.


At the time, I looked around for other conversations or 
attempts at runtime reflection for D, but couldn't really find 
anything. I did find the ModuleInfo/reflection stuff in 
object.d, but it seemed like an effort that may have been 
abandoned. Also, the above conversation seemed to suggest it 
should be opt-in, which also made me wonder if the stuff in 
object.d was abandoned or for a different purpose.


Looking again today, someone seems to have been working on it a 
bit.. For example, MemberInfo_field and MemberInfo_function 
were empty last time I checked.


So what's the current state of things?
Is anybody working on it?

Although MemberInfo_field exists, it doesn't seem to be 
available from TypeInfo_Class... Is that the eventual goal?


Is there anything I can do to help get things moving?


Any comments on my implementation would be welcome as well.
(https://github.com/bitwise-github/D-Reflection)

main.d shows some general use cases, but basically, if the 
reflect(T) template is used on a class,
that class, and any child types will be reflected. Recursive 
reflection only propagates downward, or else it could leak 
sideways and unnecessarily reflect several modules.


Most of the reflection information is available at compile 
time. For example:


enum name = 
reflectModule!(test).findClass("Test").findField("variable").name;

pragma(msg, name); // "variable" will be outputted.

To make a module available for runtime reflection, the 
following can be used:

mixin(runtimeReflection!test);

At this point, the above example can be rewritten as:

string name = 
getModuleReflection("tests.test").findClass("Test3").findField("static_variable").name;

writeln(name);


Hi, your link is not working any more and I really need your 
implementation.

Gabriel


Re: goinsu - Switch user, group and execute a program - a tiny betterC program

2017-09-27 Thread Anton Fediushin via Digitalmars-d-announce

On Wednesday, 27 September 2017 at 12:49:16 UTC, jamonahn wrote:
On Saturday, 16 September 2017 at 19:56:14 UTC, Anton Fediushin 
wrote:
Hey-hey-hey, I am so excited to announce a brand-new program I 
just wrote: goinsu!


Just built on my Raspberry Pi 3.  Kudos - very fast, not even a 
warning!  Now to get some Docker images and go crazy.


Hooray!



BTW, I got a 14,116 byte executable image with LDC but 
1,958,892 with GDC.  The GDC image (stripped) is 324,492.  I 
installed reggae on my laptop (debian) and did a "reggae 
--export".  Then using make (with ldc2) I got image of 13,088.  
Using "dub -b release --compiler=ldc2" (same build as on 
Raspbian) I get image of 381,928.


Reggae builds goinsu in betterC mode, which removes dependency on 
the druntime and phobos.


Dub can also build betterC programs, but I decided not to add 
such flag to dub.json, because betterC is a new thing which can 
cause problems.


LDC and GDC could have very limited betterC support, so results 
may vary.


How do I do a static linkage using LDC?  I need a static 
because I want to try and run this with an Alpine (arm) Docker 
image and Alpine is using muslib-c.  I once built an Alpine 
Docker image by hand that built ldc, but it couldn't survive D 
version/Alpine Os updates.


You don't have to compile LDC for this. It is possible to compile 
a static musl and link it together with the goinsu. Take a look 
at `.travis.yml`, since this is exactly what I am doing to build 
releases.


Also, do not forget the `errnofix.c`, which is important for 
static linking.


Reggae does this automatically, you just have to specify static 
libc you want to link to. Maybe it won't work for RPi though.


I've ordered Raspberry Pi recently, so as soon as I get it I can 
start hacking on it as well)




Thank you so much for this tool!


You're welcome!




Re: Is it possible to specify the address returned by the address of operator?

2017-09-27 Thread DreadKyller via Digitalmars-d-learn

On Wednesday, 27 September 2017 at 19:55:07 UTC, nkm1 wrote:
On Wednesday, 27 September 2017 at 16:35:54 UTC, DreadKyller 
wrote:
Been using D for a couple years now, however one problem I've 
had, more so recently since I've been dealing a lot with 
OpenGL is related to pointers.


I have a matrix object to aid with the matrix math required 
for working with 3D transforms. However OpenGL (I'm using 
DerelictGL3 bindings) requires pointers to the data. I am 
currently doing the following:


Matrix!float ortho(float l, float r, float b, float t, float 
f, float n = -1)

{
Matrix!float oMat = identity(); // Get default Identity Matrix

oMat[0,0] =  2 / (r - l);
oMat[1,1] =  2 / (t - b);
oMat[2,2] = -2 / (f - n);

oMat[3] = [-(r+l)/(r-l), -(t+b)/(t-b), -(f+n)/(f-n), 1];

return oMat;
}

And then to use with OpenGL (passing as uniform into shader):

glUniformMatrix4fv(transform_uniform, 1, GL_FALSE, matrix.addr 
);


where addr is a property that returns the address of the first 
item in the Matrix's internal data. I know I can also use 
[0][0]


My question is about overloading, several operators can be 
overloaded in D, one of the ones that can't apparently is the 
address of operator (). My question is have I simply 
missed it or does it actually not exist, and if it's not 
overloadable, is there any reason why this was decided? 
Because there's been numerous times that it'd be useful to me, 
just recently with how much I use the operator because of 
OpenGL I decided to ask.


& is not overloadable, presumably because some people were 
annoyed by abuse of operator overloading in C++. The reason is 
to improve readability (of other people's code).
Just rename matrix.addr to matrix.ptr... like in arrays: 
https://dlang.org/spec/arrays.html#array-properties
That would be clearer (opinion), since the reader of your code 
can assume that matrix.ptr does the same thing with your matrix 
as array.ptr does with arrays. OTOH, overloading  to do 
something different from built in  seems like a 
pointless obfuscation to me.


I mean to an extent I agree, but I moved from using GLfloat 
arrays for matrix's to a Matrix object to aid in Matrix math like 
multiplication, so I have to go through my code and in many 
places change it to using matrix.ptr, considering that I have to 
do this for every object in a scene multiple times for the 
translation, scale, projection and etc matrix's it's more 
tedious, and I'm the only one working on the code and I comment 
and document my code a lot. If one thing annoys m e about 
language design, it's when peoples actions dictate the decisions 
of the language, it shouldn't be the responsibility of the 
language to limit users in order to prevent bad habits or 
practices, it should be the responsibility of education to do so. 
The attitude of "some people use this feature incorrectly, so 
let's ban it's use entirely" is honestly ridiculous to me, but oh 
well, that's apparently the modern philosophy.


Re: Compile-time reflection and templates

2017-09-27 Thread jmh530 via Digitalmars-d
On Wednesday, 27 September 2017 at 19:47:32 UTC, Jean-Louis Leroy 
wrote:


I'd like to go further: find the template arguments and the 
function arguments and return types. Looking at __traits and 
std.traits, it doesn't seem feasible, but maybe I overlooked 
something?


You can use TemplateArgsOf
https://dlang.org/phobos/std_traits.html#TemplateArgsOf
to get the template arguments.

You can test if it's a function
https://dlang.org/phobos/std_traits.html#isFunction

You can get the Parameter and Return types
https://dlang.org/phobos/std_traits.html#Parameters
https://dlang.org/phobos/std_traits.html#ReturnType

You can get the names of parameters
https://dlang.org/phobos/std_traits.html#ParameterIdentifierTuple


I need runtime reflection

2017-09-27 Thread Gheorghe Gabriel via Digitalmars-d

Hi,

I have a 3D scene editor.
I need my scripts to be dynamically loaded in the scene.
In c# or java I can use reflections to do that.
How can I do that with D?
I know that std.traits only works in compile time.
Please, help me

Gabriel


Re: Compile-time reflection and templates

2017-09-27 Thread jmh530 via Digitalmars-d
On Wednesday, 27 September 2017 at 19:47:32 UTC, Jean-Louis Leroy 
wrote:


I'd like to go further: find the template arguments and the 
function arguments and return types. Looking at __traits and 
std.traits, it doesn't seem feasible, but maybe I overlooked 
something?


You can use TemplateArgsOf
https://dlang.org/phobos/std_traits.html#TemplateArgsOf
to get the template arguments.

For the stuff below, I think you can't just use foo, it has to be 
a specific foo!T.


You can test if it's a function
https://dlang.org/phobos/std_traits.html#isFunction

You can get the Parameter and Return types
https://dlang.org/phobos/std_traits.html#Parameters
https://dlang.org/phobos/std_traits.html#ReturnType

You can get the names of parameters
https://dlang.org/phobos/std_traits.html#ParameterIdentifierTuple


Re: Is it possible to specify the address returned by the address of operator?

2017-09-27 Thread nkm1 via Digitalmars-d-learn
On Wednesday, 27 September 2017 at 16:35:54 UTC, DreadKyller 
wrote:
Been using D for a couple years now, however one problem I've 
had, more so recently since I've been dealing a lot with OpenGL 
is related to pointers.


I have a matrix object to aid with the matrix math required for 
working with 3D transforms. However OpenGL (I'm using 
DerelictGL3 bindings) requires pointers to the data. I am 
currently doing the following:


Matrix!float ortho(float l, float r, float b, float t, float f, 
float n = -1)

{
Matrix!float oMat = identity(); // Get default Identity Matrix

oMat[0,0] =  2 / (r - l);
oMat[1,1] =  2 / (t - b);
oMat[2,2] = -2 / (f - n);

oMat[3] = [-(r+l)/(r-l), -(t+b)/(t-b), -(f+n)/(f-n), 1];

return oMat;
}

And then to use with OpenGL (passing as uniform into shader):

glUniformMatrix4fv(transform_uniform, 1, GL_FALSE, matrix.addr 
);


where addr is a property that returns the address of the first 
item in the Matrix's internal data. I know I can also use 
[0][0]


My question is about overloading, several operators can be 
overloaded in D, one of the ones that can't apparently is the 
address of operator (). My question is have I simply 
missed it or does it actually not exist, and if it's not 
overloadable, is there any reason why this was decided? Because 
there's been numerous times that it'd be useful to me, just 
recently with how much I use the operator because of OpenGL I 
decided to ask.


& is not overloadable, presumably because some people were 
annoyed by abuse of operator overloading in C++. The reason is to 
improve readability (of other people's code).
Just rename matrix.addr to matrix.ptr... like in arrays: 
https://dlang.org/spec/arrays.html#array-properties
That would be clearer (opinion), since the reader of your code 
can assume that matrix.ptr does the same thing with your matrix 
as array.ptr does with arrays. OTOH, overloading  to do 
something different from built in  seems like a pointless 
obfuscation to me.


Compile-time reflection and templates

2017-09-27 Thread Jean-Louis Leroy via Digitalmars-d

I can identify the templates in a module:

  module modtemp;

  import std.stdio;
  import std.traits;

  void foo(T)(T x) {}

  void main()
  {
foreach (m; __traits(allMembers, modtemp)) {
  if (__traits(isTemplate, mixin(m))) {
mixin("alias F = " ~ m ~ ";");
writeln(m);
  }
}
  }
  // output:
  // foo

I'd like to go further: find the template arguments and the 
function arguments and return types. Looking at __traits and 
std.traits, it doesn't seem feasible, but maybe I overlooked 
something?






[Issue 17860] some code exaples from site doesn't build on Visual Studio 2010 (and probably at all)

2017-09-27 Thread d-bugmail--- via Digitalmars-d-bugs
https://issues.dlang.org/show_bug.cgi?id=17860

greenify  changed:

   What|Removed |Added

 CC||greeen...@gmail.com

--- Comment #2 from greenify  ---
All examples (aka D unittests) are automatically tested with every PR on
multiple CIs (even Windows), so chances are it's a problem on your side.
What setup to you use? Which D compiler? 
What error messages do you see?

--


Inter-module symbol resolution error of template type-parameter when using mixins

2017-09-27 Thread Nordlöw via Digitalmars-d-learn

At

https://github.com/nordlow/phobos-next/blob/03b4736fdd65ef84c6fc583eddee4196629cea81/src/variant_arrays.d

I've implemented a lightweight-polymorphic array container I call 
`VariantArrays(Types...)` indexed by a corresponding polymorphic 
index I call `VariantIndex(Types...)`.


It uses `.mangleof` together with mixins to automatically infer 
the definition (including its name) of each array store for each 
element type in `Types`. The element types are passed in the 
template parameter `Types` to the two templated structs mentioned 
above.


Everything works except for when I try to instantiate 
`VariantArrays` from within a module other than 
`variant_arrays.d`. For instance, if I try to use it another 
module containing


unittest
{
struct S { int x; }
import variant_arrays : VariantArrays;
VariantArrays!S a;
}

I get the error

variant_arrays.d-mixin-130(130,1): Error: undefined identifier `S`
foo.d(5,5): Error: template instance 
variant_arrays.VariantArrays!(S) error instantiating


In other words, the symbol `S` cannot be resolved in the scope of 
`VariantArrays` eventhough it's feed as a template parameter.


Is there a way around this problem?

Here follows the definition of variant_arrays.d (excluding 
unittests):


/** Polymorphic index into an element in `VariantArrays`. */
private struct VariantIndex(Types...)
{
import std.meta : staticIndexOf;
private:
alias Kind = ubyte;  // kind code
alias Size = size_t; // size type

import bit_traits : bitsNeeded;

/// Number of bits needed to represent kind.
enum kindBits = bitsNeeded!(Types.length);

/// Get number kind of kind type `SomeKind`.
enum nrOfKind(SomeKind) = staticIndexOf!(SomeKind, Types); // 
TODO cast to ubyte if Types.length is <= 256


/// Is `true` iff an index to a `SomeKind`-kind can be stored.
enum canReferTo(SomeKind) = nrOfKind!SomeKind >= 0;

/// Construct.
this(Kind kind, Size index) // TODO can ctor inferred by 
bitfields?

{
_kindNr = kind;
_index = index;
}

import std.bitmanip : bitfields;
mixin(bitfields!(Size, "_index", 8*Size.sizeof - kindBits,
 Kind, "_kindNr", kindBits));
}

/** Stores set of variants.

Enables lightweight storage of polymorphic objects.

Each element is indexed by a corresponding `VariantIndex`.
 */
private struct VariantArrays(Types...)
{
alias Index = VariantIndex!Types;

import basic_copyable_array : CopyableArray;

/// Returns: array type (as a string) of `Type`.
private static immutable(string) arrayTypeString(Type)()
{
return `CopyableArray!(` ~ Type.stringof ~ `)`;
}

/// Returns: array instance (as a strinng) storing `Type`.
private static immutable(string) arrayInstanceString(Type)()
{
return `_values` ~ Type.mangleof;
}

/** Insert `value` at back.
 */
pragma(inline) // DMD cannot 
inline
Index insertBack(SomeKind)(SomeKind value) // TODO add array 
type overload

if (Index.canReferTo!SomeKind)
{
mixin(`alias arrayInstance = ` ~ 
arrayInstanceString!SomeKind ~ `;`);

const currentIndex = arrayInstance.length;
arrayInstance.insertBack(value);
return Index(Index.nrOfKind!SomeKind,
 currentIndex);
}
alias put = insertBack; // polymorphic `OutputRange` 
support


/// Get reference to element of type `SomeKind` at `index`.
scope ref inout(SomeKind) at(SomeKind)(in size_t index) inout 
return

if (Index.canReferTo!SomeKind)
{
mixin(`return ` ~ arrayInstanceString!SomeKind ~ 
`[index];`);

}

/// Peek at element of type `SomeKind` at `index`.
scope inout(SomeKind)* peek(SomeKind)(in Index index) inout 
return @system

if (Index.canReferTo!SomeKind)
{
if (Index.nrOfKind!SomeKind == index._kindNr)
{
return !SomeKind(index._index);
}
else
{
return null;
}
}

private:
// TODO this fails:
mixin({
string s = "";
foreach (Type; Types)
{
s ~= arrayTypeString!Type ~ ` ` ~ 
arrayInstanceString!Type ~ `;`;

}
return s;
}());
}



Re: What does ! mean?

2017-09-27 Thread Ali Çehreli via Digitalmars-d-learn

On 09/27/2017 08:33 AM, Ky-Anh Huynh wrote:
> On Wednesday, 27 September 2017 at 14:34:06 UTC, Eugene Wissner wrote:
>>
>> See also the following chapter in Ali's book:
>> http://ddili.org/ders/d.en/templates.html
>
> Thanks a lot. I will keep reading :)

The fact that such an important operator is explained so late in the 
book is due to the book's strong desire to have a linear flow.


Although binary ! appears before the templates chapter as to!int, 
format!"%s", etc., I decided to get to templates only after going 
through everything that could be templatized. (For example, even 
interfaces can be templates.) I don't claim this is the best choice but 
I'm happy that some people said that they found the linear flow useful. 
(I know that others would find it boring. :) )


If I were to write the book again, one other thing that I would explain 
earlier would be UFCS, and I would use much more of it in the examples. 
(UFCS was added to the language after I wrote most of the book.)


Ali



Is it possible to specify the address returned by the address of operator?

2017-09-27 Thread DreadKyller via Digitalmars-d-learn
Been using D for a couple years now, however one problem I've 
had, more so recently since I've been dealing a lot with OpenGL 
is related to pointers.


I have a matrix object to aid with the matrix math required for 
working with 3D transforms. However OpenGL (I'm using DerelictGL3 
bindings) requires pointers to the data. I am currently doing the 
following:


Matrix!float ortho(float l, float r, float b, float t, float f, 
float n = -1)

{
Matrix!float oMat = identity(); // Get default Identity Matrix

oMat[0,0] =  2 / (r - l);
oMat[1,1] =  2 / (t - b);
oMat[2,2] = -2 / (f - n);

oMat[3] = [-(r+l)/(r-l), -(t+b)/(t-b), -(f+n)/(f-n), 1];

return oMat;
}

And then to use with OpenGL (passing as uniform into shader):

glUniformMatrix4fv(transform_uniform, 1, GL_FALSE, matrix.addr );

where addr is a property that returns the address of the first 
item in the Matrix's internal data. I know I can also use 
[0][0]


My question is about overloading, several operators can be 
overloaded in D, one of the ones that can't apparently is the 
address of operator (). My question is have I simply 
missed it or does it actually not exist, and if it's not 
overloadable, is there any reason why this was decided? Because 
there's been numerous times that it'd be useful to me, just 
recently with how much I use the operator because of OpenGL I 
decided to ask.


Re: Can I skip sub directories with file.dirEntries() ?

2017-09-27 Thread Ky-Anh Huynh via Digitalmars-d-learn
On Wednesday, 27 September 2017 at 10:05:34 UTC, Nicholas Wilson 
wrote:




I'd just use dirEntries with SpanMode.shallow in combination 
with filter either in a loop or a recursive function like below.


void foo(string path = "path")
{
foreach(e; 
dirEntries(path,SpanMode.shallow).filter!(myCritreia(paramters)))

{
if (e. isDir)
foo(e.name); // recurse
// do other stuff
}
}

you will loop over all subdirs of "path" that satisfy 
`myCritreia`.


Thank you Nicolas. It's a good idea.

PS: With Linux find command, the thing can be done easily with 
`-prune` option:


```
find . -iname node_modules -prune
```

Without `-prune` option, there are a lot of unnecessary sub 
directories...


Re: What does ! mean?

2017-09-27 Thread Gary Willoughby via Digitalmars-d-learn
On Wednesday, 27 September 2017 at 14:23:01 UTC, Ky-Anh Huynh 
wrote:
Can you please explain and give any link where I can learn more 
about these things?


Thanks a lot.


http://nomad.so/2013/07/templates-in-d-explained/


Re: What does ! mean?

2017-09-27 Thread Ky-Anh Huynh via Digitalmars-d-learn
On Wednesday, 27 September 2017 at 14:34:06 UTC, Eugene Wissner 
wrote:


See also the following chapter in Ali's book:
http://ddili.org/ders/d.en/templates.html


Thanks a lot. I will keep reading :)



Re: DlangIDE v0.8.0 released

2017-09-27 Thread bitwise via Digitalmars-d-announce
On Wednesday, 27 September 2017 at 13:22:20 UTC, Vadim Lopatin 
wrote:

On Tuesday, 26 September 2017 at 22:35:09 UTC, bitwise wrote:
On Tuesday, 26 September 2017 at 15:20:54 UTC, Vadim Lopatin 
wrote:

New DlangIDE version is released.


I've only had time to take a quick look, but this IDE seems 
pretty good. I was surprised at how fast it loaded up, and how 
it downloaded the dependencies for the sample project on it's 
own.


The text rendering needs work though. Honestly, I passed this 
editor up the first time I came across it because of the way 
the text looks. It reminds me of Visual Studio 2005. I 
couldn't help but assume the IDE was outdated and probably be 
abandon-ware.


I would definitely change the default font to the platform-IDE 
defaults:


Visual Studio: Consolas
XCode: Menlo Regular

Also, FreeType has made improvements lately, and now does a 
much better job of rendering fonts at small sizes(no so 
blurry). In particular 2.8.1, which just came out, implements 
a patent-free substitute for MS style clear-type 
rendering[1][2].


[1] http://i.imgur.com/nK8Xu.png
[2] 
https://www.freetype.org/freetype2/docs/reference/ft2-base_interface.html#FT_LOAD_TARGET_LCD


The thick bezels and deep 3D shading make it look retro as 
well.


For Windows, added libfreetype 2.8.1 dlls.

Made additional fixes for better font rendering.

Win32 binaries are uploaded to
https://github.com/buggins/dlangide/releases/tag/v0.8.2

To disable freetype, delete libfreetype-6.dll

Consolas/Menlo are already selected if "Default" font is chosen 
for editors.


Hey, thanks!
Looks good.

One small thing though - when you use the LCD/BGR style fonts, 
you get a mismatch between the font metrics and bitmap size.


So if you're using FT_LOAD_TARGET_LCD, then some of these may be 
true:


glyph.bitmap_left != (glyph.metrics.horiBearingX >> 6);
glyph.bitmap_top != (glyph.metrics.horiBearingY >> 6);
glyph.bitmap.width != (glyph.metrics.width >> 6);
glyph.bitmap.rows != (glyph.metrics.height >> 6);

The result could be a crash, clipping, or misalignment of glyphs, 
depending on the assumptions made by your blitting code.


I asked about this on the FT mailing list, and unfortunately, 
they don't believe that the 1 or 2 pixels of padding added to the 
bitmap to accommodate the LCD rendering belongs in metrics.


The fix is simply using bitmap_left, bitmap_top, bitmap.width, 
bitmap.height, instead of the metrics.


I was looking at the commits and saw that you added kerning, so 
was wondering if you hit this problem.





Re: mir-random: major additions

2017-09-27 Thread jmh530 via Digitalmars-d-announce
On Wednesday, 27 September 2017 at 12:21:24 UTC, Ilya Yaroshenko 
wrote:


Thanks! And looking forward to find you PR in Lubeck! --Ilya


It's what prompted eachLower/eachUpper. I was like, there's gotta 
be a pretty way of doing this and got completely distracted from 
cholesky!


Re: What does ! mean?

2017-09-27 Thread Eugene Wissner via Digitalmars-d-learn
On Wednesday, 27 September 2017 at 14:23:01 UTC, Ky-Anh Huynh 
wrote:

Hi,

I am from Ruby world where I can have `!` (or `?`) in method 
names: `!` indicates that a method would modify its object 
(`foo.upcase!` means `foo = foo.upcase`). ( I don't know if 
there is any official Ruby documentation on this convention 
though. )


In D I see `!` quite a lot. I have read the first 50 chapters 
in Ali's book but nowhere I see a note on `!`. It's about the 
compile thing, isn't it? E.g,


```
foo = formattedRead!"%s"(value);
```

But I also see `!` for some map/filter invocations. It's quite 
confusing me.


Can you please explain and give any link where I can learn more 
about these things?


Thanks a lot.


See also the following chapter in Ali's book:
http://ddili.org/ders/d.en/templates.html


Re: What does ! mean?

2017-09-27 Thread rikki cattermole via Digitalmars-d-learn
There are two types of arguments in D. The runtime one (which you are 
well aware of) and the compile time one. A compile time argument is a 
constant passed in during construction of a symbol.


But here is the thing, it isn't just limited to functions, you can have 
it on classes as well.


---
class Foo(bool b) {
bool get() { return b; }
}

void main() {
Foo!true v = new Foo!true;
assert(v.get);
}
---

Same logic going on.

---
bool get(bool b)() {
return b;
}

void main() {
assert(get!true == true);
}
---

It can do more than a simple boolean being passed in, but that is the 
gist. Templates are wonderful (also read the spec!).


Re: Finding class template instantiations via runtime reflection (for openmethods)

2017-09-27 Thread Jacob Carlborg via Digitalmars-d

On 2017-09-26 18:08, Jean-Louis Leroy wrote:

Ah, I suspected that. I don't want to go down that path, what of 
Windows? But thanks anyway...


It's possible to do the same on Windows (using LoadLibrary instead of 
dlopen). You would need to have separate code for each binary format. On 
Windows there are two, OMF used by DigitalMars and COFF used by 
Microsoft. DMD can output both. Linux and FreeBSD use ELF.


--
/Jacob Carlborg


What does ! mean?

2017-09-27 Thread Ky-Anh Huynh via Digitalmars-d-learn

Hi,

I am from Ruby world where I can have `!` (or `?`) in method 
names: `!` indicates that a method would modify its object 
(`foo.upcase!` means `foo = foo.upcase`). ( I don't know if there 
is any official Ruby documentation on this convention though. )


In D I see `!` quite a lot. I have read the first 50 chapters in 
Ali's book but nowhere I see a note on `!`. It's about the 
compile thing, isn't it? E.g,


```
foo = formattedRead!"%s"(value);
```

But I also see `!` for some map/filter invocations. It's quite 
confusing me.


Can you please explain and give any link where I can learn more 
about these things?


Thanks a lot.



Re: DlangIDE v0.8.0 released

2017-09-27 Thread Vadim Lopatin via Digitalmars-d-announce
On Wednesday, 27 September 2017 at 08:00:21 UTC, Traktor Toni 
wrote:
Code completion isnt working for me on windows, no clue what's 
missing.


Did you try Ctrl+Space?


Re: DlangIDE v0.8.0 released

2017-09-27 Thread Vadim Lopatin via Digitalmars-d-announce

On Tuesday, 26 September 2017 at 22:35:09 UTC, bitwise wrote:
On Tuesday, 26 September 2017 at 15:20:54 UTC, Vadim Lopatin 
wrote:

New DlangIDE version is released.


I've only had time to take a quick look, but this IDE seems 
pretty good. I was surprised at how fast it loaded up, and how 
it downloaded the dependencies for the sample project on it's 
own.


The text rendering needs work though. Honestly, I passed this 
editor up the first time I came across it because of the way 
the text looks. It reminds me of Visual Studio 2005. I couldn't 
help but assume the IDE was outdated and probably be 
abandon-ware.


I would definitely change the default font to the platform-IDE 
defaults:


Visual Studio: Consolas
XCode: Menlo Regular

Also, FreeType has made improvements lately, and now does a 
much better job of rendering fonts at small sizes(no so 
blurry). In particular 2.8.1, which just came out, implements a 
patent-free substitute for MS style clear-type rendering[1][2].


[1] http://i.imgur.com/nK8Xu.png
[2] 
https://www.freetype.org/freetype2/docs/reference/ft2-base_interface.html#FT_LOAD_TARGET_LCD


The thick bezels and deep 3D shading make it look retro as well.


For Windows, added libfreetype 2.8.1 dlls.

Made additional fixes for better font rendering.

Win32 binaries are uploaded to
https://github.com/buggins/dlangide/releases/tag/v0.8.2

To disable freetype, delete libfreetype-6.dll

Consolas/Menlo are already selected if "Default" font is chosen 
for editors.




[Issue 11188] std.math.abs fails for shared BigInt type

2017-09-27 Thread d-bugmail--- via Digitalmars-d-bugs
https://issues.dlang.org/show_bug.cgi?id=11188

Simen Kjaeraas  changed:

   What|Removed |Added

 Status|NEW |RESOLVED
 Resolution|--- |WONTFIX

--- Comment #14 from Simen Kjaeraas  ---
True - access to the BigInt would need to be protected somehow, and letting
abs(shared BigInt) simply compile without warning signals to the user that it's
perfectly safe, while tearing could still happen (unsynced ptr/length for the
data field, or wrong sign). The way shared works in D today, it's simply the
wrong choice. Thanks for enlightening me! :)

Closing this issue as wontfix because while important parts of the original
issue are fixed, the current name indicates shared only, and forcing the user
to cast (and thus hopefully think about locking or otherwise limiting access).

--


Re: goinsu - Switch user, group and execute a program - a tiny betterC program

2017-09-27 Thread jamonahn via Digitalmars-d-announce
On Saturday, 16 September 2017 at 19:56:14 UTC, Anton Fediushin 
wrote:
Hey-hey-hey, I am so excited to announce a brand-new program I 
just wrote: goinsu!


Just built on my Raspberry Pi 3.  Kudos - very fast, not even a 
warning!  Now to get some Docker images and go crazy.


BTW, I got a 14,116 byte executable image with LDC but 1,958,892 
with GDC.  The GDC image (stripped) is 324,492.  I installed 
reggae on my laptop (debian) and did a "reggae --export".  Then 
using make (with ldc2) I got image of 13,088.  Using "dub -b 
release --compiler=ldc2" (same build as on Raspbian) I get image 
of 381,928.


How do I do a static linkage using LDC?  I need a static because 
I want to try and run this with an Alpine (arm) Docker image and 
Alpine is using muslib-c.  I once built an Alpine Docker image by 
hand that built ldc, but it couldn't survive D version/Alpine Os 
updates.


Thank you so much for this tool!



Re: DlangIDE v0.8.0 released

2017-09-27 Thread Dmitry via Digitalmars-d-announce
On Wednesday, 27 September 2017 at 08:00:21 UTC, Traktor Toni 
wrote:
The shortcuts should be identical to Visual Studio, anything 
else is a waste of time to learn and configure.
Visual Studio? Why not Vim? Why not Xamarin Studio? Why not IDEA? 
Why not Sublime or tons of other popular configurations? If you 
want Visual Studio, then just use Visual Studio.



The IDE should contain the compiler for convenience

No.


Re: mir-random: major additions

2017-09-27 Thread Ilya Yaroshenko via Digitalmars-d-announce

On Wednesday, 27 September 2017 at 11:52:32 UTC, jmh530 wrote:
On Wednesday, 27 September 2017 at 05:24:50 UTC, Ilya 
Yaroshenko wrote:


private Cholesky decomposition, which has not unittests yet. 
PRs are welcome.




My fork of lubeck has a branch where I was doing some work on 
adding cholesky that has some unittests if you want to borrow 
them (probably needs some adjustments).

https://github.com/jmh530/lubeck/blob/f012582871c0cde8d7dc18d7f833f513a06cfaca/source/lubeck.d#L1377


Thanks! And looking forward to find you PR in Lubeck! --Ilya


Re: Should we add `a * b` for vectors?

2017-09-27 Thread jmh530 via Digitalmars-d
On Wednesday, 27 September 2017 at 07:41:23 UTC, Ilya Yaroshenko 
wrote:


I would prefer outer operator overloading be added to D instead 
of type wrappers. So a user can import a library for 
operations, rather then library of wrappers. --Ilya


This might be a step in the right direction. It doesn't need to 
be full-blown extension methods/partial classes. Just the ability 
to treat operator overloading like free-standing functions (with 
power of UFCS). Something like:


struct Foo
{
int data;
}

Foo opBinary!(string op)(Foo x, Foo y)
{
return mixin("x.data" ~ op ~ "y.data");
}

That would mean you could also do something like:
import lubeck : opBinary;


Sectioned variables?

2017-09-27 Thread Arav Ka via Digitalmars-d-learn
GCC supports a `__attribute((section("...")))` for variables to 
put them in specific sections in the final assembly. Is there any 
way this can be achieved in D? Does GDC support this?


Re: mir-random: major additions

2017-09-27 Thread jmh530 via Digitalmars-d-announce
On Wednesday, 27 September 2017 at 05:24:50 UTC, Ilya Yaroshenko 
wrote:


private Cholesky decomposition, which has not unittests yet. 
PRs are welcome.




My fork of lubeck has a branch where I was doing some work on 
adding cholesky that has some unittests if you want to borrow 
them (probably needs some adjustments).

https://github.com/jmh530/lubeck/blob/f012582871c0cde8d7dc18d7f833f513a06cfaca/source/lubeck.d#L1377


Re: Should we add `a * b` for vectors?

2017-09-27 Thread jmh530 via Digitalmars-d

On Wednesday, 27 September 2017 at 04:59:10 UTC, Manu wrote:


An alternative solution might be to introduce a wrapper of 
ndslice called 'matrix' that supports matrix mul...?


That's exactly how Numpy works with array and matrix types. It's 
confusing. That being said, mir has 
Contiguous/Universal/Canonical, which are also a little 
confusing...


Re: Should we add `a * b` for vectors?

2017-09-27 Thread John Colvin via Digitalmars-d
On Friday, 22 September 2017 at 17:11:56 UTC, Ilya Yaroshenko 
wrote:

Should we add `a * b` to ndslice for 1d vectors?
Discussion at https://github.com/libmir/mir-algorithm/issues/91


Unless it's always just simple element-wise, make it a different 
type. N-dimensional rectangular data structures are only 
sometimes matrices.


Also, if you did two different types I have concerns about code 
that mixed the two, it would become quite unclear which ones were 
matrix operations and which were element-wise.


Re: Can I skip sub directories with file.dirEntries() ?

2017-09-27 Thread Nicholas Wilson via Digitalmars-d-learn
On Wednesday, 27 September 2017 at 09:00:55 UTC, Ky-Anh Huynh 
wrote:

Hi,

Can I have a `break` option when using `dirEntries()`  (similar 
to `break` in a loop)? I want to study sub-directories but if 
any sub-directory matches my criteria I don't to look further 
into their subdirectories


```
  
 A/   -> matches criteria, stop here, go to next directory 
(B)
 B/   -> doesn't match criteria, will look at its 
sub-directories (BX, BY,...)

   BX
   BY
```

Thanks a lot


I'd just use dirEntries with SpanMode.shallow in combination with 
filter either in a loop or a recursive function like below.


void foo(string path = "path")
{
foreach(e; 
dirEntries(path,SpanMode.shallow).filter!(myCritreia(paramters)))

{
if (e. isDir)
foo(e.name); // recurse
// do other stuff
}
}

you will loop over all subdirs of "path" that satisfy 
`myCritreia`.


Re: Should we add `a * b` for vectors?

2017-09-27 Thread tn via Digitalmars-d
On Friday, 22 September 2017 at 17:11:56 UTC, Ilya Yaroshenko 
wrote:

Should we add `a * b` to ndslice for 1d vectors?
Discussion at https://github.com/libmir/mir-algorithm/issues/91


If it is for element-wise product, then possibly yes.
If it is for dot product (as suggested by the github issue), then 
definitely no.


Can I skip sub directories with file.dirEntries() ?

2017-09-27 Thread Ky-Anh Huynh via Digitalmars-d-learn

Hi,

Can I have a `break` option when using `dirEntries()`  (similar 
to `break` in a loop)? I want to study sub-directories but if any 
sub-directory matches my criteria I don't to look further into 
their subdirectories


```
  
 A/   -> matches criteria, stop here, go to next directory (B)
 B/   -> doesn't match criteria, will look at its 
sub-directories (BX, BY,...)

   BX
   BY
```

Thanks a lot


Re: DlangIDE v0.8.0 released

2017-09-27 Thread Traktor Toni via Digitalmars-d-announce
On Wednesday, 27 September 2017 at 07:23:30 UTC, Vadim Lopatin 
wrote:
1. Ctrl+F5 does. You can change shortcuts in 
~/.dlangide/shortcuts.json (on Windows - in 
currentUser/AppData/.dlangide/shortcuts.json
2. Why should IDE include compiler. It's easy to download it 
from official site.
3. Is Code completion/GoToDefinition/Call tips/Doc comments 
enough? If so, it's present. No refactoring support.


The shortcuts should be identical to Visual Studio, anything else 
is a waste of time to learn and configure.
The IDE should contain the compiler for convenience, this way 
dlang.org can point to your download and say "install and press 
run"
Code completion isnt working for me on windows, no clue what's 
missing.


Re: Should we add `a * b` for vectors?

2017-09-27 Thread Ilya Yaroshenko via Digitalmars-d

On Wednesday, 27 September 2017 at 04:59:10 UTC, Manu wrote:
On 26 September 2017 at 21:41, Atila Neves via Digitalmars-d < 
digitalmars-d@puremagic.com> wrote:


On Friday, 22 September 2017 at 17:11:56 UTC, Ilya Yaroshenko 
wrote:



Should we add `a * b` to ndslice for 1d vectors?
Discussion at 
https://github.com/libmir/mir-algorithm/issues/91




I'd say yes.

Atila




Just remember, it's okay to vote no! Even if it makes you a 
bigoted dick ;)

In this case, I think 'no' is the only reasonable choice.
If this is going to seriously be considered, then ndslice 
should definitely

be renamed to 'matrix'.

An alternative solution might be to introduce a wrapper of 
ndslice called 'matrix' that supports matrix mul...?


I would prefer outer operator overloading be added to D instead 
of type wrappers. So a user can import a library for operations, 
rather then library of wrappers. --Ilya


Re: DlangIDE v0.8.0 released

2017-09-27 Thread Vadim Lopatin via Digitalmars-d-announce
On Wednesday, 27 September 2017 at 02:37:41 UTC, Traktor Toni 
wrote:
On Tuesday, 26 September 2017 at 15:20:54 UTC, Vadim Lopatin 
wrote:

New DlangIDE version is released.
Now I'm considering DlangIDE as mostly usable.


well don't. I just tested the windows build.

1. F5 doesnt build+run the application
2. I have to install dmd/D compiler separately
3. no intellisense

This is not usable by any reasonable definition as an IDE.


1. Ctrl+F5 does. You can change shortcuts in 
~/.dlangide/shortcuts.json (on Windows - in 
currentUser/AppData/.dlangide/shortcuts.json
2. Why should IDE include compiler. It's easy to download it from 
official site.
3. Is Code completion/GoToDefinition/Call tips/Doc comments 
enough? If so, it's present. No refactoring support.


Re: Visual D does not always break in function that threw.

2017-09-27 Thread Psychological Cleanup via Digitalmars-d-debugger
On Wednesday, 27 September 2017 at 04:40:59 UTC, Psychological 
Cleanup wrote:
It usually breaks at the calling site. The error message gives 
the correct module and line number but this is not the line 
number show in visual studio. The function does not show up in 
the call stack either making it difficult to debug. I'm 
referring to templated functions as it might not do it with 
normal functions.


Also, when in a C callback(using a D function), it seems that it 
confuses the debugger and no stack entry is shown nor are the 
autos or watches. The debugger just kinda goes blank now showing 
anything helpful like it should.




[Issue 17862] New: std.random.XorshiftEngine.min is wrong when bits == 32

2017-09-27 Thread d-bugmail--- via Digitalmars-d-bugs
https://issues.dlang.org/show_bug.cgi?id=17862

  Issue ID: 17862
   Summary: std.random.XorshiftEngine.min is wrong when bits == 32
   Product: D
   Version: D2
  Hardware: All
OS: All
Status: NEW
  Severity: minor
  Priority: P1
 Component: phobos
  Assignee: nob...@puremagic.com
  Reporter: n8sh.second...@hotmail.com

XorshiftEngine.min is defined as 0 regardless of template parameters
but an XorshiftEngine cannot produce a value of zero if its internal
state has the same number of bits as the output element type.

--