Re: Where do I learn to use GtkD

2018-10-31 Thread helxi via Digitalmars-d-learn

On Tuesday, 30 October 2018 at 14:38:53 UTC, Michelle Long wrote:

On Sunday, 13 March 2016 at 19:28:57 UTC, karabuta wrote:
Gtk3 from python3 has got I nice book with examples that are 
not so advanced but enough to get you doing real work(from a 
beginner point of view). GtkD seem to have changed the API 
structure compared to python3 Gtk3 and the demo examples just 
"show-off" IMO :). The documentation is really^ not good :)


Any help on where I can get better leaning materials(GtkD)? 
Repo, blogs post, etc please


I will avoid using GTK for large projects. If can be used for 
simple things and you can automate a lot of acts(and use glade 
for UI design)... but it has some problems that will bite you 
in the long run.


Why is that, if I may ask? Is it the licensing concerns?

I'd just jump in to it, it's not too hard but hard to find the 
correct information. It will be a time investment of a few 
months.


Might try nuklearD first. Seems to be better in many aspects.


I believe the gtk stack is very comprehensive. It integrates to 
Linux desktops fairly well. Has nice power management rules, 
support for appID, and many widgets.


Re: CT BitArray

2018-10-31 Thread Stefan Koch via Digitalmars-d-learn
On Wednesday, 31 October 2018 at 23:14:08 UTC, Bastiaan Veelo 
wrote:
Currently, BitArray is not usable at compile time, so you 
cannot do

```
enum e = BitArray([1, 1, 1, 0]);
```
This gives
/dlang/dmd/linux/bin64/../../src/phobos/std/bitmanip.d(1190): 
Error: `bts` cannot be interpreted at compile time, because it 
has no available source code


IIUC, that is because `bts` comes from core.bitop but no source 
code is there. I am guessing these are filled in by compiler 
intrinsics or the like, and they are unavailable at CT, correct?


I suppose that alternative implementations of `btc`, `bts`, 
`btr`, `bsf` and `bt` could exist that do not use the runtime 
that could be used if(__ctfe) in the implementation of 
BitArray, that would make the above code work. Is this 
feasible? Is there precedent in phobos? Are there complications?


Thanks!


Oh that ... actually I can fix that with a small patch to dmd.

Tell me which version are you using and I'll make it for you.

Cheers,

Stefan


CT BitArray

2018-10-31 Thread Bastiaan Veelo via Digitalmars-d-learn
Currently, BitArray is not usable at compile time, so you cannot 
do

```
enum e = BitArray([1, 1, 1, 0]);
```
This gives
/dlang/dmd/linux/bin64/../../src/phobos/std/bitmanip.d(1190): 
Error: `bts` cannot be interpreted at compile time, because it 
has no available source code


IIUC, that is because `bts` comes from core.bitop but no source 
code is there. I am guessing these are filled in by compiler 
intrinsics or the like, and they are unavailable at CT, correct?


I suppose that alternative implementations of `btc`, `bts`, 
`btr`, `bsf` and `bt` could exist that do not use the runtime 
that could be used if(__ctfe) in the implementation of BitArray, 
that would make the above code work. Is this feasible? Is there 
precedent in phobos? Are there complications?


Thanks!



Re: std.math log and family

2018-10-31 Thread H. S. Teoh via Digitalmars-d-learn
On Wed, Oct 31, 2018 at 11:29:17AM +, kinke via Digitalmars-d-learn wrote:
> On Wednesday, 31 October 2018 at 01:26:19 UTC, H. S. Teoh wrote:
> > Is it true that on modern hardware computing with `real` reverts to
> > slow x87 emulation in the CPU instead of using SSE/MMX/whatever
> > native math functions?
> 
> You should have read recent DMD & LDC release notes. ;)
> https://github.com/dlang/phobos/pull/6272#issuecomment-373967109

Ah, very nice!  Thanks for the link.


T

-- 
Public parking: euphemism for paid parking. -- Flora


Re: How in the name of D do you deal with more than one optional template parameter?

2018-10-31 Thread aliak via Digitalmars-d-learn

On Tuesday, 30 October 2018 at 21:19:13 UTC, H. S. Teoh wrote:
On Tue, Oct 30, 2018 at 08:46:31PM +, aliak via 
Digitalmars-d-learn wrote:

[...]


struct C(Args...)
	if ((rest.length == 2 && is(Args[0] == B!C, C) && is(Args[1] 
== string)) ||
	(rest.length == 1 && (is(Args[0] == B!C, C) || is(Args[0] 
== string

{
...
}



Hah! Yep. That.



[...]

[...]


This is unnecessary.  Why not just use `void` directly?


Ah true, yes brain fart on my part.

I think it was left overs from a scenario where I didn't want to 
do this:


static if (!is(T == void)) {
  T variable;
}

Because a Void struct would be declared as well. But then one 
realises that everywhere you want to use "variable" you need to 
guard it with a static if so meh.




struct C(string name, T, string desc)
if (is(T : B!C, C) || is(T == void))
{
...
}



[...]

[...]

You can also use default parameters for templates:

struct C(string name, T, string desc = null)
{
...
}

then you just need one more alias for the string-only variant:

alias C(string name, string desc) = C!(name, void, desc);

Note that this syntax is much shorter than the full eponymous 
template syntax, which makes it easier to deal with longer 
parameter lists:


Ah nice! Yes that helps indeed :)



	struct ManyParams(A a, B b=defaultB, C c=defaultC, D 
d=defaultD)

{
...
}
	alias ManyParams(A a, C c, D d=defaultD) = ManyParams!(a, 
null, c, d);
	alias ManyParams(A a, D d=defaultD) = ManyParams!(a, void, 
void, d);


And so on.

And there's probably a way to auto-generate those alias 
templates if you anticipate needing to do this many times. (Or 
if you're insane and want to let the user specify different 
arguments in any order.) Mixins and CTFE codegen FTW!  :-D


Did I hear "specify different arguments in any order"? -> 
https://forum.dlang.org/thread/cjbqrpbpymwayzcgc...@forum.dlang.org.


:p

Cheers,
- Ali





T




Re: expanding variadic into format

2018-10-31 Thread Codifies via Digitalmars-d-learn
On Wednesday, 31 October 2018 at 12:54:52 UTC, Stanislav Blinov 
wrote:

On Wednesday, 31 October 2018 at 12:13:57 UTC, Codifies wrote:

[...]



[...]


As rikki already explained, std.format is a variadic template, 
which gets expanded into argument list at compile time. That's 
why it can't be used with C-syle variadics: when you passed 
_arguments, the expansion treated that as a single argument 
instead of a tuple.
Therefore, to forward arguments to std.format, your 
`printValue` must also be a variadic.


[...]


thanks for this makes it a lot clearer, I'm guessing there is a 
mailing list backing this web forum, as I replied missing some 
other responses.


Re: expanding variadic into format

2018-10-31 Thread Stanislav Blinov via Digitalmars-d-learn

On Wednesday, 31 October 2018 at 12:13:57 UTC, Codifies wrote:
On Wednesday, 31 October 2018 at 12:09:04 UTC, Stanislav Blinov 
wrote:



```
void printValue(Args...)(Font fnt, float x, float y, string 
frmt, auto ref Args args) {

// ...
import std.functional : forward;
string message = format(frmt, forward!args);
// ...
}
```


thats fantastic thanks so much, can you explain a little more 
about whats going on here ?


As rikki already explained, std.format is a variadic template, 
which gets expanded into argument list at compile time. That's 
why it can't be used with C-syle variadics: when you passed 
_arguments, the expansion treated that as a single argument 
instead of a tuple.
Therefore, to forward arguments to std.format, your `printValue` 
must also be a variadic.


There are, broadly speaking, two ways to pass arguments to 
functions: by value and by reference.


When you make a template like this:

void foo(T)(T value) { /* ... */ }

it will take the argument by value, making copies when necessary:

struct S { /* ... */ }

S s;
foo(S.init); // calls foo without copying, argument is 
constructed directly

foo(s); // copies `s` and passes that copy to `foo`

If that template is defined like this:

void foo(T)(ref T value) { /* ... */ }

then it will *only* take argument by reference:

foo(S.init); // error, 'ref' cannot bind to rvalue
foo(s); // no copy is made, `foo` takes `s` by reference

There are more subtleties, especially when taking `const ref` 
arguments, but I won't get into those.


There's a special syntax for template functions: `auto ref` 
arguments. Those are deduced to be by-value or by-reference at 
compile time (see

https://dlang.org/spec/template.html#auto-ref-parameters):

void foo(T)(auto ref T value) { /* ... */ }

foo(S.init); // works, compiles as foo(S);
foo(s); // works, compiles as foo(ref S);

But, because inside of function definition all arguments are 
lvalues, you lose this additional information if you pass them to 
another function directly. To preserve that information, there's 
a `forward` template in std.functional. D doesn't have rvalue 
references, so that template will still copy the bits of 
non-`ref` arguments, but it will not call postblits, etc (it 
`move`s them using std.algorithm.mutation.move).


So, there are two possible ways to implement your print:

// Take all Args by value, i.e. copy everything first time
void printValue(Args...)(Font fnt, float x, float y, string frmt, 
Args args) {
// make copies of every argument in `args` (again) and pass 
those to `format`

auto message = format(frmt, args);
}

or

// Infer whether each argument is an lvalue or not
void printValue(Args...)(Font fnt, float x, float y, string frmt, 
auto ref Args args) {

import std.functional : forward;
// preserve lvalue/rvalue
string message = format(frmt, forward!args);
}

Both allow you to accomplish your goal, but the second one only 
copies the argument bits when necessary.


Getting into finer implementation nuances, conceptually this 
allows a function to even take and pass around non-copyable types 
as arguments. Sadly, this is not widely adopted by Phobos, which 
likes to make unnecessary copies. I.e. the `format` function 
itself takes Args by value, even though it probably should take 
advantage of this specific language feature. But at least calling 
it via `forward`, you only make necessary copies once, instead of 
twice.




Re: expanding variadic into format

2018-10-31 Thread rikki cattermole via Digitalmars-d-learn

On 01/11/2018 1:08 AM, Codifies wrote:

On Wednesday, 31 October 2018 at 11:56:31 UTC, rikki cattermole wrote:

On 01/11/2018 12:53 AM, Codifies wrote:

[...]


Just to confirm, format there is std.format:format right?

Because that isn't using C variadics, its using template variadics.


thought I was using core.vararg and std.format both using templates ??


No. They use different variadics.

Template variadics happen on the template parameter side:

void func(T...)(T args) {
pragma(msg, T.length);
pragma(msg, T.stringof);
}

C variadics happen on the function parameters side and are highly unsafe:

void func(...) {

}

If you use core.vararg you're talking with C.
If you use std.format you're talking D's template variadics.


Re: expanding variadic into format

2018-10-31 Thread Codifies via Digitalmars-d-learn
On Wednesday, 31 October 2018 at 12:09:04 UTC, Stanislav Blinov 
wrote:

On Wednesday, 31 October 2018 at 11:53:52 UTC, Codifies wrote:


void printValue(Font fnt,float x, float y, string frmt, ...)
{
/* matrix math and other stuff removed for readability */
string message = format(frmt, _arguments);




is there some way to somehow transfer my input variadic into 
formats variadic ?



Just to confirm, format there is std.format:format right?
Because that isn't using C variadics, its using template 
variadics.


...as in:

```
void printValue(Args...)(Font fnt, float x, float y, string 
frmt, auto ref Args args) {

// ...
import std.functional : forward;
string message = format(frmt, forward!args);
// ...
}
```


thats fantastic thanks so much, can you explain a little more 
about whats going on here ?


Re: expanding variadic into format

2018-10-31 Thread Codifies via Digitalmars-d-learn
On Wednesday, 31 October 2018 at 11:56:31 UTC, rikki cattermole 
wrote:

On 01/11/2018 12:53 AM, Codifies wrote:

[...]


Just to confirm, format there is std.format:format right?

Because that isn't using C variadics, its using template 
variadics.


thought I was using core.vararg and std.format both using 
templates ??


Re: expanding variadic into format

2018-10-31 Thread Stanislav Blinov via Digitalmars-d-learn

On Wednesday, 31 October 2018 at 11:53:52 UTC, Codifies wrote:


void printValue(Font fnt,float x, float y, string frmt, ...)
{
/* matrix math and other stuff removed for readability */
string message = format(frmt, _arguments);




is there some way to somehow transfer my input variadic into 
formats variadic ?



Just to confirm, format there is std.format:format right?
Because that isn't using C variadics, its using template 
variadics.


...as in:

```
void printValue(Args...)(Font fnt, float x, float y, string frmt, 
auto ref Args args) {

// ...
import std.functional : forward;
string message = format(frmt, forward!args);
// ...
}
```


Re: expanding variadic into format

2018-10-31 Thread rikki cattermole via Digitalmars-d-learn

On 01/11/2018 12:53 AM, Codifies wrote:
I have a routine that was happily printing ASCII strings and values 
using opengl, however I want to improve it so it can be used in the same 
manner as some other languages printf function...


void printValue(Font fnt,float x, float y, string frmt, ...)
{
     /* matrix math and other stuff removed for readability */
     string message = format(frmt, _arguments);


no surprise this naive attempt causes a runtime error as its trying to 
format a range using the first format specifier in frmt


am I going to have to chop frmt into descrete chunks that have just one 
% symbol in them and then build up the formatted message string like that?


is there some way to somehow transfer my input variadic into formats 
variadic ?


Just to confirm, format there is std.format:format right?

Because that isn't using C variadics, its using template variadics.


expanding variadic into format

2018-10-31 Thread Codifies via Digitalmars-d-learn
I have a routine that was happily printing ASCII strings and 
values using opengl, however I want to improve it so it can be 
used in the same manner as some other languages printf function...


void printValue(Font fnt,float x, float y, string frmt, ...)
{
/* matrix math and other stuff removed for readability */
string message = format(frmt, _arguments);


no surprise this naive attempt causes a runtime error as its 
trying to format a range using the first format specifier in frmt


am I going to have to chop frmt into descrete chunks that have 
just one % symbol in them and then build up the formatted message 
string like that?


is there some way to somehow transfer my input variadic into 
formats variadic ?


Re: std.math log and family

2018-10-31 Thread kinke via Digitalmars-d-learn

On Wednesday, 31 October 2018 at 01:26:19 UTC, H. S. Teoh wrote:
Is it true that on modern hardware computing with `real` 
reverts to slow x87 emulation in the CPU instead of using 
SSE/MMX/whatever native math functions?


You should have read recent DMD & LDC release notes. ;)
https://github.com/dlang/phobos/pull/6272#issuecomment-373967109