Re: Indexed graphics for retro engine?

2019-09-18 Thread Mike Parker via Digitalmars-d-learn
On Thursday, 19 September 2019 at 03:47:05 UTC, Shadowblitz16 
wrote:
Is there a way to make a indexed graphics library that can 
handle importing and exporting true color images?


I don't see why not.



I would guess something like this could be simulated with 
pointers and references right?


If you want to, say, take a 24-bit or 32-bit and treat it as an 
8-bit image, you'll probably want to actually do a conversion 
rather than a simulation. In which case you'd probably be better 
off just using an existing C library like FreeImage. You can find 
a binding here:


https://github.com/BindBC/bindbc-freeimage

Otherwise, you'll want to hit up a graphics programming forum for 
resources on image conversion. Two possibilities:


https://www.reddit.com/r/GraphicsProgramming/

https://www.gamedev.net/forums/forum/5-graphics-and-gpu-programming/




Re: combining libraries into 1 or 1 for each system?

2019-09-18 Thread Mike Parker via Digitalmars-d-learn
On Thursday, 19 September 2019 at 03:44:28 UTC, Shadowblitz16 
wrote:

let's say I have a project the relies on multiple packages..
is it possible to combine these libraries into a single one (or 
1 per os) for final shipment of a program?


I assume you're referring to dub packages, in which case any 
dependencies you have will usually be configured to compile as 
static libraries. That means they'll be compiled into the 
executable without any extra effort on your part.


If they're configured as dynamic libraries, you'll need to ship 
the dynamic library with your executable or manually edit the 
configurations to compile as static libraries.


If they're bindings to C libraries, you'll need to ship the C 
dynamic libraries unless you statically link them.


If none of this answers your question, please clarify what you 
mean by "multiple packages".


Re: Collect Statistics efficiently and easily

2019-09-18 Thread Brett via Digitalmars-d-learn

On Tuesday, 17 September 2019 at 14:06:41 UTC, Paul Backus wrote:

On Tuesday, 17 September 2019 at 01:53:39 UTC, Brett wrote:
Many times I have to get statistical info which is simply 
compute statistics on a data set that may be generating or 
already generated.


The code usually is

M = max(M, v);
m = min(m, v);

but other things like standard deviation, mean, etc might need 
to be computed.


This may need to be done on several data sets simultaneously.

is there any way that one could just compute them in one line 
that is efficient, probably using ranges? I'd like to avoid 
having to loop through a data set multiple times as it would 
be quite inefficient.


You can use `std.algorithm.fold` to compute multiple results in 
a single pass:


auto stats = v.fold!(max, min);
M = stats[0];
m = stats[1];


That may work but I'm already iterating and doing it inside a 
loop.


I'm I'm specifically talking about is sort of abstract the 
computation of each statistic type.


If I were to convert my algorithm to be a range then maybe I 
could do similar to what you are saying but I would still require 
using more than min and max(such as avg, std, and others).


It may be viable but I'll have to think about it. I tend to find 
myself writing the same abstract code to compute the same 
statistics quite often(sometimes it deals with a history and 
sometimes not. E.g., I might want to compute the average and keep 
the last 5, or the 5 largest).







Re: Indexed graphics for retro engine?

2019-09-18 Thread Shadowblitz16 via Digitalmars-d-learn

*indexed color images and shapes


Indexed graphics for retro engine?

2019-09-18 Thread Shadowblitz16 via Digitalmars-d-learn
Is there a way to make a indexed graphics library that can handle 
importing and exporting true color images?


I would guess something like this could be simulated with 
pointers and references right?


Re: Indexed graphics for retro engine?

2019-09-18 Thread Shadowblitz16 via Digitalmars-d-learn
oh I would also like to be able to draw indexed images shapes as 
well.


combining libraries into 1 or 1 for each system?

2019-09-18 Thread Shadowblitz16 via Digitalmars-d-learn

let's say I have a project the relies on multiple packages..
is it possible to combine these libraries into a single one (or 1 
per os) for final shipment of a program?


How do I install modules into my project?

2019-09-18 Thread Shadowblitz16 via Digitalmars-d-learn

how do I install modules into my project?
I have installed dub and tried doing "dub add tkd" and "dub 
install tkd" to install this library 
https://github.com/nomad-software/tkd however I get this error 
when building..


Severity Code   Description Project FileLineSuppression State
Error	module `tkdapplication` is in file 'tkd\tkdapplication.d' 
which cannot be read


I am using visual d for visual studio 2019


Re: Is there a way to do the same thing in entry and return of a bunch of functions?

2019-09-18 Thread Stefanos Baziotis via Digitalmars-d-learn
On Wednesday, 18 September 2019 at 01:03:27 UTC, Nicholas Wilson 
wrote:


I think a mixin that does

string LOG_SCOPE = q{
callDepth++;
scope(exit) callDepth--;
}

is probably the easiest. for bonus points

string LOG_SCOPE = q{
callDepth++;
debug_log(__FUNCTION__);// or __PRETTY_FUNTION__
scope(exit) callDepth--;
}

and the mixin(LOG_SCOPE);


Yes that's what I meant sort of the mixin (where we can also put 
local scope inside etc.).


I mean you _could_ do some UDA reflection to generate wrapping 
function that do the indentation, bit that is overkill.


Interesting, I didn't know about that. I didn't completely get it 
but I get

that it seems the easier way to do it is the mixin.

Thanks,
Stefanos


Re: Deprecation message sources

2019-09-18 Thread Jacob Carlborg via Digitalmars-d-learn

On 2019-09-17 22:55, Johan Engelen wrote:


Wow. How come this is not caught by the CI testing?


That issue seems to be because "writeln" is printing "type", which is an 
enum. For enums, "writeln" prints the actual name of the enum member and 
not the value. It seems it extracts the names of all enum members and 
this particular enum contains deprecated members.


--
/Jacob Carlborg


Re: Deprecation message sources

2019-09-18 Thread Steven Schveighoffer via Digitalmars-d-learn

On 9/18/19 11:09 AM, H. S. Teoh wrote:

On Wed, Sep 18, 2019 at 10:48:27AM -0400, Steven Schveighoffer via 
Digitalmars-d-learn wrote:

On 9/17/19 8:14 PM, Jonathan M Davis wrote:

[...]

I suspect that deprecation messages are being triggered simply by
code trying to use Nullable in template constraints rather than just
when it's actually used in proper code, but I don't know.


I too, think that it's really the template constraints that are
causing so much grief. Not only that, but it's impossible to find the
code that's actually triggering the usage.


That's really annoying.  Why are constraints triggering deprecation
messages?  Shouldn't it be actual usage that trigger them?


Well, if the constraint is going to change the result when the symbol is 
actually removed, I'd say yes.


For example:

foo(int);

Nullable!int x;

static if(is(typeof(foo(x))) // true before removal, false after

But of course, my call isn't going to be that, that's going to be buried 
somewhere deep in a template.



I've also seen similar in my own projects, and it's an eyesore, esp.
since it was Phobos code that was triggering the messages, not actually
anything in my own code.


Yeah, I would like to see where the deprecation is being triggered in MY 
code. I don't think -de will work, because then it simply changes what 
the is-expression returns, rather than show me the full trace of what I 
was trying to instantiate.


Really annoying.

-Steve


Re: segmentation fault when running void main() {}

2019-09-18 Thread berni via Digitalmars-d-learn

On Wednesday, 18 September 2019 at 13:57:53 UTC, ag0aep6g wrote:

You're probably hitting this issue:
https://issues.dlang.org/show_bug.cgi?id=19116


Yes, sounds similar. I tried PR 9981, but that didn't work on my 
machine. Similar message, just an other file, that cannot be 
compiled (dmd/backend/optabgen.d if it matters).


The hello-example in issue 19116 didn't work either. Got a lot of

/usr/bin/ld: hello.o/(.eh_frame+0x47): undefined reference to 
´__dmd_peronsality_v0´


and the like.


Re: Problem with using std.math: abs and std.complex: abs at the same time

2019-09-18 Thread H. S. Teoh via Digitalmars-d-learn
On Wed, Sep 18, 2019 at 12:37:28PM +, Simen Kjærås via Digitalmars-d-learn 
wrote:
[...]
> template MergeOverloads(T...) {
> alias MergeOverloads = T[0];
> static if (T.length > 1) {
> alias MergeOverloads = MergeOverloads!(T[1..$]);
> }
> }
> 
> I would however label that a horrible hack.
> 
> FWIW, I've filed this issue: https://issues.dlang.org/show_bug.cgi?id=20226
[...]

Horrible or not, it's very clever. I wouldn't have thought of that!

But yeah, the way alias can't be overloaded inside a function body is
kinda stupid, esp. seeing that aliasing an overload is exactly how you
resolve an analogous problem inside class scope:

class Base {
int abs(int);
}
class Derived : Base {
float abs(float); // causes ambiguity
alias abs = Base.abs; // brings Base.abs into overload set
void func() {
// now abs(...) will correctly use overload sets
}
}

I would have expected you could do this in function scope as well, and
was surprised the compiler rejected it.


T

-- 
Famous last words: I wonder what will happen if I do *this*...


Re: Deprecation message sources

2019-09-18 Thread H. S. Teoh via Digitalmars-d-learn
On Wed, Sep 18, 2019 at 10:48:27AM -0400, Steven Schveighoffer via 
Digitalmars-d-learn wrote:
> On 9/17/19 8:14 PM, Jonathan M Davis wrote:
[...]
> > I suspect that deprecation messages are being triggered simply by
> > code trying to use Nullable in template constraints rather than just
> > when it's actually used in proper code, but I don't know.
> 
> I too, think that it's really the template constraints that are
> causing so much grief. Not only that, but it's impossible to find the
> code that's actually triggering the usage.

That's really annoying.  Why are constraints triggering deprecation
messages?  Shouldn't it be actual usage that trigger them?

I've also seen similar in my own projects, and it's an eyesore, esp.
since it was Phobos code that was triggering the messages, not actually
anything in my own code.


T

-- 
If the comments and the code disagree, it's likely that *both* are wrong. -- 
Christopher


Re: static if (is (T==Complex))

2019-09-18 Thread Steven Schveighoffer via Digitalmars-d-learn

On 9/18/19 7:10 AM, berni wrote:

Is it possible to simplfy this?

static if (is (T==Complex!double) || is (T==Complex!float) || is 
(T==Complex!real))


https://dlang.org/phobos/std_traits.html#TemplateOf

import std.traits : TemplateOf;

static if(__traits(isSame, TemplateOf!T, Complex))

-Steve


Re: Deprecation message sources

2019-09-18 Thread Steven Schveighoffer via Digitalmars-d-learn

On 9/17/19 8:14 PM, Jonathan M Davis wrote:

On Tuesday, September 17, 2019 2:34:00 PM MDT Steven Schveighoffer via
Digitalmars-d-learn wrote:

On 9/17/19 4:16 PM, Anonymouse wrote:

On Tuesday, 17 September 2019 at 19:31:53 UTC, Steven Schveighoffer

wrote:

I'd hate to say the answer is to special case Nullable for so many
functions, but what other alternative is there?

-Steve


Nullable isn't alone, std.json.JSONType causes a literal wall of text of
deprecation warnings.

import std.stdio;
import std.json;

void main()
{

  writeln(JSONValue.init.type);

}

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


I mean, I'm OK with the idea, but having these deprecation messages is
helping nobody. I can't figure out if there's something I'm supposed to,
or can, change in order to get rid of them.

There are quite a few places where it is flagging my code for Nullable
usage without get, and I'm fixing those. But I'll still be left with
this mess of deprecation messages from Phobos and vibe.d. I don't even
know where or if it will break once the alias this is removed.


I ran into problems along those lines with dxml recently, and I couldn't
figure out why one of the deprecation messages was being triggered. It
seemed to have to do with isInputRange, but I couldn't figure out where in
my code was resulting in that problem. I tried to track it down by compiling
Phobos with the alias this outright removed from Nullable (with the idea
that I'd then hopefully get some decent error messages wherever the real
problem was), and dxml's tests then compiled and ran just fine with no
deprecation messages. So, I don't know what to do about it. I suspect that
deprecation messages are being triggered simply by code trying to use
Nullable in template constraints rather than just when it's actually used in
proper code, but I don't know.


I too, think that it's really the template constraints that are causing 
so much grief. Not only that, but it's impossible to find the code 
that's actually triggering the usage.


Maybe the best idea then is to use a version. In other words, you 
compile your code with version=nullableRequiresGet, and then it aliases 
Nullable to a new type (to avoid symbol conflicts) that requires get 
without the deprecation? After the deprecation, just replace the alias 
with the real Nullable. Then at least you can update your code to get 
rid of all the deprecation messages.


-Steve


Re: Program exited with code -11

2019-09-18 Thread Adam D. Ruppe via Digitalmars-d-learn

On Wednesday, 18 September 2019 at 13:36:30 UTC, Arjan wrote:

On Wednesday, 18 September 2019 at 13:22:03 UTC, Danny Arends

"Program exited with code -11"


Not signal 11? On unix/linux I assume?


Same thing. This is a segmentation fault.

Compile the program with the -g switch to dmd, then run it inside 
the gdb program



gdb --args ./your_program any_args_to_your_program

the hit the "r" command to run and when it crashes, it will tell 
you where. probably a null pointer.


Re: segmentation fault when running void main() {}

2019-09-18 Thread ag0aep6g via Digitalmars-d-learn

On 17.09.19 20:03, berni wrote:
I'm trying to install D on my old 32-bit machine (debian stable). First 
I tried to install a precompiled version and now I followed [1]. In both 
cases, I always get a segmentation fault when I try to run a compiled 
program.


You're probably hitting this issue:
https://issues.dlang.org/show_bug.cgi?id=19116


Re: Program exited with code -11

2019-09-18 Thread Danny Arends via Digitalmars-d-learn

On Wednesday, 18 September 2019 at 13:36:30 UTC, Arjan wrote:
On Wednesday, 18 September 2019 at 13:22:03 UTC, Danny Arends 
wrote:

Hey all,

"Program exited with code -11"


Not signal 11? On unix/linux I assume?


It's on linux yes...

No idea if it is a signal or an exitcode, the only indication is 
the text:

"Program exited with code -11"



Re: Program exited with code -11

2019-09-18 Thread Arjan via Digitalmars-d-learn
On Wednesday, 18 September 2019 at 13:22:03 UTC, Danny Arends 
wrote:

Hey all,

"Program exited with code -11"


Not signal 11? On unix/linux I assume?




Program exited with code -11

2019-09-18 Thread Danny Arends via Digitalmars-d-learn

Hey all,

I have written some code to analyze massive gzipped files (using 
std.iopipe), tested it on small subsets of the gzip files, and 
everything works using small 20 to 50 Mb files.


However when I try to run the code on 2.7 Gb file sizes the 
program always crashes with the following error:


"Program exited with code -11"

No other messages, did anyone ever encounter something like this 
before / got any ideas on how to figure out what is wrong ?


Danny




Re: Problem with using std.math: abs and std.complex: abs at the same time

2019-09-18 Thread berni via Digitalmars-d-learn
On Wednesday, 18 September 2019 at 12:37:28 UTC, Simen Kjærås 
wrote:
How to resolve this, though? The simplest solution is to not 
use selective imports:


import std.math;
import std.complex;

writeln(abs(complex(1.0,1.0)));
writeln(abs(1.0));


That works. But: I'm trying to write some code for math.d and 
when I put this code inside math.d it doesn't work anymore. Also 
removing "import std.math" or moving it after the other import, 
did not help.




Re: When should we use Modules and when Should we use Classes?

2019-09-18 Thread Adam D. Ruppe via Digitalmars-d-learn
You can only have one instance of a module, so it is really more 
a collection of types, functions, etc. that help each other do a 
particular job.


Then structs and classes can have multiple objects of each type 
so you use them to do most the stuff you run. You can make class 
objects in a loop or array, you can make temporary ones, 
replacable ones, etc. Modules cannot do any of that.


So in short:

* use a module to group classes and functions
* use a class when you need to subclass it and customize 
functionality and/or need several instances
* use a struct for most other cases, it is a generic collection 
of data


Re: Problem with using std.math: abs and std.complex: abs at the same time

2019-09-18 Thread Simen Kjærås via Digitalmars-d-learn

On Wednesday, 18 September 2019 at 12:03:28 UTC, berni wrote:

The following code doesn't compile:


import std.stdio;

void main()
{
   import std.complex: abs, complex;
   import std.math: abs;

   auto a = complex(1.0,1.0);
   auto b = 1.0;

   writeln(abs(a));
   writeln(abs(b));
}


The error message depends on the order of the two import 
statements. Seems like the second import is actually ignored.


import std.complex: abs, complex;

Is treated by the compiler as if you'd written something somewhat 
like this:


static import std.complex;
alias abs = std.complex.abs;
alias complex = std.complex.complex;

When you add

import std.math: abs;

It's treated like:

static import std.math;
alias abs = std.math.abs;

In other words, we have two aliases with the same name inside a 
function scope, and the compiler can't do that (try doing it 
explicitly, as in the 'treated like' sections above - you'll get 
a compilation error). This is related to why you can't have 
overloaded nested functions:


unittest {
void fun() {}
void fun(int i) {} // declaration fun is already defined
}

How to resolve this, though? The simplest solution is to not use 
selective imports:


import std.math;
import std.complex;

writeln(abs(complex(1.0,1.0)));
writeln(abs(1.0));

If you absolutely can't contaminate the scope with all the unused 
symbols in std.math and std.complex, you *can* do this:


import std.stdio;

unittest {
import std.complex : complex;
static import std.math;

alias abs = MergeOverloads!(std.complex.abs, std.math.abs);

auto a = complex(1.0,1.0);
auto b = 1.0;

writeln(abs(a));
writeln(abs(b));
}

template MergeOverloads(T...) {
alias MergeOverloads = T[0];
static if (T.length > 1) {
alias MergeOverloads = MergeOverloads!(T[1..$]);
}
}

I would however label that a horrible hack.

FWIW, I've filed this issue: 
https://issues.dlang.org/show_bug.cgi?id=20226


--
  Simen


Re: Problem with using std.math: abs and std.complex: abs at the same time

2019-09-18 Thread Daniel Kozak via Digitalmars-d-learn
On Wed, Sep 18, 2019 at 2:05 PM berni via Digitalmars-d-learn
 wrote:
>
> The following code doesn't compile:
>
> >import std.stdio;
> >
> >void main()
> >{
> >import std.complex: abs, complex;
> >import std.math: abs;
> >
> >auto a = complex(1.0,1.0);
> >auto b = 1.0;
> >
> >writeln(abs(a));
> >writeln(abs(b));
> >}
>
> The error message depends on the order of the two import
> statements. Seems like the second import is actually ignored.
>
> I hoped for a mechanism similar to overloading, which makes the
> compiler decide, which "abs" to use, depending on the type of the
> operand. Is there a way to do this? (As the code appears inside a
> template, something like std.math.abs() with static import
> doesn't work out well.)

import std.stdio;

void main()
{
import std.complex: abs, complex;
import std.math: mabs = abs;

auto a = complex(1.0,1.0);
auto b = 1.0;

writeln(abs(a));
writeln(mabs(b));
}


Re: Problem with using std.math: abs and std.complex: abs at the same time

2019-09-18 Thread Andrea Fontana via Digitalmars-d-learn

On Wednesday, 18 September 2019 at 12:03:28 UTC, berni wrote:

The following code doesn't compile:


import std.stdio;

void main()
{
   import std.complex: abs, complex;
   import std.math: abs;

   auto a = complex(1.0,1.0);
   auto b = 1.0;

   writeln(abs(a));
   writeln(abs(b));
}


What about https://run.dlang.io/is/PGasQD ?



Problem with using std.math: abs and std.complex: abs at the same time

2019-09-18 Thread berni via Digitalmars-d-learn

The following code doesn't compile:


import std.stdio;

void main()
{
   import std.complex: abs, complex;
   import std.math: abs;

   auto a = complex(1.0,1.0);
   auto b = 1.0;

   writeln(abs(a));
   writeln(abs(b));
}


The error message depends on the order of the two import 
statements. Seems like the second import is actually ignored.


I hoped for a mechanism similar to overloading, which makes the 
compiler decide, which "abs" to use, depending on the type of the 
operand. Is there a way to do this? (As the code appears inside a 
template, something like std.math.abs() with static import 
doesn't work out well.)


Re: static if (is (T==Complex))

2019-09-18 Thread berni via Digitalmars-d-learn

On Wednesday, 18 September 2019 at 11:25:21 UTC, Norm wrote:

I usually do something like the following:


Ah great. I was looking for "is(T == Complex!R, R)". :-) Thanks!


DUB WTF?

2019-09-18 Thread Daniel Kozak via Digitalmars-d-learn
Why is dub automaticaly changing dub.sdl from packages to 
dub.json?


Re: static if (is (T==Complex))

2019-09-18 Thread Norm via Digitalmars-d-learn

On Wednesday, 18 September 2019 at 11:10:11 UTC, berni wrote:

Is it possible to simplfy this?

static if (is (T==Complex!double) || is (T==Complex!float) || 
is (T==Complex!real))


I usually do something like the following:
---
import std.traits;


template isComplexReal(T) {

  enum isComplexReal = is(T == Complex!R, R) && 
(isFloatingPoint!R);

}


static if(isComplexReal!T) {// do something}
---


static if (is (T==Complex))

2019-09-18 Thread berni via Digitalmars-d-learn

Is it possible to simplfy this?

static if (is (T==Complex!double) || is (T==Complex!float) || is 
(T==Complex!real))


When should we use Modules and when Should we use Classes?

2019-09-18 Thread BoQsc via Digitalmars-d-learn

Would be nice to have a short summary or detailed answer on this.

Some resources to discuss this topic:
https://dlang.org/spec/class.html
https://dlang.org/spec/module.html


Re: segmentation fault when running void main() {}

2019-09-18 Thread berni via Digitalmars-d-learn
On Tuesday, 17 September 2019 at 18:13:06 UTC, Adam D. Ruppe 
wrote:
Did you make sure the old version was totally uninstalled 
before the new version was attempted to be built? This thing 
often happens because of a compiler/runtime version mismatch, 
typically because the old version didn't get fully removed 
first.


Well, there was no old version. It's been the first time I tried 
to install D on than computer. Meanwhile I removed my first 
attempt, using the install script mentioned on the download page. 
And I removed also gdc and ldc (the last one also not working). 
But that didn't help...