Re: why won't byPair work with a const AA?

2017-08-03 Thread Olivier FAURE via Digitalmars-d-learn

On Wednesday, 2 August 2017 at 18:06:03 UTC, H. S. Teoh wrote:
On Wed, Aug 02, 2017 at 01:15:44PM -0400, Steven Schveighoffer 
via Digitalmars-d-learn wrote: [...]
The real answer is to have tail modifiers for structs, so you 
can do the same thing an array does. Note that if Result is an 
array, you CAN use inout:


auto byPair(AA)(inout(AA) aa)
{
   alias Result = inout(X)[];
   return Result(...);
}

[...]

Yeah, this isn't the first time I've run into this.  But then 
the problem becomes, how do you design tail modifiers for 
structs?


I understand the general concept you're describing, but what 
exactly are tail modifiers? It's the first time I see this name, 
and my google-fu gives me nothing.


Re: How to build GUI-based applications in D ?

2017-08-03 Thread ashit via Digitalmars-d-learn

On Tuesday, 1 August 2017 at 16:12:45 UTC, Dukc wrote:

On Tuesday, 1 August 2017 at 15:18:12 UTC, ashit wrote:
i couldn't set control's width and height (Button widget) 
shows error. maybe it works a different way.


1. Try layoutHeight/width. Remember to set it for the main 
widget too, not just the children of it.


2. DlangUI is not intended to define sizes in pixels as a 
standard practice. Instead, use layouts and layout sizes. This 
is intended to courage you to make your program 
resolution-agnostic.


But I'm a beginner at this topic too. Take these with a grain 
of salt


thank you Dukc

it worked, i should adapt with this different naming style. (as 
comparing to C#)

[yesterday]
but today, when i went to create another project, it failed.
i get this message:

D:\ashit\documents\D\simpled>dub init simpled dlangui
Couldn't find package: dlangui.

it works without the "dlangui" option, but then when i execute 
run command:


D:\ashit\documents\D\simpled>dub run
Performing "debug" build using dmd for x86.
simpled ~master: building configuration "application"...
source\app.d(2,8): Error: module dlangui is in file 'dlangui.d' 
which cannot be

read
import path[0] = source
import path[1] = C:\dmd2\windows\bin\..\..\src\phobos
import path[2] = C:\dmd2\windows\bin\..\..\src\druntime\import
dmd failed with exit code 1.

this is the path i have extracted the dlangui files:

D:\ashit\software\D Compiler\DlangUI\dlangui-master

how to define dlangui for DUB?




Issue with template constraints in numeric types

2017-08-03 Thread data pulverizer via Digitalmars-d-learn

Dear all,

I am writing template constraints for different numeric types:

```
import std.stdio: writeln;
import std.traits: isIntegral, isNumeric;


T test(T)(T x, T y)
if(is(T: double) && isNumeric!T)
{
return x*y;
}


auto test(T)(T x, T y)
if(!is(T: double) && isNumeric!T)
{
return 5*test!double(x, y);
}


void main()
{
int x = 2;
double y = 2.0;
writeln("int test: ", test(x, x));
writeln("double test: ", test(y, y));
}
```

returns:

```
int test: 4
double test: 4
```

The same issue occurs when I try using template specializations 
instead. Explanations and suggestions please.


Thank you!

Compiler details:
$ dmd --version
DMD64 D Compiler v2.074.1
Copyright (c) 1999-2017 by Digital Mars written by Walter Bright



Re: Issue with template constraints in numeric types

2017-08-03 Thread data pulverizer via Digitalmars-d-learn

On Thursday, 3 August 2017 at 12:24:02 UTC, data pulverizer wrote:

The same issue occurs when I try using template specializations 
instead. ...


That is T test(T: double)(T x, T y){...} and T test(T)(T x, T 
y){...}


Thanks


Re: Issue with template constraints in numeric types

2017-08-03 Thread Adam D. Ruppe via Digitalmars-d-learn

On Thursday, 3 August 2017 at 12:24:02 UTC, data pulverizer wrote:

import std.traits: isIntegral, isNumeric;


Are you familiar with isFloatingPoint?

http://dpldocs.info/experimental-docs/std.traits.isFloatingPoint.html


if(is(T: double) && isNumeric!T)


Keep in mind that T:double here means "if T can implicitly 
convert to double". Since int can implicitly convert to double 
too, this case covers both families!


You might want to try == instead of : for a more exact match.


Re: Issue with template constraints in numeric types

2017-08-03 Thread data pulverizer via Digitalmars-d-learn

On Thursday, 3 August 2017 at 12:31:00 UTC, Adam D. Ruppe wrote:
On Thursday, 3 August 2017 at 12:24:02 UTC, data pulverizer 
wrote:

import std.traits: isIntegral, isNumeric;


Are you familiar with isFloatingPoint?

http://dpldocs.info/experimental-docs/std.traits.isFloatingPoint.html


if(is(T: double) && isNumeric!T)


Keep in mind that T:double here means "if T can implicitly 
convert to double". Since int can implicitly convert to double 
too, this case covers both families!


You might want to try == instead of : for a more exact match.


Thank you very much!

What about this case:

```
T test(T: double)(T x, T y)
{
return x*y;
}

auto test(T)(T x, T y)
{
return 5*test!double(x, y);
}
```

which also gives:

```
int test: 4
double test: 4
```




Re: Issue with template constraints in numeric types

2017-08-03 Thread data pulverizer via Digitalmars-d-learn

On Thursday, 3 August 2017 at 12:35:08 UTC, data pulverizer wrote:

What about this case:

```
T test(T: double)(T x, T y)
{
return x*y;
}

auto test(T)(T x, T y)
{
return 5*test!double(x, y);
}
```

which also gives:

```
int test: 4
double test: 4
```


Hmm ... it looks as the specialization `:` operator is working 
like the constraint `:` operator and doing convertible at least 
for the floating point case. Is that right?


Re: gtkD load images

2017-08-03 Thread Mengu via Digitalmars-d-learn

On Thursday, 3 August 2017 at 03:59:40 UTC, Johnson Jones wrote:
How can be use gtkD to load images, I assume through gdkpixbuf? 
While I am getting errors loading images through glade's image:


(test.exe:8188): Gtk-WARNING **: Could not load 
image 'a.jpg': Couldn't recognize the image file format for 
file 'test\a.jpg'


(loads fine in glade)

which needs to be resolved, I'd also like to be able to use 
gdkpixbuf to load images programmatically. There seems to be no 
demos on the gtkD github page that deals with image loading.


I've tried to do something like

import gtkc.gdkpixbuf;
auto x = c_gdk_pixbuf_get_formats().data;

but I don't know how to interpret x.

Also something like

import gtkc.gdkpixbuf;
void* x;
auto p = c_gdk_pixbuf_get_formats();
for(int i = 0; i < 10; i++)
{   
x = p.data;
p = p.next;
}

which doesn't offer any help.


Aside: How can we call the gtk functions directly using gtkD? 
Seems it uses stuff like


Linker.link(gdk_pixbuf_get_formats, "gdk_pixbuf_get_formats", 
LIBRARY_GDKPIXBUF);


It does seem to alias to these function but something is off 
and I'm not sure what.


hi

- is the gtk.Image class not working for you? 
https://api.gtkd.org/gtkd/gtk/Image.html


- there's also a gdkpixbuf.Pixbuf that you can use. 
https://api.gtkd.org/gtkd/gdkpixbuf/Pixbuf.html


- you can import those functions from gdkpixbuf.c.functions.





Why free and realloc seem to include .

2017-08-03 Thread Michael via Digitalmars-d-learn
So this might be a bit of a stupid question, but looking at the 
DMD source code (dmodule.d in particular) I see the following 
code:



if (srcfile._ref == 0)
   .free(srcfile.buffer);
srcfile.buffer = null;
srcfile.len = 0;


and I was just wondering why certain functions seem to be called 
using the dot operator on its own, unattached to some object. 
This is probably a naive question but I haven't seen this in my 
limited experience using D and I was just wondering why this is. 
I have only really seen this relating to D's manual memory 
management. But in the same file, I see examples like this:



FileName.free(n);


so what is the case when you should use .free() and why not just 
free()? Thanks.


Re: Access derived type in baseclass static function template

2017-08-03 Thread Timoses via Digitalmars-d-learn

On Wednesday, 2 August 2017 at 12:07:46 UTC, Timoses wrote:

Hey,

wondering whether it's possible to access the derived type from 
a function template in the base class or interface.


[...]


Created an enhancement issue:

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


Re: Access derived type in baseclass static function template

2017-08-03 Thread Timoses via Digitalmars-d-learn
On Wednesday, 2 August 2017 at 15:38:12 UTC, Steven Schveighoffer 
wrote:

On 8/2/17 11:06 AM, Timoses wrote:
On Wednesday, 2 August 2017 at 13:51:01 UTC, Steven 
Schveighoffer wrote:
However, your original code has potential as an enhancement 
request, as the type is known at compile-time and could 
certainly be resolved to pass in as the `this` template 
parameter.


I guess the `this` is really misleading it being a static 
method.
I suppose 
https://issues.dlang.org/buglist.cgi?bug_severity=enhancement&bug_status=NEW&bug_status=ASSIGNED&bug_status=REOPENED&product=D&query_format=report-table&y_axis_field=bug_severity would be the place for an enhancement request?

Possibly related:
https://issues.dlang.org/show_bug.cgi?id=14191


Yes, that's exactly it.

Note that typeof(this) has special meaning for static methods:

class C
{
   static typeof(this) foo() { return new typeof(this); }
}

So there is precedence for the meaning of `this` in a static 
context.


-Steve


Oh, just now get it after creating the issue ^^. Makes sense. I 
kind of connected the "this" to existing instances because the 
DMD compiler often complains about something like "need this 
for..." when calling something from a static method that... 
well... needs "this" or instantiation..

E.g.:

class A
{
static void a()
{
b();
}
void b();
}

will throw
  Error: need 'this' for 'b' of type 'void()'


Re: Why free and realloc seem to include .

2017-08-03 Thread Temtaime via Digitalmars-d-learn

On Thursday, 3 August 2017 at 14:03:56 UTC, Michael wrote:
So this might be a bit of a stupid question, but looking at the 
DMD source code (dmodule.d in particular) I see the following 
code:



if (srcfile._ref == 0)
   .free(srcfile.buffer);
srcfile.buffer = null;
srcfile.len = 0;


and I was just wondering why certain functions seem to be 
called using the dot operator on its own, unattached to some 
object. This is probably a naive question but I haven't seen 
this in my limited experience using D and I was just wondering 
why this is. I have only really seen this relating to D's 
manual memory management. But in the same file, I see examples 
like this:



FileName.free(n);


so what is the case when you should use .free() and why not 
just free()? Thanks.


Dot is equal to C++'s :: operator to access a global namespace.
Aka ::free(ptr);


Re: Bug in gtkd?

2017-08-03 Thread Mike Wey via Digitalmars-d-learn

On 03-08-17 05:00, Johnson Jones wrote:

On Wednesday, 2 August 2017 at 14:51:45 UTC, Mike Wey wrote:

On 02-08-17 08:04, Johnson Jones wrote:
Ok, Using msys I was able to get glade 3.20 running. Maybe that will 
fix everything.


Great, unfortunately "Use msys2" seems to be the official way to 
install anything GTK related on windows.


... Also, I cannot seem to load a jpg using an imageview

(test.exe:1628): Gtk-WARNING **: Could not load image 
'a.jpg': Couldn't recognize the image file format for file 'a.jpg'


Just a normal jpg. Tried a bmp, same thing. It shows fine in glade itself.



It looks like the pixbuf loaders are missing from the installer.

--
Mike Wey


Re: Why free and realloc seem to include .

2017-08-03 Thread Michael via Digitalmars-d-learn

On Thursday, 3 August 2017 at 14:15:40 UTC, Temtaime wrote:

On Thursday, 3 August 2017 at 14:03:56 UTC, Michael wrote:
So this might be a bit of a stupid question, but looking at 
the DMD source code (dmodule.d in particular) I see the 
following code:



[...]


and I was just wondering why certain functions seem to be 
called using the dot operator on its own, unattached to some 
object. This is probably a naive question but I haven't seen 
this in my limited experience using D and I was just wondering 
why this is. I have only really seen this relating to D's 
manual memory management. But in the same file, I see examples 
like this:



[...]


so what is the case when you should use .free() and why not 
just free()? Thanks.


Dot is equal to C++'s :: operator to access a global namespace.
Aka ::free(ptr);


I've not seen that either, though I'm not a C++ programmer. Does 
using free() on its own not assume access of a global namespace?


Re: Why free and realloc seem to include .

2017-08-03 Thread Adam D. Ruppe via Digitalmars-d-learn

On Thursday, 3 August 2017 at 15:18:17 UTC, Michael wrote:
I've not seen that either, though I'm not a C++ programmer. 
Does using free() on its own not assume access of a global 
namespace?


Consider the following:

class Foo {
   void free(void*);

   void other_method() {
  free(ptr); // calls the member function
   }
}


The leading dot in D just ensures it calls the global one instead 
of a member (if present).


Template mixins and selective imports

2017-08-03 Thread jmh530 via Digitalmars-d-learn
I am trying to create a vectorize function that mixes in a new 
version of function with the same name that applies the function 
(to an ndslice).


The code below compiles without error and has the behavior I 
would expect.


However, when I change the function import to a selective import 
(e.g. from import std.math; to import std.math : sin;), then I 
get errors implying that the overload is not actually created.


Ideally, I would like to get this working with any kind of import.

One thing I noticed is that the fullyQualifiedName of sin changes 
quite a bit depending on whether you use one or the other.


This may be related to either of the following:
https://issues.dlang.org/show_bug.cgi?id=16287
https://issues.dlang.org/show_bug.cgi?id=16023



---

import std.traits : isFunction;

private enum _vectorize(string f) = "
import mir.ndslice.slice : SliceKind, Slice;

auto " ~ f ~ "(SliceKind kind, size_t[] packs, Iterator)
   (Slice!(kind, packs, 
Iterator) slice)

{
import mir.ndslice.topology : map;
return slice.map!(f);
}
";

mixin template vectorize(alias f)
if (isFunction!f)
{
mixin(_vectorize!(__traits(identifier, f)));
}

unittest
{
import std.stdio : writeln;
import mir.ndslice.slice : sliced;
import mir.ndslice.topology : map;
import std.math; //import std.math : sin;

auto x = [0.0, 1.0, 2.0, 3.0].sliced;

auto y = x.map!(sin);
writeln(y);

mixin vectorize!(sin);
auto z = sin(x);
writeln(z);
}


Re: why won't byPair work with a const AA?

2017-08-03 Thread Steven Schveighoffer via Digitalmars-d-learn

On 8/3/17 4:30 AM, Olivier FAURE wrote:

I understand the general concept you're describing, but what exactly are 
tail modifiers? It's the first time I see this name, and my google-fu 
gives me nothing.


tail modifiers are modifiers that only apply to the "tail" of the type.

For example const(int)* is applying const to the "tail" of the int 
pointer, that is, the int that it points at. It's not applying to the 
actual pointer itself (we call that the "head").


Another way to look at it is that when you copy a variable you always 
make a copy of the head, and you don't make a copy of the tail. For this 
reason, the fully-modified and tail-modified types are implicitly 
castable, and this is the important property we need to duplicate.


A tail-modified struct would be something like this:

struct S
{
   int * x;
}

const(S) s;

This looks like this:

struct ConstS
{
   const(int *) x;
}

A tail-const S would look like this:

struct TailConstS
{
   const(int)* x;
}

That is, everything the struct points at remains const, but the actual 
data of the struct is now mutable.


Note that TailConstS and ConstS can implicitly convert.

This is how arrays work. An array T[] is really:

struct Array
{
   size_t length;
   T* ptr;
}

A tail-const array const(T)[] is really:

struct TailConstArray
{
   size_t length; // mutable
   const(T)* ptr; // mutable, but points at const data
}

This property of implicit casting is what's needed to fully realize 
custom ranges and const together. The way to get it is to define 
tail-modifier syntax for all types, not just arrays and pointers.


-Steve


Re: Template mixins and selective imports

2017-08-03 Thread Meta via Digitalmars-d-learn

On Thursday, 3 August 2017 at 15:29:47 UTC, jmh530 wrote:
I am trying to create a vectorize function that mixes in a new 
version of function with the same name that applies the 
function (to an ndslice).


The code below compiles without error and has the behavior I 
would expect.


However, when I change the function import to a selective 
import (e.g. from import std.math; to import std.math : sin;), 
then I get errors implying that the overload is not actually 
created.


Ideally, I would like to get this working with any kind of 
import.


One thing I noticed is that the fullyQualifiedName of sin 
changes quite a bit depending on whether you use one or the 
other.


This may be related to either of the following:
https://issues.dlang.org/show_bug.cgi?id=16287
https://issues.dlang.org/show_bug.cgi?id=16023



---

import std.traits : isFunction;

private enum _vectorize(string f) = "
import mir.ndslice.slice : SliceKind, Slice;

auto " ~ f ~ "(SliceKind kind, size_t[] packs, Iterator)
   (Slice!(kind, packs, 
Iterator) slice)

{
import mir.ndslice.topology : map;
return slice.map!(f);
}
";

mixin template vectorize(alias f)
if (isFunction!f)
{
mixin(_vectorize!(__traits(identifier, f)));
}

unittest
{
import std.stdio : writeln;
import mir.ndslice.slice : sliced;
import mir.ndslice.topology : map;
import std.math; //import std.math : sin;

auto x = [0.0, 1.0, 2.0, 3.0].sliced;

auto y = x.map!(sin);
writeln(y);

mixin vectorize!(sin);
auto z = sin(x);
writeln(z);
}


I'm not 100% certain, but I believe you have to bring the 
vectorized overload of sin into the overload set, so first try 
`mixin vectorize!sin vsin; alias sin = vsin;` and see if it works.


https://dlang.org/spec/function.html#overload-sets


Re: Template mixins and selective imports

2017-08-03 Thread Meta via Digitalmars-d-learn

On Thursday, 3 August 2017 at 19:03:55 UTC, Meta wrote:

`mixin vectorize!sin vsin; alias sin = vsin;` and see if it


Should be `alias sin = vsin.sin;`




Re: Bug in gtkd?

2017-08-03 Thread Johnson Jones via Digitalmars-d-learn

On Thursday, 3 August 2017 at 15:11:46 UTC, Mike Wey wrote:

On 03-08-17 05:00, Johnson Jones wrote:

On Wednesday, 2 August 2017 at 14:51:45 UTC, Mike Wey wrote:

On 02-08-17 08:04, Johnson Jones wrote:
Ok, Using msys I was able to get glade 3.20 running. Maybe 
that will fix everything.


Great, unfortunately "Use msys2" seems to be the official way 
to install anything GTK related on windows.


... Also, I cannot seem to load a jpg using an imageview

(test.exe:1628): Gtk-WARNING **: Could not load 
image 'a.jpg': Couldn't recognize the image file format for 
file 'a.jpg'


Just a normal jpg. Tried a bmp, same thing. It shows fine in 
glade itself.




It looks like the pixbuf loaders are missing from the installer.


How do I remedy this?


Re: gtkD load images

2017-08-03 Thread Johnson Jones via Digitalmars-d-learn

On Thursday, 3 August 2017 at 13:12:03 UTC, Mengu wrote:

On Thursday, 3 August 2017 at 03:59:40 UTC, Johnson Jones wrote:
How can be use gtkD to load images, I assume through 
gdkpixbuf? While I am getting errors loading images through 
glade's image:


(test.exe:8188): Gtk-WARNING **: Could not load 
image 'a.jpg': Couldn't recognize the image file format for 
file 'test\a.jpg'


(loads fine in glade)

which needs to be resolved, I'd also like to be able to use 
gdkpixbuf to load images programmatically. There seems to be 
no demos on the gtkD github page that deals with image loading.


I've tried to do something like

import gtkc.gdkpixbuf;
auto x = c_gdk_pixbuf_get_formats().data;

but I don't know how to interpret x.

Also something like

import gtkc.gdkpixbuf;
void* x;
auto p = c_gdk_pixbuf_get_formats();
for(int i = 0; i < 10; i++)
{   
x = p.data;
p = p.next;
}

which doesn't offer any help.


Aside: How can we call the gtk functions directly using gtkD? 
Seems it uses stuff like


Linker.link(gdk_pixbuf_get_formats, "gdk_pixbuf_get_formats", 
LIBRARY_GDKPIXBUF);


It does seem to alias to these function but something is off 
and I'm not sure what.


hi

- is the gtk.Image class not working for you? 
https://api.gtkd.org/gtkd/gtk/Image.html


- there's also a gdkpixbuf.Pixbuf that you can use. 
https://api.gtkd.org/gtkd/gdkpixbuf/Pixbuf.html


- you can import those functions from gdkpixbuf.c.functions.


no, they are not... I haven't tried though, but there seems to be 
a problem with the pixbuf not having loaders for any images. 
using a gtk Image widget does not load the image and complains 
about the image format.


If I do something like

import gdkpixbuf.Pixbuf;
Pixbuf.newFromResource("C:\\a.jpg");

Unhandled exception: glib.GException.GException The resource at 
'C:\a.jpg' does not exist at generated\gtkd\glib\GException.d(40) 
occurred


which doesn't seem to make much sense.

The resource exists where I say it is and not sure if this is 
related to the missing pixbuf loaders.


Re: Bug in gtkd?

2017-08-03 Thread Johnson Jones via Digitalmars-d-learn

On Thursday, 3 August 2017 at 15:11:46 UTC, Mike Wey wrote:

On 03-08-17 05:00, Johnson Jones wrote:

On Wednesday, 2 August 2017 at 14:51:45 UTC, Mike Wey wrote:

On 02-08-17 08:04, Johnson Jones wrote:
Ok, Using msys I was able to get glade 3.20 running. Maybe 
that will fix everything.


Great, unfortunately "Use msys2" seems to be the official way 
to install anything GTK related on windows.


... Also, I cannot seem to load a jpg using an imageview

(test.exe:1628): Gtk-WARNING **: Could not load 
image 'a.jpg': Couldn't recognize the image file format for 
file 'a.jpg'


Just a normal jpg. Tried a bmp, same thing. It shows fine in 
glade itself.




It looks like the pixbuf loaders are missing from the installer.


I tried to use the mingw version of gtk with no luck. It first 
looks in C:\MinGW even though I have MinGW installed somewhere 
else. Using a junction doesn't help becomes then it when it finds 
the dll it has missing symbols


"The Procedure Entry Point gdk_pixbuf_gettext could not be 
located in the dynamic link library 
C:\MinGW\lib\gdk-pix-buf-2.0\2.10.0\loaders\libpixbufloader-gdip-jpeg.dll".


I actually just copied over the loaders rather than using the 
full gtk mingw install because when I do that it complains about 
some lib??svg missing. I guess one can't mix mingw installs with 
non-mingw... but the gtk mingw install is incomplete too ;/


I hope this isn't going to be an on going thing... seems I've 
wasted quite a bit of time to try and get gdk to work. I probably 
could have written my own gui by now.


Re: Bug in gtkd?

2017-08-03 Thread Johnson Jones via Digitalmars-d-learn

On Thursday, 3 August 2017 at 15:11:46 UTC, Mike Wey wrote:

On 03-08-17 05:00, Johnson Jones wrote:

On Wednesday, 2 August 2017 at 14:51:45 UTC, Mike Wey wrote:

On 02-08-17 08:04, Johnson Jones wrote:
Ok, Using msys I was able to get glade 3.20 running. Maybe 
that will fix everything.


Great, unfortunately "Use msys2" seems to be the official way 
to install anything GTK related on windows.


... Also, I cannot seem to load a jpg using an imageview

(test.exe:1628): Gtk-WARNING **: Could not load 
image 'a.jpg': Couldn't recognize the image file format for 
file 'a.jpg'


Just a normal jpg. Tried a bmp, same thing. It shows fine in 
glade itself.




It looks like the pixbuf loaders are missing from the installer.


Ok, so, I linked the gtk to the msys gtk that I installed before 
when trying to get glade to work and it worked!


seems that msys is much more up to date than anything else as it 
just works(I need to remember than in the future).


The problem I see is this:

When I get ready to release my app to the public, I can't expect 
them to all have to install msys and build.


msys seems to clump everything together and I don't know what 
files I need to extract to be able to bundle everything together.


Any ideas how to solve that problem? At least now I can move 
ahead and actually make some progress on my app.


Would still be nice to get the x86 vs x64 issue resolved so I 
don't have to keep switching between the two for testing 
purposes. Since Visual D was just patched to handle x64 BP's I 
guess I can stay with that for now.






Re: Template mixins and selective imports

2017-08-03 Thread jmh530 via Digitalmars-d-learn

On Thursday, 3 August 2017 at 19:05:47 UTC, Meta wrote:

On Thursday, 3 August 2017 at 19:03:55 UTC, Meta wrote:

`mixin vectorize!sin vsin; alias sin = vsin;` and see if it


Should be `alias sin = vsin.sin;`


Thanks, this pointed me in the right direction. I got the line 
below working.


mixin vectorize!sin temp;
alias vsin = temp.sin;
auto z = vsin(x);

I couldn't give it the name of sin or the name of the identifier.

This is a little ugly and would require the user to make the 
adjustment themselves.


Below seems to work if the user doesn't import the relevant 
function, though it will still result in errors if they 
selectively import that function. I think the combination of the 
two will be sufficient.



private enum _vectorizeAlt(string mod, string func) = "
auto " ~ func ~ "(SliceKind kind, size_t[] packs, Iterator)
   (Slice!(kind, packs, 
Iterator) slice)

{
import mir.ndslice.topology : map;
return slice.map!(" ~ mod ~ "." ~ func ~ ");
}
";

mixin template vectorizeAlt(string mod, string func)
{
mixin("static import " ~ mod ~ ";");
import mir.ndslice.slice : SliceKind, Slice;

mixin(_vectorizeAlt!(mod, func));
}

unittest
{
import std.stdio : writeln;
import mir.ndslice.slice : sliced;
import mir.ndslice.topology : map;

auto x = [0.0, 1.0, 2.0, 3.0].sliced;

mixin vectorizeAlt!("std.math", "sin");
auto y = sin(x);
}


Re: Bug in gtkd?

2017-08-03 Thread Mike Wey via Digitalmars-d-learn

On 03-08-17 22:40, Johnson Jones wrote:
Ok, so, I linked the gtk to the msys gtk that I installed before when 
trying to get glade to work and it worked!


seems that msys is much more up to date than anything else as it just 
works(I need to remember than in the future).


The problem I see is this:

When I get ready to release my app to the public, I can't expect them to 
all have to install msys and build.


msys seems to clump everything together and I don't know what files I 
need to extract to be able to bundle everything together.


Any ideas how to solve that problem? At least now I can move ahead and 
actually make some progress on my app.


Would still be nice to get the x86 vs x64 issue resolved so I don't have 
to keep switching between the two for testing purposes. Since Visual D 
was just patched to handle x64 BP's I guess I can stay with that for now.




I'll try to build and test some new installers tomorrow that will 
include the loaders.


--
Mike Wey


Re: gtkD load images

2017-08-03 Thread Johnson Jones via Digitalmars-d-learn

On Thursday, 3 August 2017 at 13:12:03 UTC, Mengu wrote:

On Thursday, 3 August 2017 at 03:59:40 UTC, Johnson Jones wrote:
How can be use gtkD to load images, I assume through 
gdkpixbuf? While I am getting errors loading images through 
glade's image:


(test.exe:8188): Gtk-WARNING **: Could not load 
image 'a.jpg': Couldn't recognize the image file format for 
file 'test\a.jpg'


(loads fine in glade)

which needs to be resolved, I'd also like to be able to use 
gdkpixbuf to load images programmatically. There seems to be 
no demos on the gtkD github page that deals with image loading.


I've tried to do something like

import gtkc.gdkpixbuf;
auto x = c_gdk_pixbuf_get_formats().data;

but I don't know how to interpret x.

Also something like

import gtkc.gdkpixbuf;
void* x;
auto p = c_gdk_pixbuf_get_formats();
for(int i = 0; i < 10; i++)
{   
x = p.data;
p = p.next;
}

which doesn't offer any help.


Aside: How can we call the gtk functions directly using gtkD? 
Seems it uses stuff like


Linker.link(gdk_pixbuf_get_formats, "gdk_pixbuf_get_formats", 
LIBRARY_GDKPIXBUF);


It does seem to alias to these function but something is off 
and I'm not sure what.


hi

- is the gtk.Image class not working for you? 
https://api.gtkd.org/gtkd/gtk/Image.html


- there's also a gdkpixbuf.Pixbuf that you can use. 
https://api.gtkd.org/gtkd/gdkpixbuf/Pixbuf.html


- you can import those functions from gdkpixbuf.c.functions.


So, like I said, I've tried

import gdkpixbuf.Pixbuf;
auto x = Pixbuf.newFromResource("C:\\a.jpg");

which gives me that error I stated before for x86. For x64 it 
simply crashes and no exception is given.


If I use a dummy image I get the same error:

"Unhandled exception: glib.GException.GException The resource at 
“C:\adf.jpg” does not exist at 
generated\gtkd\glib\GException.d(40)"


The error message makes look like like it should be


"Unhandled exception: glib.GException.GException The resource at 
“C:\adf.jpg” does not exist at “C:\” 
generated\gtkd\glib\GException.d(40)"



I'd rather use Pixbuf than image because I don't need to generate 
a full blow image widget.


If I do

GError* err = null;
auto p = gdk_pixbuf_new_from_resource(Str.toStringz("C:\\a.jpg"), 
&err);


p is null and err is

The resource at “D:\a.jpgâ€. does not exist.

which is clearly not true.

So not sure what is going on ;/ Seems to be a bug in pixbuf or am 
I specifying the path wrong? If gtk.Image uses these internally 
then it is working so...




Re: Bug in gtkd?

2017-08-03 Thread Johnson Jones via Digitalmars-d-learn

On Thursday, 3 August 2017 at 21:00:17 UTC, Mike Wey wrote:

On 03-08-17 22:40, Johnson Jones wrote:
Ok, so, I linked the gtk to the msys gtk that I installed 
before when trying to get glade to work and it worked!


seems that msys is much more up to date than anything else as 
it just works(I need to remember than in the future).


The problem I see is this:

When I get ready to release my app to the public, I can't 
expect them to all have to install msys and build.


msys seems to clump everything together and I don't know what 
files I need to extract to be able to bundle everything 
together.


Any ideas how to solve that problem? At least now I can move 
ahead and actually make some progress on my app.


Would still be nice to get the x86 vs x64 issue resolved so I 
don't have to keep switching between the two for testing 
purposes. Since Visual D was just patched to handle x64 BP's I 
guess I can stay with that for now.




I'll try to build and test some new installers tomorrow that 
will include the loaders.


Thanks. Could you take a look at the loading image thread I 
started when you get time? I can't seem to get an image to load 
even though it seems straight forward.


These are the pixbufs I'm using

mingw32/mingw-w64-i686-gdk-pixbuf2 2.36.6-2 [installed]
An image loading library (mingw-w64)
mingw64/mingw-w64-x86_64-gdk-pixbuf2 2.36.6-2 [installed]
An image loading library (mingw-w64)

in x64 it crashes completely without an exception though... which 
is why I want an easy way to switch between the two 
architectures... since x64 seems to be more unstable than x86 but 
sometimes it's the reverse, and ultimately I'll want to release 
in x64.


Also, do I ever need to rebuild gdk when changing gtk 
installations? Does it ever grab anything from them at compile 
time or is it all at runtime?












Re: Why free and realloc seem to include .

2017-08-03 Thread Michael via Digitalmars-d-learn

On Thursday, 3 August 2017 at 15:29:29 UTC, Adam D. Ruppe wrote:

On Thursday, 3 August 2017 at 15:18:17 UTC, Michael wrote:
I've not seen that either, though I'm not a C++ programmer. 
Does using free() on its own not assume access of a global 
namespace?


Consider the following:

class Foo {
   void free(void*);

   void other_method() {
  free(ptr); // calls the member function
   }
}


The leading dot in D just ensures it calls the global one 
instead of a member (if present).


So it could be used without, but you risk conflicts with other 
functions. I got it, thanks to both of you.


OT: What causes the Segfault in the following?

2017-08-03 Thread Andrew Edwards via Digitalmars-d-learn

int main()
{
//int wierd[4];
struct nk_color str = nk_rgba_hex("#deadbeef");
//int wierd[4];
char *s;
//int wierd[4];
nk_color_hex_rgb(s, str);
//int wierd[4];
printf("(%d,%d,%d)\n",str.r, str.g, str.b);
//int wierd[4];
printf("%s\n", s);
//int wierd[4];
return 0;
}

The above produces as its output:

(222,173,190)
DEADBE

but if I introduce an int array on any of the commented lines, it 
results in a runtime Segmentation fault: 11. Basically I'm just trying 
to port Nuklear[1] to D as a first project after reading Ali and Mike's 
awesome books. Moving one function at a time to an independent C file, 
compiling it to observe the result and then from the understanding 
gained, re-implementing it in D. The int array here is introduced to 
prepare for port of the next function and has nothing to do with the 
current content of main(), but I'm completely confused because I don't 
see anything wrong with the code that is causing the error.


By the way, the program responds differently based on the type of the array:

double => Bus error: 10
char => no error
short => Segmentation fault: 11
long => Bus error: 10

Obviously I'm missing something... please enlighten me.

Thanks,
Andrew

[1] Yes, I know there is already a port and bindings available... this 
is purely for learning. My goal is actually to port imgui for a project 
I committed myself to at DConf2017 but in the process of doing so, I 
realized how woefully inadequate my knowledge of programming is. This is 
my attempt at rectifying the situation.


Re: OT: What causes the Segfault in the following?

2017-08-03 Thread Andrew Edwards via Digitalmars-d-learn

Andrew Edwards wrote:

int main()
{
//int wierd[4];
struct nk_color str = nk_rgba_hex("#deadbeef");
//int wierd[4];
char *s;
//int wierd[4];
nk_color_hex_rgb(s, str);
//int wierd[4];
printf("(%d,%d,%d)\n",str.r, str.g, str.b);
//int wierd[4];
printf("%s\n", s);
//int wierd[4];
return 0;
}

The above produces as its output:

(222,173,190)
DEADBE

but if I introduce an int array on any of the commented lines, it
results in a runtime Segmentation fault: 11. Basically I'm just trying
to port Nuklear[1] to D as a first project after reading Ali and Mike's
awesome books. Moving one function at a time to an independent C file,
compiling it to observe the result and then from the understanding
gained, re-implementing it in D. The int array here is introduced to
prepare for port of the next function and has nothing to do with the
current content of main(), but I'm completely confused because I don't
see anything wrong with the code that is causing the error.

By the way, the program responds differently based on the type of the
array:

double => Bus error: 10
char => no error
short => Segmentation fault: 11
long => Bus error: 10

Obviously I'm missing something... please enlighten me.

Thanks,
Andrew

[1] Yes, I know there is already a port and bindings available... this
is purely for learning. My goal is actually to port imgui for a project
I committed myself to at DConf2017 but in the process of doing so, I
realized how woefully inadequate my knowledge of programming is. This is
my attempt at rectifying the situation.


Just in case... here are the two functions being called in main():

https://github.com/vurtun/nuklear/blob/master/nuklear.h#L5695-L5722


Re: OT: What causes the Segfault in the following?

2017-08-03 Thread Ali Çehreli via Digitalmars-d-learn

On 08/03/2017 06:02 PM, Andrew Edwards wrote:

> char *s;

That's an uninitialized C string.

> nk_color_hex_rgb(s, str);

That function is expecting it to have at least 7 chars when doing things 
like


output[1] = (char)NK_TO_HEX((col.r & 0x0F));

So you have to have a proper pointer to the first element of an array to 
pass to nk_color_hex_rgb. The following may work but you shouldn't be 
needing to use magic constants like 7:

char[7] s;
nk_color_hex_rgb(s.ptr, str);
// ...
printf("%s\n", s.ptr);

There's probably the proper C macro that defines it so that you can do

  char[BLAH_LENGTH] s:

Ali



Re: OT: What causes the Segfault in the following?

2017-08-03 Thread Steven Schveighoffer via Digitalmars-d-learn

On 8/3/17 9:12 PM, Andrew Edwards wrote:

Andrew Edwards wrote:

int main()
{
//int wierd[4];
struct nk_color str = nk_rgba_hex("#deadbeef");
//int wierd[4];
char *s;
//int wierd[4];
nk_color_hex_rgb(s, str);
//int wierd[4];
printf("(%d,%d,%d)\n",str.r, str.g, str.b);
//int wierd[4];
printf("%s\n", s);
//int wierd[4];
return 0;
}

The above produces as its output:

(222,173,190)
DEADBE

but if I introduce an int array on any of the commented lines, it
results in a runtime Segmentation fault: 11. Basically I'm just trying
to port Nuklear[1] to D as a first project after reading Ali and Mike's
awesome books. Moving one function at a time to an independent C file,
compiling it to observe the result and then from the understanding
gained, re-implementing it in D. The int array here is introduced to
prepare for port of the next function and has nothing to do with the
current content of main(), but I'm completely confused because I don't
see anything wrong with the code that is causing the error.

By the way, the program responds differently based on the type of the
array:

double => Bus error: 10
char => no error
short => Segmentation fault: 11
long => Bus error: 10

Obviously I'm missing something... please enlighten me.

Thanks,
Andrew

[1] Yes, I know there is already a port and bindings available... this
is purely for learning. My goal is actually to port imgui for a project
I committed myself to at DConf2017 but in the process of doing so, I
realized how woefully inadequate my knowledge of programming is. This is
my attempt at rectifying the situation.


Just in case... here are the two functions being called in main():

https://github.com/vurtun/nuklear/blob/master/nuklear.h#L5695-L5722


Can you show how you declared these in D? It's important. I think what's 
happening is that the nk_color_hex_rgb is incorrectly defined. I think 
you should *always* get segfault, with or without any of those arrays.


-Steve


Fix gtkD api display

2017-08-03 Thread Johnson Jones via Digitalmars-d-learn

https://api.gtkd.org

It is difficult to navigate.

1. clicking the documentation on the main site takes it to the 
gtk.AboutDialog api. That is all it shows, I was confused at 
first, as I'm sure most people would be.


2. The packages list lists all the packages, but all the sub 
elements are expanded, making it time consuming to hunt down 
anything specific. Initially collapsing them and adding a search 
box would be nice.


3. When clicking on any packages it reloads the page and shows 
only the package in the first tab. This requires one to then go 
back to packages and hunt for something else again. Because the 
position of the scroll is not saved, one has to scroll down 
through the entire list.


It would be better, I think, if it was one single tab all in a 
single hierarchy that never reloaded the page so that it is 
easier to navigate quickly.


e.g.,

instead of

Package
atk
  atk.ActionIF
  atk.Action
  ...

we have

atk
  atk.ActionIF
 GetActionStruct
 GetStruct
 ...
  atk.Action
 ...
...


and so effectually combining both tabs. It should solve the 
issues that the current way has without really causing any 
problems. Everything should be collapsed by default and since no 
reloading of the page should occur(which might require having the 
api descriptions in a separate frame that is loaded separately on 
package changes to avoid reloading the tree view which will 
recollapse everything).


It will make navigating the gtkD api much more fun ;)




Re: Fix gtkD api display

2017-08-03 Thread Johnson Jones via Digitalmars-d-learn

Also, interfaces are not linkable.

e.g., for gtk.ApplicationWindow, it inherits from gtk.Window but 
I have to go back to the packages and scroll down to find 
gtk.Window to see it's properties and methods. Would be nice if I 
could just click on the gtk.Window and it jump me to it.


https://api.gtkd.org/gtkd/gtk/ApplicationWindow.html

class ApplicationWindow : gtk.Window.Window, 
gio.ActionGroupIF.ActionGroupIF, gio.ActionMapIF.ActionMapIF;


since the hierarchy is gtk/Window/Window, click on gtk should 
take one to the gtk package, the first Window should take one to 
gtk.Window and the second should take one to gtk.Window.Window




Re: OT: What causes the Segfault in the following?

2017-08-03 Thread Andrew Edwards via Digitalmars-d-learn

Steven Schveighoffer wrote:

On 8/3/17 9:12 PM, Andrew Edwards wrote:

Andrew Edwards wrote:

Just in case... here are the two functions being called in main():

https://github.com/vurtun/nuklear/blob/master/nuklear.h#L5695-L5722


Can you show how you declared these in D? It's important. I think what's
happening is that the nk_color_hex_rgb is incorrectly defined. I think
you should *always* get segfault, with or without any of those arrays.

-Steve


I certainly can, but the problem is completely in C, I'm not having any 
problems in D. In this case, I've simply copied the two functions to 
test.c and inserted main(). Here are my implementations though:


nk_color nk_rgb_hex(string rgb)
{
if (rgb[0] == '#') rgb = rgb[1..$];
return nk_color(cast(nk_byte)nk_parse_hex(rgb[0 .. 2]),
cast(nk_byte)nk_parse_hex(rgb[2 .. 4]),
cast(nk_byte)nk_parse_hex(rgb[4 .. $]), 255);
}

private void nk_color_hex_impl(int n)(out char[] output, nk_color col)
{
output.reserve(n);
alias NK_TO_HEX = (i) => i <= 9 ? '0' + i : 'A' - 10 + i;
foreach(color; col.tupleof) {
output ~= to!char(NK_TO_HEX((color & 0xF0) >> 4));
output ~= to!char(NK_TO_HEX(color & 0x0F));
}
}

void nk_color_hex_rgba(out char[] output, nk_color col)
{
nk_color_hex_impl!8(output, col);
}

void nk_color_hex_rgb(out char[] output, nk_color col)
{
 nk_color_hex_impl!6(output, col);
}

Not to happy with nk_color_hex_impl and family yet because I'm convinced 
there is a better way but for now that's what I've got.


Re: OT: What causes the Segfault in the following?

2017-08-03 Thread Steven Schveighoffer via Digitalmars-d-learn

On 8/3/17 10:14 PM, Andrew Edwards wrote:

Steven Schveighoffer wrote:

On 8/3/17 9:12 PM, Andrew Edwards wrote:

Andrew Edwards wrote:

Just in case... here are the two functions being called in main():

https://github.com/vurtun/nuklear/blob/master/nuklear.h#L5695-L5722


Can you show how you declared these in D? It's important. I think what's
happening is that the nk_color_hex_rgb is incorrectly defined. I think
you should *always* get segfault, with or without any of those arrays.



I certainly can, but the problem is completely in C, I'm not having any 
problems in D. In this case, I've simply copied the two functions to 
test.c and inserted main().


Oh. Then Ali is correct. I assumed that char *s was initialized to null 
because it was D, and maybe you were passing s by reference incorrectly. 
But actually, you are in c, so s can point anywhere.


Yeah, you need to declare an array instead of just a pointer.

char s[20] should work.

-Steve


Re: OT: What causes the Segfault in the following?

2017-08-03 Thread Andrew Edwards via Digitalmars-d-learn

Ali Çehreli wrote:

On 08/03/2017 06:02 PM, Andrew Edwards wrote:


char *s;


That's an uninitialized C string.


OK, I was is indeed the problem. I was thinking for some reason that s 
gets initialized inside nk_color_hex_rgb() but it's expecting to an 
array to work with. I actually noticed that couldn't, for the life of 
me, associate it to the cause of the resulting issue.





nk_color_hex_rgb(s, str);


That function is expecting it to have at least 7 chars when doing things
like

output[1] = (char)NK_TO_HEX((col.r & 0x0F));

So you have to have a proper pointer to the first element of an array to
pass to nk_color_hex_rgb. The following may work but you shouldn't be
needing to use magic constants like 7:
char[7] s;
nk_color_hex_rgb(s.ptr, str);
// ...
printf("%s\n", s.ptr);

There's probably the proper C macro that defines it so that you can do

  char[BLAH_LENGTH] s:

Ali





Re: OT: What causes the Segfault in the following?

2017-08-03 Thread Andrew Edwards via Digitalmars-d-learn

Steven Schveighoffer wrote:

On 8/3/17 10:14 PM, Andrew Edwards wrote:


I certainly can, but the problem is completely in C, I'm not having
any problems in D. In this case, I've simply copied the two functions
to test.c and inserted main().


Oh. Then Ali is correct. I assumed that char *s was initialized to null
because it was D, and maybe you were passing s by reference incorrectly.
But actually, you are in c, so s can point anywhere.

Yeah, you need to declare an array instead of just a pointer.

char s[20] should work.

-Steve


Much appreciated.


Re: OT: What causes the Segfault in the following?

2017-08-03 Thread Andrew Edwards via Digitalmars-d-learn

Ali Çehreli wrote:

On 08/03/2017 06:02 PM, Andrew Edwards wrote:


char *s;


That's an uninitialized C string.


OK, I was is indeed the problem. I was thinking for some reason that s 
gets initialized inside nk_color_hex_rgb() but it's expecting to an 
array to work with. I actually noticed that couldn't, for the life of 
me, associate it to the cause of the resulting issue.





nk_color_hex_rgb(s, str);


That function is expecting it to have at least 7 chars when doing things
like

output[1] = (char)NK_TO_HEX((col.r & 0x0F));

So you have to have a proper pointer to the first element of an array to
pass to nk_color_hex_rgb. The following may work but you shouldn't be
needing to use magic constants like 7:
char[7] s;
nk_color_hex_rgb(s.ptr, str);
// ...
printf("%s\n", s.ptr);


got you... this makes sense, but I'm doing it differently in D. See my 
response to Steven. I was only experiencing this issue in C.



There's probably the proper C macro that defines it so that you can do

  char[BLAH_LENGTH] s:

Ali



Much appreciated.


GtkD custom theme on Windows

2017-08-03 Thread Andres Clari via Digitalmars-d-learn
I've made a linux program with GtkD, and so far, it's been pretty 
awesome, however I'm thinking about porting it to Windows also, 
but the Adwaita theme is too fugly, and cringy, so I'd want to 
use a compatible theme, which is supposed to be doable.


What would be the way to go to make a GtkD app use a custom GTK 
theme in Windows?
I tried this in the past, but never succeeded following 
documentation found online.