Re: Unexpected behaviour of foreach statement

2018-03-02 Thread bauss via Digitalmars-d-learn

On Friday, 2 March 2018 at 10:21:39 UTC, Arredondo wrote:

Hi,

The following works as expected:

auto range = [1, 2, 3, 4, 5];
foreach (i, el; range) {
writeln(i, ": ", el);
}

but this slight modification doesn't:

auto range = iota(5);
foreach (i, el; range) {
writeln(i, ": ", el);
}

DMD 2.078.3 says:
Error: cannot infer argument types, expected 1 argument, not 2

The error message is not helpful either, because indicating the 
types, as in:


foreach (int i, int el; range) { ... }

throws the same error.
What's going on here?

Arredondo


What you want to do is call "enumerate" from "std.range".

auto range = iota(5).enumerate;

foreach (i, el; range) {
writeln(i, ": ", el);
}

You can also call "array" from "std.array".

auto range = iota(5).array;

foreach (i, el; range) {
writeln(i, ": ", el);
}



Re: is it regression?

2018-02-28 Thread bauss via Digitalmars-d-learn

On Wednesday, 28 February 2018 at 13:38:56 UTC, drug wrote:

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


I would argue that isn't a regression and that you __should__ use 
the .get and that it's not a workaround, because nullable's 
shouldn't be treated like that type they encapsulate.


std.math members such as approxEqual shouldn't have to take 
nullable into account.


Re: DerelictGL3 and glBegin() access violation.

2018-02-28 Thread bauss via Digitalmars-d-learn

On Wednesday, 28 February 2018 at 12:02:27 UTC, Kayomn wrote:
Maybe I'm missing something, but whenever I attempt to call 
glBegin() with anything my program immediately encounters an 
access violation.


I've got a very simple setup, with this being my main:

import base.application;

import derelict.opengl3.gl3;
import derelict.glfw3.glfw3;

int main(string[] args) {
DerelictGL3.load();

version (Windows) {
DerelictGLFW3.load(".\\dll\\glfw3.dll");
} else {
DerelictGLFW3.load();
}
return Application(args).run();
}

And I'm remembering to reload after creating the GL context in 
the window class:


public this(int width,int height,string title) {
if (glfwInit()) {
// Hint configuration.
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR,3);
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR,3);
glfwWindowHint(GLFW_RESIZABLE,false);
glfwWindowHint(GLFW_OPENGL_PROFILE,GLFW_OPENGL_CORE_PROFILE);

this.nextTick = Time.getTicks();
this.handle = glfwCreateWindow(
this.width = width,
this.height = height,
toStringz(this.title = title),
null,
null
);

if (this.handle is null) {
// Failure.
			Debug.log("GLFW Error: Failed to create window handle 
instance.");

glfwTerminate();
} else {
import derelict.opengl3.gl3 : DerelictGL3;

// Set positon.
glfwSetWindowPos(this.handle,100,100);
glfwMakeContextCurrent(this.handle);
DerelictGL3.reload();
}
} else {
Debug.log("GLFW Error: Failed to intialize.");
}
}

Is this a DerelictGL3 bug? Am I missing something else that I 
should be initializing? Other things like glClear() seem to be 
working fine.


Most likely a library issue. Are you sure that you link to the 
libraries correctly etc.?


Re: Where can get the strsafe.d by strsafe.h ? Thanks.

2018-02-24 Thread bauss via Digitalmars-d-learn

On Saturday, 24 February 2018 at 14:58:52 UTC, FrankLike wrote:

Hi,everyone,
Now,I use some code in strsafe.h,but where can get the 
strsafe.d ?


Thanks.


Basically nowhere.

strsafe.h is non-standard.

What you have to do is create the binding yourself.


Re: Vibe.d no more using static this() {}

2018-02-24 Thread bauss via Digitalmars-d-learn

On Friday, 23 February 2018 at 23:11:13 UTC, aberba wrote:
I recently noticed vibe.d now using main loop which call the 
vibe.d event loop. Why that change?


I can only assume it's because static constructors are a pain in 
the ass.


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


Re: Function overloading between modules

2018-02-23 Thread bauss via Digitalmars-d-learn

On Thursday, 22 February 2018 at 21:12:45 UTC, JN wrote:

Is this expected behaviour?

bar.d
---
void foo(string s)
{
}


app.d
---

import std.stdio;
import bar;

void foo(int x)
{
}

void main()
{
  foo("hi");
};


===
Error: function app.foo (int x) is not callable using argument 
types (string)


https://dlang.org/articles/hijack.html


Re: array/Array: "hard" bounds checking

2018-02-22 Thread bauss via Digitalmars-d-learn
On Thursday, 22 February 2018 at 05:22:19 UTC, TheFlyingFiddle 
wrote:


Eg:

uint a = 3;
int b = -1;

assert(a > b); //No idea what should happen here.


This is what happens:

assert(cast(int)a > b);


Generic Property Implementation

2018-02-20 Thread bauss via Digitalmars-d-learn
Would there be a reason why this wouldn't be a good 
implementation?


If so what and how could it be improved?

Are there flaws in an implementation like this?

struct Property(T, bool readOnly = false)
{
import std.traits : isScalarType, isArray, 
isAssociativeArray, isSomeString;


private T _value;

T __GET() { return _value; }

static if (readOnly)
{
private
{
void __SET(T newValue) { _value = newValue; }

void opAssign(T newValue)
{
__SET(newValue);
}
}
}
else
{
void __SET(T newValue) { _value = newValue; }

void opAssign(T newValue)
{
__SET(newValue);
}
}

bool opEquals(T other)
{
static if (isScalarType!T || isArray!T || 
isAssociativeArray!T)

{
return _value == other;
}
else
{
if (_value is other) return true;
if (_value is null || other is null) return false;
if (typeid(_value) == typeid(other)) return 
_value.opEquals(other);
return _value.opEquals(other) && 
other.opEquals(_value);

}
}

static if (!(isArray!T) && !(isAssociativeArray!T))
{
int opCmp(T other)
{
static if (isScalarType!T)
{
if (_value < other) return -1;
if (_value > other) return 1;

return 0;
}
else
{
return _value.opCmp(other);
}
}
}

string toString()
{
static if (isArray!T && isSomeString!T)
{
return _value;
}
else static if (__traits(hasMember, T, "toString"))
{
return _value.toString();
}
else
{
import std.conv : to;

return to!string(_value);
}
}

alias __GET this;
}

alias ReadOnlyProperty(T) = Property!(T, true);

---

This would allow something like this:

class Foo
{
ReadOnlyProperty!int bar;

Property!string baz;

Property!int faz;

Property!Bar bar2;
}

class Bar
{
int boo;
}

Which can be used like:

auto foo = new Foo;
foo.baz = "Hello";
foo.baz = foo.baz ~ " World!";
foo.faz = 250 + foo.bar;

foo.bar2 = new Bar;
foo.bar2.boo = 200;

import std.stdio;

writeln(foo.bar);
writeln(foo.baz);
writeln(foo.faz);
writeln(foo.bar2.boo);



Re: is this a bug with writeln / std.algorithm.remove?

2018-02-16 Thread bauss via Digitalmars-d-learn

On Friday, 16 February 2018 at 13:08:09 UTC, bauss wrote:

On Friday, 16 February 2018 at 12:15:07 UTC, arturg wrote:

On Friday, 16 February 2018 at 11:45:21 UTC, arturg wrote:

this code fails to compile:

void delegate(void*) dg;
void delegate(void*)[] dgs = [dg, dg, dg];
dgs.writeln;
dgs.remove(1).writeln();

if you comment out dgs.writeln; it works as expected,
it works if you use other types then void*:

void delegate(int*) dg;
void delegate(int*)[] dgs = [dg, dg, dg];
dgs.writeln;
dgs.remove(1).writeln();


the compiler is DMD64 D Compiler v2.078.2 and the error 
message is:


/usr/include/dlang/dmd/std/algorithm/mutation.d(1929): Error: 
template std.algorithm.mutation.moveAll cannot deduce 
function from argument types !()(void delegate(void*)[], void 
delegate(void*)[]), candidates are:
/usr/include/dlang/dmd/std/algorithm/mutation.d(1455):
std.algorithm.mutation.moveAll(InputRange1, 
InputRange2)(InputRange1 src, InputRange2 tgt) if 
(isInputRange!InputRange1 && isInputRange!InputRange2 && 
is(typeof(move(src.front, tgt.front
empty.d(9): Error: template instance 
std.algorithm.mutation.remove!(cast(SwapStrategy)2, void 
delegate(void*)[], int) error instantiating


running all dmd version on run.dlang.io
gives me this output:

Up to  2.075.1: Success with output:
-
[void delegate(void*), void delegate(void*), void 
delegate(void*)]

[void delegate(void*), void delegate(void*)]
-

Since  2.076.1: Failure with output:
-
/path/to/dmd.linux/dmd2/linux/bin64/../../src/phobos/std/algorithm/mutation.d(1929):
 Error: template std.algorithm.mutation.moveAll cannot deduce function from 
argument types !()(void delegate(void*)[], void delegate(void*)[]), candidates 
are:
/path/to/dmd.linux/dmd2/linux/bin64/../../src/phobos/std/algorithm/mutation.d(1455):
std.algorithm.mutation.moveAll(InputRange1, InputRange2)(InputRange1 src, InputRange2 tgt) if 
(isInputRange!InputRange1 && isInputRange!InputRange2 && 
is(typeof(move(src.front, tgt.front
onlineapp.d(7): Error: template instance 
std.algorithm.mutation.remove!(cast(SwapStrategy)2, void 
delegate(void*)[], int) error instantiating

-


It's definitely a bug, the question is what change has caused 
it.


Looking at "moveAll" which is the one that causes the error, no 
changes has been made to that which could cause this as within 
the last 3 months only changes made to it has been two asserts 
that has been inserted. Other than that has only been a 
documentation change a year ago and prior to that changes hasn't 
been made to it for 3 years.


So it's a bug in the compiler, rather than Phobos itself.



Re: is this a bug with writeln / std.algorithm.remove?

2018-02-16 Thread bauss via Digitalmars-d-learn

On Friday, 16 February 2018 at 12:15:07 UTC, arturg wrote:

On Friday, 16 February 2018 at 11:45:21 UTC, arturg wrote:

this code fails to compile:

void delegate(void*) dg;
void delegate(void*)[] dgs = [dg, dg, dg];
dgs.writeln;
dgs.remove(1).writeln();

if you comment out dgs.writeln; it works as expected,
it works if you use other types then void*:

void delegate(int*) dg;
void delegate(int*)[] dgs = [dg, dg, dg];
dgs.writeln;
dgs.remove(1).writeln();


the compiler is DMD64 D Compiler v2.078.2 and the error 
message is:


/usr/include/dlang/dmd/std/algorithm/mutation.d(1929): Error: 
template std.algorithm.mutation.moveAll cannot deduce function 
from argument types !()(void delegate(void*)[], void 
delegate(void*)[]), candidates are:
/usr/include/dlang/dmd/std/algorithm/mutation.d(1455):
std.algorithm.mutation.moveAll(InputRange1, 
InputRange2)(InputRange1 src, InputRange2 tgt) if 
(isInputRange!InputRange1 && isInputRange!InputRange2 && 
is(typeof(move(src.front, tgt.front
empty.d(9): Error: template instance 
std.algorithm.mutation.remove!(cast(SwapStrategy)2, void 
delegate(void*)[], int) error instantiating


running all dmd version on run.dlang.io
gives me this output:

Up to  2.075.1: Success with output:
-
[void delegate(void*), void delegate(void*), void 
delegate(void*)]

[void delegate(void*), void delegate(void*)]
-

Since  2.076.1: Failure with output:
-
/path/to/dmd.linux/dmd2/linux/bin64/../../src/phobos/std/algorithm/mutation.d(1929):
 Error: template std.algorithm.mutation.moveAll cannot deduce function from 
argument types !()(void delegate(void*)[], void delegate(void*)[]), candidates 
are:
/path/to/dmd.linux/dmd2/linux/bin64/../../src/phobos/std/algorithm/mutation.d(1455):
std.algorithm.mutation.moveAll(InputRange1, InputRange2)(InputRange1 src, InputRange2 tgt) if 
(isInputRange!InputRange1 && isInputRange!InputRange2 && 
is(typeof(move(src.front, tgt.front
onlineapp.d(7): Error: template instance 
std.algorithm.mutation.remove!(cast(SwapStrategy)2, void 
delegate(void*)[], int) error instantiating

-


It's definitely a bug, the question is what change has caused it.


Re: How to check if aggregate member is static templated method?

2018-02-16 Thread bauss via Digitalmars-d-learn

On Thursday, 15 February 2018 at 15:49:47 UTC, RazvanN wrote:

On Thursday, 15 February 2018 at 13:51:41 UTC, drug wrote:

15.02.2018 16:50, drug пишет:

https://run.dlang.io/is/zHT2XZ
I can check againts if member is either static function or 
template. But I failed to check if it both static and 
templated.


The best I could come up with is:

struct Foo
{
static staticMethod()
{
}

static templatedStaticMethod(T)(T t)
{
}
}

void main()
{
static if(__traits(isTemplate, Foo.templatedStaticMethod) &&
  __traits(isStaticFunction, 
Foo.templatedStaticMethod!int))

{
 writeln("win");
}
}

It seems like a templated method can be queried if it is static 
only after it's instantiation. Hope this helps.


Cheers,
RazvanN


I would kinda argue that it's a bug, because checking whether a 
template function is static can become very complex if the 
template also has constraints etc.


Re: getSymbolsByUDA does not take private symbols under consideration. Should I file a bug?

2018-02-16 Thread bauss via Digitalmars-d-learn

On Friday, 16 February 2018 at 09:26:47 UTC, Piotr Mitana wrote:

Hello,

The code below:


import std.traits;

enum Attr;

class MyClass
{
private @Attr int a;
static assert(getSymbolsByUDA!(typeof(this), 
MyClass).length == 1);

}


does not compile as static assertion fails. Making the filed a 
public makes it compile properly. Should I file a bug or is by 
design?


It's definitely a bug!


Re: import strangeness with std.stdio.write

2018-02-13 Thread bauss via Digitalmars-d-learn
On Tuesday, 13 February 2018 at 13:56:17 UTC, psychoticRabbit 
wrote:
On Tuesday, 13 February 2018 at 13:52:37 UTC, rikki cattermole 
wrote:

On 13/02/2018 1:46 PM, psychoticRabbit wrote:

So, strange problem below.

The commented-out line will not compile (if I un-comment it), 
unless I either move std.stdio into main, or, move std.file 
out of main.


Whereas writeln works just fine as is.

-
module test;

import std.stdio;

void main()
{
     import std.file;

     //write("hello");
     writeln("hello again");
}
---


write exists in both, writeln exists only in std.stdio.

Use named imports to pick which write you want.


oh..you must have posted as I why posting ;-)

That makes sense then. Thanks for clearing that up.

And I should have read the compiler message more clearly..cause 
the answer was in that error message (more or less)


What you can do is use aliases to use both functions.

import io = std.stdio;

void main()
{
import file = std.file;

file.write("hello");
io.writeln("hello again");
}


Re: How to imporve D-translation of these Python list comprehensions ?

2018-02-01 Thread bauss via Digitalmars-d-learn

On Thursday, 1 February 2018 at 11:59:23 UTC, Russel Winder wrote:
On Mon, 2018-01-15 at 21:13 +, lobo via Digitalmars-d-learn 
wrote:

On Monday, 15 January 2018 at 19:05:52 UTC, xenon325 wrote:
> A workmate has recently shown this piece of code to show how 
> nice Python is (we are mostly C and growing C++ shop):
> 
> [...]


Well if that is what they can do in Python I'd hate to see 
their C++! They have done a great job making Python code read 
like Perl. This looks like something you'd see in an 
assignment at uni; "Decipher this Python code and port to your 
language of choice" :)


Apart from the slur on Perl, I have to agree with this. Using a 
dreadful bit of Python code is the start of a downward spiral 
of expectation and programming in other languages.


As noted earlier, I am working on a nicer rendering of this 
algorithm, and will be happy to share if people are interested.


I'd be interested in seeing the result.


Re: Discarded return values

2018-01-30 Thread bauss via Digitalmars-d-learn

On Tuesday, 30 January 2018 at 10:49:54 UTC, Simen Kjærås wrote:
Is there a way to get a compile error when returning a 
temporary from a function and then not assigning it to a 
variable or passing it to a different function? E.g:


struct S {
int[] a;
void morph() {}
}

@warnOnDiscard
S foo() {
return S([1,2,3]);
}

unittest {
auto a = foo(); // Fine, assigned to variable.
bar(foo()); // Fine, passed to other function.
foo();  // Error: return value is discarded.
foo().morph();  // Error: return value is discarded.
}

I know that pure functions give errors when their results are 
discarded, but in this case foo() might not be pure.

--
  Simen


On top of what's said.

It would be very complex to implement properly.

For example the following should fail, but will be very hard for 
the compiler to actually track.


struct S {
int[] a;
void morph() {}
}

@warnOnDiscard
S foo() {
return S([1,2,3]);
}

void d(S s) {

}

unittest {
auto a = foo();  // This should fail, because a is 
never used.


// This should also fail, because b is never used actually 
used afterwards.

auto b = foo()
b.morph();

   // This should fail, because d does not use c.
   // A simply analysis of d will not work, you'll have to track 
all passed values to d and whether they themselves should be 
tracked with the attribute.

   auto c = foo();

   d(c);

  // Same as above, should fail too since d doesn't use the 
return value

  d(foo());
}

The above is going to be very complex to implement in the 
compiler.


Sure a simple check if it has just been assigned to a variable 
would work fine, but in the reality people would most likely just 
do something like this then:


auto unused = foo();

And there ... we "hacked" our way around the attribute.

So for it to work it has to track every single return value from 
a function that implements the attribute and that is borderline 
impossible to get correct.


Re: Don't expect class destructors to be called at all by the GC

2017-12-21 Thread bauss via Digitalmars-d-learn
On Thursday, 21 December 2017 at 19:43:16 UTC, Steven 
Schveighoffer wrote:

On 12/20/17 9:57 PM, Mike Franklin wrote:

[...]


It's implementation defined :)

The gist is, you cannot expect that destructors will be run in 
a timely manner, or at all.


They may be called, and most of the time they are. But the 
language nor the current implementation makes a guarantee that 
they will be called.


For this reason, any classes that use non-memory resources 
should clean up those resources before becoming garbage. This 
is why most of the time, such items are managed by structs.


Note that the same non-guarantee exists in other GC'd 
languages, such as Java or C#.


-Steve


Except for that in C# you have the IDisposable interface, which 
can actually be used to prevent this kind of stuff and generally 
used to clean up non-GC memory.


Re: can't run libuid examples

2017-12-21 Thread bauss via Digitalmars-d-learn
On Thursday, 21 December 2017 at 18:41:28 UTC, greatsam4sure 
wrote:
I am having problem with running the examples of libuid on 
Windows and how to use libuid on a project without errors. I am 
using dmd version 2.076


Okay, but how are we supposed to help if you don't show us what 
errors you get?


Errors can depend on many things like your compiler-setup, paths, 
linker, your code, packages, compiler-flags and so on.





Re: WARN on implicit super?

2017-12-21 Thread bauss via Digitalmars-d-learn

On Thursday, 21 December 2017 at 06:47:25 UTC, Ali Çehreli wrote:

On 12/20/2017 10:36 PM, Chris Katko wrote:
Is there any way to get a warning anytime an implicit super 
constructor is called in a sub-class/child-class?


There can be a number of solutions but can you please 
demonstrate the issue with compilable code? My attempt does not 
agree with your description: super() is called *before* the 
subclass constructor. (Compiled with DMD64 D Compiler 
v2.077.1-384-gc6829a8)


import std.stdio;

// To get the code compile:
enum : int {
BMP_PLACEHOLDER,
BMP_BUILDING
}
alias bitmap_t = int;

class object_t
{
bitmap_t bmp;
float x,y;
this() {
writeln("super()");
bmp = BMP_PLACEHOLDER;
}

this(float _x, float _y)
{
writeln("super(float, float)");
bmp = BMP_PLACEHOLDER;
x = _x;
y = _y;
}
}

class building_t : object_t
{
this(float _x, float _y)
{
//super(_x, _y);
// ^^ If I forget this, it implicitly gets called AFTER
// this function is done. Which resets bmp to 
BMP_PLACEHOLDER!
// AND, it'll call the DEFAULT constructor this() with 
no arguments.


writeln("setting in building_t");
bmp = BMP_BUILDING;
}
}

void main() {
auto b = new building_t(10, 20);
assert(b.bmp != BMP_PLACEHOLDER);
}

Prints

super()
setting in building_t

Ali


This is what I would believe __IS__ and __SHOULD__ be the default 
behavior too, because that's how it generally is in other 
languages.


It doesn't make much sense to call a super constructer after and 
it's very rare cases that you need too.


The only time you really call super constructors after is if the 
parameters are different.


Ex.

class Foo
{
int baz;
int boo;

this() { ... }

this(int baz, int boo) { ... }
}

class Bar : Foo
{
this()
{
int baz =getBazFromSomewhere();
int boo = getBooFromSomewhere();
super(baz, boo);
}
}

In that case it makes sense to call super() after, but you rarely 
end up in cases like that and thus you should generally be able 
to omit the call.


If super() is ever called explicit after (if no call to a super 
constructor has been done.) then I can only imagine A LOT of code 
will break, because it's a general concept and known behavior 
from most languages that base/super constructors are called 
before.


Re: DateTime formatting

2017-12-20 Thread bauss via Digitalmars-d-learn
On Wednesday, 20 December 2017 at 22:38:06 UTC, Jonathan M Davis 
wrote:
On Wednesday, December 20, 2017 21:36:00 bauss via 
Digitalmars-d-learn wrote:
On Wednesday, 20 December 2017 at 18:50:37 UTC, Jonathan M 
Davis


wrote:
> On Wednesday, December 20, 2017 14:30:55 bauss via
>
> Digitalmars-d-learn wrote:
>> I can't seem to find anything in Phobos that allows you to 
>> specify custom formats for dates.

>>
>> Am I on my own or is there already such functionality?
>>
>> I'm interested in a formatter with the possibility to 
>> output ex.:

>>
>> December 20th, 2017 10:00 AM
>>
>> All I could find was toSimpleString(), but it seem to use a
>> pre-defined format like:
>> -Mon-DD HH:MM:SS
>
> At present, the only formats that Phobos supports are ISO, 
> ISO Extended, and Boost's simple time format. It does not 
> yet have support for custom date/time formatting beyond 
> constructing the string yourself from the properties on a 
> DateTime or SysTime.

>
> This was posted about recently in the Announce group though:
>
> http://code.dlang.org/packages/datefmt
>
> It might do what you want.
>
> - Jonathan M Davis

Unfortunately I can't rely on any third-party packages for it 
:p


But thanks anyway @ both of you.

I'll write my own function to do it :)


Well, if you can't use a 3rd party package, I suspect that 
you'd have to write your own solution even if Phobos does 
finally get custom date/time formatting, because what you're 
trying to do includes "th", which is English-specific, and I'm 
not about to add localization/i18n stuff to std.datetime. One 
of the reasons that I regret porting Boost's simple time format 
over to std.datetime is that it includes English in it, which 
has occasionally resulted in localization requests, and i18n is 
really way too involved to put into Phobos.


I expect that I'll get around to finishing custom date/time 
formatting for Phobos at some point, but it's not a high 
priority for me, and I have yet to come up with a scheme for 
defining the formatting that doesn't seem terrible to me.


- Jonathan M Davis


Well a way to achieve it without putting i18n into Phobos would 
be something like being able to specify formatters.


Ex. you could have something like a global formatter, which is 
used if you don't pass a formatter to toString().


Example:
globalTimeFormatter = (fmt, time) {
   // fmt would be the string format passed to ex. 
DateTime.toString()

   // time would be the DateTime

   // return a formatted string based on what you give
};

If you give no formatter to DateTime.toString() like:
auto formattedTime = dateTime.toString("HH:mm:ss");

Then it will automatically use the "globalTimeFormatter".

However you should be able to also "override" the globalFormatter 
when needed like:

auto formattedTime = dateTime.toString("HH:mm:ss", (fmt, time) {
   // Same concept as the global formatter ...
});

Perhaps it could be a static member of DateTime, to avoid 
confusion on which time implementations it's used for. Eg. I'd 
argue that it shouldn't be usable for SysTime.


DateTime.globalFormatter = ...;

This would leave i18n etc. up to the caller.

This can basically be done ouselves using UFC, but something 
official in Phobos would be  great addition to be honest.


It would be a relative small implementation, but very useful.


Re: DateTime formatting

2017-12-20 Thread bauss via Digitalmars-d-learn
On Wednesday, 20 December 2017 at 18:50:37 UTC, Jonathan M Davis 
wrote:
On Wednesday, December 20, 2017 14:30:55 bauss via 
Digitalmars-d-learn wrote:
I can't seem to find anything in Phobos that allows you to 
specify custom formats for dates.


Am I on my own or is there already such functionality?

I'm interested in a formatter with the possibility to output 
ex.:


December 20th, 2017 10:00 AM

All I could find was toSimpleString(), but it seem to use a
pre-defined format like:
-Mon-DD HH:MM:SS


At present, the only formats that Phobos supports are ISO, ISO 
Extended, and Boost's simple time format. It does not yet have 
support for custom date/time formatting beyond constructing the 
string yourself from the properties on a DateTime or SysTime.


This was posted about recently in the Announce group though:

http://code.dlang.org/packages/datefmt

It might do what you want.

- Jonathan M Davis


Unfortunately I can't rely on any third-party packages for it :p

But thanks anyway @ both of you.

I'll write my own function to do it :)


DateTime formatting

2017-12-20 Thread bauss via Digitalmars-d-learn
I can't seem to find anything in Phobos that allows you to 
specify custom formats for dates.


Am I on my own or is there already such functionality?

I'm interested in a formatter with the possibility to output ex.:

December 20th, 2017 10:00 AM

All I could find was toSimpleString(), but it seem to use a 
pre-defined format like:

-Mon-DD HH:MM:SS




Alias!T

2017-12-16 Thread bauss via Digitalmars-d-learn

In what scenario would you use Alias!T from std.meta?

I understand what it does and how it can be used, but I can't 
seem to think of a reasonable situation where it's desirable.


Re: weird exception on windows

2017-12-16 Thread bauss via Digitalmars-d-learn

On Saturday, 16 December 2017 at 08:07:30 UTC, Szabo Bogdan wrote:
On Friday, 15 December 2017 at 21:56:48 UTC, Steven 
Schveighoffer wrote:

On 12/15/17 10:08 AM, Kagamin wrote:

Maybe this https://issues.dlang.org/show_bug.cgi?id=18084


Thanks for looking into this. I created a PR to fix.

Szabo, can you please try with this patch and see if it fixes 
your issue?


https://github.com/dlang/phobos/pull/5932

-Steve


I have installed DMD 2.77.1 and I can not find the patched file 
in the phobos folder... should I try this by building the 
compiler?


It seams that I can not build phobos without compiling dmd.. or 
maybe I don't know how...


Just go and do the changes manually in your local phobos folder, 
wherever you have DMD installed, since you can't build phobos or 
dmd.


Re: What's the proper way to use std.getopt?

2017-12-13 Thread bauss via Digitalmars-d-learn
On Wednesday, 13 December 2017 at 07:37:17 UTC, Jonathan M Davis 
wrote:
On Wednesday, December 13, 2017 06:55:46 bauss via 
Digitalmars-d-learn wrote:

[...]


If it works, it's a bug related to code lowering (since scope 
statements are always lowered to try-catch-finally blocks). 
You're not supposed to have access to the exception in a scope 
statement.


- Jonathan M Davis


Yeah that's what I thought.

Just tested and it doesn't allow you to.


Re: What's the proper way to use std.getopt?

2017-12-12 Thread bauss via Digitalmars-d-learn

On Tuesday, 12 December 2017 at 18:34:26 UTC, Mike Wey wrote:

On 12-12-17 00:35, Seb wrote:

D style would be to use sth. like this (instead of try/catch):

```
scope(failure) {
   e.msg.writeln;
   1.exit;
}
```


I might have missed something, but where is `e` defined in this 
case?


I was thinking the same and can't find anything in the 
documentation that states you can retrieve the exception that 
caused the failure by an "e" variable.


All I could find is that in case you need to use the exception 
you'd have to do a try/catch.


So ultimately that code wouldn't work, according to the language 
specs.


I haven't tested it, so I don't know if it's some hidden feature, 
but if it is, then I'm against it.


Re: how would I go about creating a Socket receiveAll method?

2017-12-12 Thread bauss via Digitalmars-d-learn

On Tuesday, 12 December 2017 at 22:11:37 UTC, Adam D. Ruppe wrote:

On Tuesday, 12 December 2017 at 21:52:57 UTC, Ali Çehreli wrote:
The same buffer is used for all segments and socket.receive 
should be inside while.


The buffer is copied by the ~= operator, but indeed you're 
right that I forgot to receive again inside the loop! That 
would just spin until it ran out of memory lol.


But I did put receive outside the loop for a reason: it just 
needs to prime the return value before it gets checked the 
first time. But then, of course, it should receive again at the 
end of the loop to advance to the next chunk.


do while would work better.


Re: Abstract Classes

2017-12-06 Thread bauss via Digitalmars-d-learn

On Wednesday, 6 December 2017 at 07:23:29 UTC, IM wrote:

Assume the following:

interface IFace {
  void foo();
  void bar();
}

abstract class A : IFace {
  override void foo() {}
}

class B : A {
  override void bar() {}
}

Now why this fails to compiler with the following message:


--->>>
function bar does not override any function, did you mean to 
override 'IFace.bar()'?

<<<---


Obviously, I meant that, since the abstract class A implements 
IFace, and B derives from A.


Do I need to declare IFace's unimplemented methods in A as 
abstract? If yes, why? Isn't that already obvious enough (any 
unimplemented virtual function is abstract)?


bar() is not a virtual function, but is defined in the interface 
IFace and thus you don't need to override it in B.


The same goes for foo() which I'd argue should have given same 
error.


What you possibly wanted to do is this:

interface IFace {
  void foo();
  void bar();
}

abstract class A : IFace {
  abstract void bar(); // All child classes must implement bar 
and override it


  abstract void foo(); // Since A implements IFace we must 
implement both bar() and foo()
   // However it's an abstract class, so we 
can leave implementation

   // up to the children.
}

class B : A {
  override void bar() {}

  override void foo() {}
}



Re: Object oriented programming and interfaces

2017-12-05 Thread bauss via Digitalmars-d-learn

On Tuesday, 5 December 2017 at 08:08:55 UTC, Daniel Kozak wrote:

You can do something like this:

interface Medoid(T) {
float distance( T other );
uint id() const @property;
}

class Item : Medoid!(Item) {
float distance( Item m ) { return 0.;}
uint id() const @property { return 1; }
}

class MedoidClassification {
this(T:Medoid!T)(T[] list) {}
//Medoid[][] getClusters() {...}
}

void main() {
auto items = new Item[10];
auto mc = new MedoidClassification( items );
}

On Tue, Dec 5, 2017 at 8:47 AM, Dirk via Digitalmars-d-learn < 
digitalmars-d-learn@puremagic.com> wrote:


The distance function is implementation dependend and can only 
be computed between two objects of the same class (in this 
example the class is Item).


My goal is to write a module for a k-medoids clustering 
algorithm. The class MedoidClassification shall be able to 
partition a list of objects from the same class, which 
implement the Medoid interface.


My current approach is this (which does not work):

interface Medoid {
float distance( Medoid other );
uint id() const @property;
}

class Item : Medoid {
float distance( Item m ) {...}
uint id() const @property {...}
}

class MedoidClassification {
this( Medoid[] list ) {...}
Medoid[][] getClusters() {...}
}

void main() {
Item[10] items;
auto mc = MedoidClassification( items );
}


What would be a good way to implement this?


This still defeats the purpose of having multiple Medoid types, 
as each Medoid is still specified with a specific type.


Re: Struct inside a class: How to get outer?

2017-12-03 Thread bauss via Digitalmars-d-learn
On Sunday, 3 December 2017 at 07:38:47 UTC, Jonathan M Davis 
wrote:
On Sunday, December 03, 2017 01:05:00 Nick Sabalausky  via 
Digitalmars-d- learn wrote:

Is this even possible? My attempts:

class Outer {
  struct Inner {
  void foo() {
  // Error: no property 'outer' for type 'Inner'
  Outer o = this.outer;

  // Error: cannot implicitly convert expression
  // this of type Inner to testNested.Outer
  Outer o = this;
  }
  }
}


As I understand it, there is no outer for nested structs, only 
nested classes. So, you'll either have to use a nested class or 
explicitly pass a reference to the outer class to the nested 
struct.


- Jonathan M Davis


It wouldn't make much sense either, if a struct  was able to do 
it.





Re: Is variable void?

2017-11-27 Thread bauss via Digitalmars-d-learn

On Monday, 27 November 2017 at 02:12:40 UTC, codephantom wrote:
On Saturday, 25 November 2017 at 15:34:21 UTC, John Chapman 
wrote:
Is there any way of determining whether a variable has been 
initialized or not? For example, if something is declared like 
this:


  int x = void;

can I check if it's void before I use it, say, in a function 
it's been passed to?


// --

module test;

import std.stdio;
import std.typecons; // see: 
https://dlang.org/phobos/std_typecons.html#Nullable


void main()
{
Nullable!int x;  // requires: import std.typecons
assert(x.isNull);
writeln("x is ", x);

x = 1;
assert(!x.isNull);
writeln("x is ", x);

x.nullify(); // Forces x back to a null state.
assert(x.isNull);
writeln("x is ", x);

}
// --


null != void


Re: dub: Use Alternate Dependency

2017-11-20 Thread bauss via Digitalmars-d-learn

On Tuesday, 21 November 2017 at 02:51:13 UTC, jmh530 wrote:
I'm working on two related dub projects on code.dlang.org. One 
has a dependency on the other. However, I've made changes to 
both and to run the tests properly requires me to use both 
versions in my working directory, rather than the versions 
(specifically for the dependency) that is registered on dub.


How do I ensure that dub picks up the right version?


Well dub will always use the versions you have specified in your 
dub.json/dub.sdl file, so if you have a specific version in you 
dub.json/dub.sdl then dub will use that version only and won't 
fetch a new version, so don't use something like "~>version", but 
just "version".


Example
---

Instead of (something like this.):
dependency "package" version="~>1.2.3"

Do:
dependency "package" version="1.2.3"




Re: Json

2017-11-19 Thread bauss via Digitalmars-d-learn

On Sunday, 19 November 2017 at 10:50:58 UTC, Mafi wrote:
On Saturday, 18 November 2017 at 14:25:58 UTC, kerdemdemir 
wrote:
I am using vibe.d's json(http://vibed.org/api/vibe.data.json/) 
module without a problem and really happy with it. There are 
also some 
examples(https://github.com/vibe-d/vibe.d/tree/master/examples/json). If you are using "dub" package manager it is also very easy to integrate vibe.d.


Well, this would pull the whole vibe.d into the executable, 
wouldn't it? I'll stick with stdx.data.json for now, which I 
have tried and it does work in my case. But I'll minimize the 
actual json-interaction code so I can switch out the lib at any 
time.


Thank you all! It's rather unfortunate that the (std lib) json 
situation is still not sorted out!


Well you could hand pick the two sub packages.

https://github.com/vibe-d/vibe.d/tree/master/data
https://github.com/vibe-d/vibe.d/tree/master/utils (data depends 
on this)




Re: Json

2017-11-18 Thread bauss via Digitalmars-d-learn
On Friday, 17 November 2017 at 19:12:04 UTC, Jonathan M Davis 
wrote:
On Friday, November 17, 2017 19:02:12 Mafi via 
Digitalmars-d-learn wrote:

[...]


I've typically used 
http://code.dlang.org/packages/std_data_json which comes from 
vibe.d and was a candidate for replacing std.json - though it 
didn't complete the review process, and I'm not sure that Sonke 
is interested in going through the effort of actually getting 
it into Phobos at this point (if I understand correctly, there 
were too many disagreements over what the final result should 
look like than there really being much wrong with 
std_data_json). But overall, I've found that it works 
reasonably well - certainly, it's better than using std.json. I 
don't know if it's quite what you're looking for though.


Regardless, just searching on code.dlang.org gives plenty of 
hits for libraries to try out if std_data_json doesn't suit 
your fancy.


- Jonathan M Davis


Sadly it's not really updated and vibe.d's json module seems more 
stable, as it has had 60+ commits this year, while std_data_json 
hasn't been updated for over a year.


It will probably work fine in general, but I assume it'll have a 
few gotchas here and there, as it seems like even vibe.d's module 
has that.


Re: ESR on post-C landscape

2017-11-15 Thread Bauss via Digitalmars-d-learn

On Thursday, 16 November 2017 at 02:12:10 UTC, codephantom wrote:

On Tuesday, 14 November 2017 at 11:55:17 UTC, codephantom wrote:

[...]


Actually, I got that wrong.

Perhaps the mistake C++ made, was concluding that 'classes' 
were the "proper primary focus of program design" (chp1. The 
Design and Evolution of C++).


I have to wonder whether that conclusion sparked the inevitable 
demise of C++.


Eric should be asking a similar question about Go ..what 
decision has been made that sparked Go's inevitable demise - or 
in the case of Go, decision would be decisions.


this is what did it for me:

a := b

interface{} definitely



Re: ESR on post-C landscape

2017-11-14 Thread bauss via Digitalmars-d-learn

On Tuesday, 14 November 2017 at 04:31:43 UTC, Laeeth Isharc wrote:

He mentions D, a bit dismissively.
http://esr.ibiblio.org/?p=7724=1#comment-1912717


Couldn't read that without cringing.


Re: opCast'ing strings

2017-11-13 Thread bauss via Digitalmars-d-learn

On Monday, 13 November 2017 at 01:12:59 UTC, Adam D. Ruppe wrote:

On Monday, 13 November 2017 at 01:03:17 UTC, helxi wrote:
In this program, casting using to does not work as intended 
(returning 23/11) on the struct. However, calling opCast 
directly seems to do the job. Why is that?



to!string calls a function called `string toString() {}` on the 
struct, not the cast operator.


Which is generally what you want to use anyway and not a cast 
overload.


My rule of thumb (Which can of course differ per preference.) is 
that cast overload should only be done between the following:


struct <-> scalar types
class <-> scalar types
struct <-> class

Any string conversions should always be done with `toString()`.

Anything else should not be implemented with casts or conversion 
methods. An exception of course is creating slices, which is 
acceptable using `opSlice`, but generally I avoid using something 
like `opCast` to an array, UNLESS it's an array wrapper, which 
you most likely won't have in D anyway, because you'd be better 
off creating a range.







Re: How do I create a fileWatcher with an onFileChange event using spawn?

2017-11-13 Thread bauss via Digitalmars-d-learn

On Monday, 28 August 2017 at 11:25:03 UTC, Jacob Carlborg wrote:

On 2017-08-28 08:31, Nemanja Boric wrote:
On Monday, 28 August 2017 at 06:27:20 UTC, Jacob Carlborg 
wrote:

http://code.dlang.org/packages/vibe-core
http://code.dlang.org/packages/libasync


In addition, to avoid polling, it's possible to register 
yourself to the operating system so it will tell you when a 
modification on the given file has happened: 
https://msdn.microsoft.com/en-us/library/aa364417%28VS.85%29.aspx?f=255=-2147217396 http://man7.org/linux/man-pages/man7/inotify.7.html


That's what the two libraries above provides, in a 
cross-platform way.


There's already a dub package for file system watching:

https://code.dlang.org/packages/fswatch


Re: convert string to ubyte[]

2017-11-11 Thread bauss via Digitalmars-d-learn

On Saturday, 11 November 2017 at 15:48:59 UTC, Mike Parker wrote:

On Saturday, 11 November 2017 at 15:38:18 UTC, aki wrote:

[...]


I don't know about the error you're seeing, but the generic way 
to get an array of the underlying data type of a string is via 
std.string.representation.


import std.string;
auto s = "hello";
auto bytes = s.representation;

https://dlang.org/phobos/std_string.html#.representation

You can also simply cast to the appropriate type if you already 
know what type of string you have.


auto bytes = cast(immutable(ubyte)[])s;

Of course, if you need a mutable array you should dup:

auto bytes = cast(ubyte[])s.dup;


That function needs to be highlighted more through documentation. 
I've always implemented my own versions to achieve the same as 
representation. I had no idea that function existed.


If just I knew.


Re: Synchronize Class fields between different threads

2017-11-10 Thread bauss via Digitalmars-d-learn

On Friday, 10 November 2017 at 14:36:03 UTC, DrCataclysm wrote:

On Friday, 10 November 2017 at 14:27:41 UTC, bauss wrote:

On Friday, 10 November 2017 at 14:13:26 UTC, DrCataclysm wrote:
On Friday, 10 November 2017 at 13:50:56 UTC, rikki cattermole 
wrote:
Remember this bit: Everything on the heap, is not 
thread-local, it is global. This includes everything inside 
a class.


When you synchronize (statement) it is locking and then 
unlocking a mutex. A class has a mutex, simple! It only 
prevent multiple threads modifying a single thing at 
specific times, thats all.


this is my implementation of Accept


private void Accept(){
// start accepting in a different thread
try{
_client = _server.accept();

emit(ClientConnected(_client.remoteAddress.toAddrString));

auto _acceptTask = task();
_acceptTask.executeInNewThread();
Receive();
}
catch (SocketAcceptException e){
writeln("Error while accepting connection: " ~ 
e.msg);

}
}

Is _client on the Heap or the Stack? If it is on the Stack, 
how would i get in on the Heap?


_client is allocated in the heap.

Socket accept(); returns the socket created from Socket 
accepting().


Which is like below:

 protected Socket accepting() pure nothrow
{
return new Socket;
}


thank you, i thought i was going mad.

It is working now. The problem was that the debugger in eclipse 
ddt seems to completely broken. If i run it directly from bash 
it is working.


One last question: is there a function in the std to wait for a 
task to finish within a time limit?


Not an ideal solution, but should work: (I'm not aware of any 
build-in solutions using Phobos' tasks.


```
static const timeLimit = 1000; // Wait for the task up to 1000 
milliseconds


while (!task.done && timeLimit)
{
import core.time : Thread, dur;

Thread.sleep( dur!("msecs")(1) ); // Preventing the CPU to go 
nuts

timeLimit--;
}

if (task.done)
{
auto value = task.yieldForce();
}
```

Could make it a function though:

```
bool yieldTimeLimit(Task)(Task task)
{
while (!task.done && timeLimit)
{
import core.time : Thread, dur;

Thread.sleep( dur!("msecs")(1) );
timeLimit--;
}

return task.done;
}

...

if (yieldTimeLimit(task))
{
auto value = task.yieldForce();
}
```


Re: Synchronize Class fields between different threads

2017-11-10 Thread bauss via Digitalmars-d-learn

On Friday, 10 November 2017 at 15:01:30 UTC, bauss wrote:

On Friday, 10 November 2017 at 14:36:03 UTC, DrCataclysm wrote:

On Friday, 10 November 2017 at 14:27:41 UTC, bauss wrote:
On Friday, 10 November 2017 at 14:13:26 UTC, DrCataclysm 
wrote:

[...]


_client is allocated in the heap.

Socket accept(); returns the socket created from Socket 
accepting().


Which is like below:

 protected Socket accepting() pure nothrow
{
return new Socket;
}


thank you, i thought i was going mad.

It is working now. The problem was that the debugger in 
eclipse ddt seems to completely broken. If i run it directly 
from bash it is working.


One last question: is there a function in the std to wait for 
a task to finish within a time limit?


Not an ideal solution, but should work: (I'm not aware of any 
build-in solutions using Phobos' tasks.


```
static const timeLimit = 1000; // Wait for the task up to 1000 
milliseconds


while (!task.done && timeLimit)
{
import core.time : Thread, dur;

Thread.sleep( dur!("msecs")(1) ); // Preventing the CPU to 
go nuts

timeLimit--;
}

if (task.done)
{
auto value = task.yieldForce();
}
```

Could make it a function though:

```
bool yieldTimeLimit(Task)(Task task)
{
while (!task.done && timeLimit)
{
import core.time : Thread, dur;

Thread.sleep( dur!("msecs")(1) );
timeLimit--;
}

return task.done;
}

...

if (yieldTimeLimit(task))
{
auto value = task.yieldForce();
}
```


Pardon my brain fart.

The last bit should be:

```
bool yieldTimeLimit(Task)(Task task, size_t timeLimit)
{
while (!task.done && timeLimit)
{
import core.time : Thread, dur;

Thread.sleep( dur!("msecs")(1) );
timeLimit--;
}

return task.done;
}

...

if (task.yieldTimeLimit(1000)) // Waits 1000 milliseconds
{
auto value = task.yieldForce();
}
```


Re: Synchronize Class fields between different threads

2017-11-10 Thread bauss via Digitalmars-d-learn

On Friday, 10 November 2017 at 14:13:26 UTC, DrCataclysm wrote:
On Friday, 10 November 2017 at 13:50:56 UTC, rikki cattermole 
wrote:
Remember this bit: Everything on the heap, is not 
thread-local, it is global. This includes everything inside a 
class.


When you synchronize (statement) it is locking and then 
unlocking a mutex. A class has a mutex, simple! It only 
prevent multiple threads modifying a single thing at specific 
times, thats all.


this is my implementation of Accept


private void Accept(){
// start accepting in a different thread
try{
_client = _server.accept();

emit(ClientConnected(_client.remoteAddress.toAddrString));

auto _acceptTask = task();
_acceptTask.executeInNewThread();
Receive();
}
catch (SocketAcceptException e){
writeln("Error while accepting connection: " ~ 
e.msg);

}
}

Is _client on the Heap or the Stack? If it is on the Stack, how 
would i get in on the Heap?


_client is allocated in the heap.

Socket accept(); returns the socket created from Socket 
accepting().


Which is like below:

 protected Socket accepting() pure nothrow
{
return new Socket;
}


Re: How do i find a list of the methods Object implements, or maybe just locate the 'write' method?

2017-11-08 Thread bauss via Digitalmars-d-learn

On Wednesday, 8 November 2017 at 03:48:58 UTC, codephantom wrote:

On Wednesday, 8 November 2017 at 03:33:08 UTC, bauss wrote:

--


Compiles fine with DMD: https://dpaste.dzfl.pl/95b896aa242f



ahh.. that site saves it with some random temporary file name I 
assume.


If it saved it as write.d, it likely would not compile, unless 
they were using gdc.


That's because the module name becomes `write` then.

Generally you should be explicit about module names anyway, 
unless you have a single file for testing or something.


You could get around the error using an alias:

```
module write;

import std.stdio;
alias write = std.stdio.write; // <<

void main()
{
auto o = new Object;

o.write;
write(o);

}
```


Re: How do i find a list of the methods Object implements, or maybe just locate the 'write' method?

2017-11-07 Thread bauss via Digitalmars-d-learn

On Wednesday, 8 November 2017 at 03:05:22 UTC, codephantom wrote:
On Tuesday, 7 November 2017 at 21:32:26 UTC, Adam D. Ruppe 
wrote:

[...]


it's interesting how the compiler deals with scope.
---
// save this in a file named: write.d

import std.stdio;

void main()
{
auto o = new Object;

// One of statements below will prevent this code from 
compiling.

// Which one do you think it is?

// btw. If I instead use gdc on debian, then it will
// compile both statements just fine, and will work as 
expected too.


o.write;
write(o);

}

--


Compiles fine with DMD: https://dpaste.dzfl.pl/95b896aa242f


Re: Issues with Vibe.d Dynamic HTML with JSON

2017-11-02 Thread bauss via Digitalmars-d-learn

On Thursday, 2 November 2017 at 18:48:10 UTC, bauss wrote:
On Thursday, 2 November 2017 at 16:23:55 UTC, SamwiseFilmore 
wrote:

On Thursday, 2 November 2017 at 08:40:28 UTC, bauss wrote:

[...]


No, the html does come in, and the whole content of the 
rendered page is sent to the browser. The page has closing 
head and body tags.



[...]


I'll play with that. Would there be any reason for my data to 
get randomly truncated?


Before you did:
render!("index.dt", title, major_categories);

Have you tried to check the contents of "major_categories" 
making sure it's all there. Just to figure out whether the 
problem is in the view rendering or the json parsing.


Also alternatively have you tried "vibe.data.json"?

http://vibed.org/api/vibe.data.json/


Re: Issues with Vibe.d Dynamic HTML with JSON

2017-11-02 Thread bauss via Digitalmars-d-learn
On Thursday, 2 November 2017 at 16:23:55 UTC, SamwiseFilmore 
wrote:

On Thursday, 2 November 2017 at 08:40:28 UTC, bauss wrote:
Do you get a response back with rendered html or does the 
connection get dropped?


No, the html does come in, and the whole content of the 
rendered page is sent to the browser. The page has closing head 
and body tags.


Have you tried to cut down the amount of data and see if it 
will render it all? That should eliminate whether it's the 
amount of data or what.


I'll play with that. Would there be any reason for my data to 
get randomly truncated?


Before you did:
render!("index.dt", title, major_categories);

Have you tried to check the contents of "major_categories" making 
sure it's all there. Just to figure out whether the problem is in 
the view rendering or the json parsing.


Re: Issues with Vibe.d Dynamic HTML with JSON

2017-11-02 Thread bauss via Digitalmars-d-learn
On Thursday, 2 November 2017 at 04:00:10 UTC, SamwiseFilmore 
wrote:
I've got a serialized JSON structure that looks something like 
this:


[...]


Do you get a response back with rendered html or does the 
connection get dropped?


Have you tried to cut down the amount of data and see if it will 
render it all? That should eliminate whether it's the amount of 
data or what.




Re: "version" private word

2017-10-31 Thread bauss via Digitalmars-d-learn

On Tuesday, 31 October 2017 at 13:55:56 UTC, Igor Shirkalin wrote:
On Tuesday, 31 October 2017 at 13:53:54 UTC, Jacob Carlborg 
wrote:

On 2017-10-31 14:46, Igor Shirkalin wrote:

Hello!

We need some conditional compilation using 'version'.
Say we have some code to be compiled for X86 and X86_64.
How can we do that using predefined (or other) versions?
Examples:

    version(X86 || X86_64) // failed
    version(X86) || version(X86_64) // failed


The following works but it is too verbose:

version(X86) {
 version = X86_or_64;
}
version(X86_64) {
 version = X86_or_64;
}


The only alternative is to do something like this:

version (X86)
enum x86 = true;
else
enum x86 = false;

else version (X86_64)
enum x86_64 = true;
else
enum x86_64 = false;

static if (x86 || x86_64) {}


Got it. Thank you!


Yeah, in Diamond I went with this approach to make conditional 
compilation around the project much easier.


https://github.com/DiamondMVC/Diamond/blob/master/core/apptype.d


Re: Empty UDA for classes not allowed?

2017-10-26 Thread bauss via Digitalmars-d-learn
On Thursday, 26 October 2017 at 21:24:43 UTC, Jonathan M Davis 
wrote:
On Thursday, October 26, 2017 15:09:48 bauss via 
Digitalmars-d-learn wrote:

[...]


It worked just fine when I just tried it on my machine - both 
with dmd master and with 2.076.1. Are you using an older 
version of the compiler than 2.076.1? It's possible that there 
was a bug that was fixed.


- Jonathan M Davis


Yeah I can't reproduce it right now, so I'm not even sure.


Empty UDA for classes not allowed?

2017-10-26 Thread bauss via Digitalmars-d-learn

Why is it not allowed to have empty UDAs for classes?

Let's say we have an UDA like this:
struct Exclude { }

Then we want to put it on a class like:

@Exclude class Foo
{
...
}

This will fail with the following error:
Error: type Exclude has no value

But on everything else we can place an empty UDA like that ex. on 
a function:


This is okay:

@Exclude void foo()
{
...
}

Can someone explain to me why it's not possible with classes?


Re: Garbage Collector profiling and the dynamic array reserve() function

2017-10-22 Thread bauss via Digitalmars-d-learn
On Wednesday, 18 October 2017 at 15:39:43 UTC, Steven 
Schveighoffer wrote:

On 10/18/17 1:40 AM, Tony wrote:
On Tuesday, 17 October 2017 at 13:27:24 UTC, Steven 
Schveighoffer wrote:




I don't know what "allocations" represents, but reserve 
actually calls gc_malloc, and the others do not (the space is 
available to expand into the block). There should be only one 
allocation IMO.




So there should be a bug report written for this?



It all depends on what "allocations" means. I'd wait to find 
out from someone who is familiar with the GC profiling.


-Steve


I don't have a lot of clues on how the GC profiling work, but 
looking at reserve() it calls mem.xmalloc() for allocations which 
in fact calls GC.malloc().


Looking at the profiling for GC though:
https://github.com/dlang/dmd/blob/69567a32c5bffae5513b41e7691c91b50766b552/src/ddmd/e2ir.d#L5952

It doesn't look like there's anything for array reserve calls, 
unless:

 [ RTLSYM_ALLOCMEMORY, RTLSYM_TRACEALLOCMEMORY ]
are triggered from the allocations done in reserve(), but I have 
no idea about that.


Re: Static if on release build

2017-10-19 Thread bauss via Digitalmars-d-learn

On Friday, 20 October 2017 at 02:36:37 UTC, Fra Mecca wrote:
I can't find any documentation regarding conditional 
compilation in release and debug mode.


I have read the page regarding the topicon dlang.org but adding 
the snippet below makes no difference when compiling with dub 
-b release

{
version(full) {
 //do something
} else {
//do something else
}

How can I produce a release version with different parameters 
from debug using dub and static if's?


Take a look at this:
https://dlang.org/spec/version.html#DebugCondition


Re: Does D have an equivalent to C#'s String.IsNullOrWhiteSpace?

2017-10-13 Thread bauss via Digitalmars-d-learn

On Thursday, 12 October 2017 at 18:17:54 UTC, Adam D. Ruppe wrote:

On Thursday, 12 October 2017 at 18:11:55 UTC, Nieto wrote:
Does D have an equivalent to C#'s String.IsNullOrWhiteSpace() 
in the standard library?


import std.string;

if(str.strip().length == 0) {
  // is null, empty, or all whitespace
}


Or this:
if(!str.strip()) {
  // is null, empty, or all whitespace
}



Re: How to call function with variable arguments at runtime?

2017-10-10 Thread bauss via Digitalmars-d-learn

On Tuesday, 10 October 2017 at 02:58:45 UTC, Mr. Jonse wrote:
I need to store a hetrogeneous array of delegates. How can I do 
this but still call the function with the appropriate number of 
parameters at run time?


I have the parameters as Variant[] params and a 
function/delegate pointer(void* for now).


Normally I'd push the parameters on the stack and use a call, 
but I'm sure D has some ability to do this, like apply(foo, 
args) would be the same as foo(args[0], ..., args[1]).


I'm not concerned about type correctness, it should always be 
consistent between what I call and what is stored.


Thanks.


Not entirely sure what you're wanting to do, but sounds a lot 
like variadic parameters.



https://dlang.org/spec/function.html#variadic mixed with some 
compile-time terminology.


Re: How to make commented code to compile?

2017-10-10 Thread bauss via Digitalmars-d-learn

On Monday, 9 October 2017 at 15:22:54 UTC, Adam D. Ruppe wrote:

On Monday, 9 October 2017 at 15:15:48 UTC, Zhuo Nengwen wrote:

test(cast(ushort) 1, (m, c) => {
  writeln(m);
  writeln(m);
});


Just remove the =>

(m, c) {
  // code here
}


Common mistake from people who worked with LINQ in C#.


Re: High-level wrapper for readline package

2017-09-07 Thread bauss via Digitalmars-d-learn

On Thursday, 7 September 2017 at 14:00:36 UTC, Nordlöw wrote:
On Thursday, 7 September 2017 at 13:44:52 UTC, Adam D. Ruppe 
wrote:

[...]


There's always room for usability improvements when wrapping C 
APIs...


[...]


Isn't it pointless to make "prompt" in?


Re: Web servers in D

2017-09-02 Thread bauss via Digitalmars-d-learn

On Saturday, 2 September 2017 at 20:18:17 UTC, bauss wrote:

On Friday, 25 August 2017 at 05:25:09 UTC, Hasen Judy wrote:

[...]


Here is another template engine that can be used along with 
vibe. I actually made it for the same reason you don't wanna 
use vibe. Because I didn't like the template language and I was 
more familiar with razor templates from ASP.NET


https://github.com/bausshf/Diamond


To add onto this you can use mysql-native with vibe.d.

https://github.com/mysql-d/mysql-native


Re: Web servers in D

2017-09-02 Thread bauss via Digitalmars-d-learn

On Friday, 25 August 2017 at 05:25:09 UTC, Hasen Judy wrote:
What libraries are people using to run webservers other than 
vibe.d?


Don't get me wrong I like the async-io aspect of vibe.d but I 
don't like the weird template language and the fact that it 
caters to mongo crowd.


I think for D to a have good web story it needs to appeal to 
serious backend developers, not hipsters who go after fads 
(mongodb is a fad, jade/haml is a fad).


I probably need to combine several libraries, but the features 
I'm looking for are:


- Spawn an HTTP server listening on a port, and routing 
requests to functions/delegates, without hiding the details of 
the http request/response objects (headers, cookies, etc).


- Support for websockets

- Runs delegates in fibers/coroutines

- Basic database connectivity (No "orm" needed; just raw sql).

- When iterating the result set of a sql query, has the ability 
to automatically map each row against a struct, and throw if 
the structure does not match.


- More generally, map any arbitrary object (such as json) to a 
struct. Something like Zewo/Reflection package for swift[0].


[0]: https://github.com/Zewo/Reflection

I feel like Vibe.d satisfies my first 3 requirements, but for 
the rest I will probably have to look for something else.


Here is another template engine that can be used along with vibe. 
I actually made it for the same reason you don't wanna use vibe. 
Because I didn't like the template language and I was more 
familiar with razor templates from ASP.NET


https://github.com/bausshf/Diamond


Re: opEquals nothrow

2017-07-20 Thread bauss via Digitalmars-d-learn

On Thursday, 20 July 2017 at 14:38:03 UTC, Aldo wrote:

Hello,

im tring to add nothrow keyword in my code, but compilation 
fails :


function 'object.opEquals' is not nothrow


its a simple comparison between 2 objects. How to make opEquals 
nothrow ?


thanks


Could you show some code.


Re: Base class' constructor is not implicitly inherited for immutable classes. A bug or a feature?

2017-07-20 Thread bauss via Digitalmars-d-learn

On Wednesday, 19 July 2017 at 16:00:56 UTC, Piotr Mitana wrote:

Hello, I have this code:

immutable class Base
{
this() {}
}

immutable class Derived : Base {}

void main()
{
new immutable Derived();
}

I'd like class Derived to automatically inherit the default 
constructor from Base. However, this is not the case:


main.d(6): Error: class main.Derived cannot implicitly generate 
a default ctor when base class main.Base is missing a default 
ctor


Is it a bug or it should be like this?


I'd say it's a bug. There was a similar issue at one point where 
it wouldn't consider default constructor with default args.


Re: D doesn't read the first character of a file (reads everything but the first chararacter) with either read() or readText()

2017-07-19 Thread bauss via Digitalmars-d-learn
On Wednesday, 19 July 2017 at 15:18:00 UTC, Steven Schveighoffer 
wrote:

On 7/17/17 10:21 PM, Enjoys Math wrote:


DMD32 D Compiler v2.074.1

import std.file;

void main() {
string bigInput = readText("input.txt");
}

The file is 7 MB of ascii text, don't know if that matters...

Should I upgrade versions?


Looking at the implementation of readText, I believe its 
implementation is not able to trim off the beginning of a file. 
Be wary of how you look at the result, some tools may 
"helpfully" hide things (like unprintable characters, or 
overwrite what has already been displayed when it sees a 
carriage return).


If you can't figure it out yourself, the best thing to do here 
is to post your exact file somewhere so people can diagnose. Or 
reproduce with a smaller one, and then post that somewhere.


-Steve


I'm feeling this. My keyboard sometimes messes up and will send 
invalid key presses to my OS which often ends up with invalid 
characters being written in files.


When I encounter it I usually open Notepad++ and turn on show all 
characters which will display unprintable characters, simply 
allowing me to delete them and have a clean file again.




Auto-decoding

2017-07-14 Thread bauss via Digitalmars-d-learn
I understand what it is and how it works, but I don't understand 
anything of how it solves any problems?


Could someone give an example of when auto-decoding actually is 
useful in contrast to not using it?


Just trying to get an understanding of what exactly its purpose 
is.


I did read 
https://jackstouffer.com/blog/d_auto_decoding_and_you.html


But I still feel like there's not a clear explanation of what 
issues exist when you don't have it.


If I need to be more clear, just let me know.


Re: Need help to get OpenSSL 64 work on Windows x64 | I hate D's GC!

2017-07-14 Thread bauss via Digitalmars-d-learn

On Friday, 14 July 2017 at 13:16:17 UTC, Suliman wrote:
It's look that GC in D is really suxx. There is already second 
toy-project where I am getting stuck on Windows with D for last 
3 month.


I'm using 32-bit build, because I can't understand which libs I 
should use to get OpenSSL 64 bit work with dlang-request.


32-bit version compile and works fine, but it's fail during 
downloading 300MB file with next error:
core.exception.OutOfMemoryError@src\core\exception.d(696): 
Memory allocation failed


You might wanna read the file in chunks and write in chunks.


Re: Fiber based UI-Toolkit

2017-07-10 Thread bauss via Digitalmars-d-learn

On Monday, 10 July 2017 at 08:40:15 UTC, Jacob Carlborg wrote:

On 2017-07-09 23:12, bauss wrote:

I believe OSX (possibly macOS too.) only allows it from the 
main thread.


Yes, that's correct. But what's the difference between OSX and 
macOS ;)


Well besides that it's newer versions of the OS, then nothing 
much I guess. It could potentially change such specs though.


Re: Fiber based UI-Toolkit

2017-07-09 Thread bauss via Digitalmars-d-learn

On Sunday, 9 July 2017 at 19:43:14 UTC, Christian Köstlin wrote:
I wonder if there is any fiber based / fiber compatible 
UI-Toolkit out for dlang. The second question is, if it would 
make sense at all to have such a thing?


christian


It doesn't really make sense to have that, because most (if not 
all) operating systems only allow rendering from a single thread 
and I believe OSX (possibly macOS too.) only allows it from the 
main thread. Which means the only thing you can really operate on 
other threads are events, but you'll always have to do callbacks 
to your UI thread in order to render.


Re: Application settings

2017-07-07 Thread bauss via Digitalmars-d-learn

On Friday, 7 July 2017 at 22:52:22 UTC, FoxyBrown wrote:

On Friday, 7 July 2017 at 20:45:36 UTC, Moritz Maxeiner wrote:

On Friday, 7 July 2017 at 19:40:35 UTC, FoxyBrown wrote:
What's the "best" way to do this? I want something I can 
simply load at startup in a convenient and easy way then save 
when necessary(possibly be efficient at it, but probably 
doesn't matter).


Simply json an array and save and load it, or is there a 
better way?


"best" always depends on your specific use case. I use json 
files via asdf [1]


[1] https://github.com/tamediadigital/asdf



Seems like quite a heavy package for what I need. I just want 
to write a AA to disk and load it, ultimately.


Then I would go with INI, because you'll ultimately just have 
key-value pairs.


https://code.dlang.org/packages/baussini (Pretty old but should 
still work just fine.)


Re: Panda Antivirus puts the latest dmd installer in quarantine

2017-07-06 Thread bauss via Digitalmars-d-learn

On Thursday, 6 July 2017 at 18:33:35 UTC, Ecstatic Coder wrote:
But no problem with any file stored inside the current .7z 
archive file.


So I guess the problem comes from the installer executable 
itself.


Please try to fix this as soon as possible, as this immediately 
drives people away from D before they even got a chance to 
install it...


Why is it put in quarantine? Posting the reason and some 
information about it would help a lot to identify the issue.


Not everyone has "Panda Antivirus" installed and nobody working 
on dmd should be expected to anyway.


It's possible that the issue could be their AV too in which case 
contacting Panda Antivirus might be helpful too. I know in the 
past there has been problems with Avast.


See: https://forum.avast.com/index.php?topic=203573.0


Re: Finding all the interfaces and their inheritance relationships at runtime

2017-07-03 Thread bauss via Digitalmars-d-learn

On Monday, 3 July 2017 at 13:54:42 UTC, Jean-Louis Leroy wrote:

I know how to find all the classes:

foreach (mod; ModuleInfo) {
  foreach (c; mod.localClasses) {
// use c.base to construct inheritance graph
  }
}

Can I do the same with all the interfaces? Looking at object.d 
gives no clue...


Is there a reason you need to do it with runtime and can't use 
__traits?


Re: ReadProcessMemory + address from ollydbg

2017-07-01 Thread bauss via Digitalmars-d-learn

On Saturday, 1 July 2017 at 00:48:01 UTC, bauss wrote:

On Saturday, 1 July 2017 at 00:40:11 UTC, ag0aep6g wrote:

[...]


Yeah, the cast was unnecessary.

So this is my code after the changes:
string ReadWinString(HANDLE process, DWORD address, size_t 
stringSize, string defaultValue = "") {

  if (!process || !address) {
return defaultValue;
  }

[...]


I have solved the problem. It was caused by an invalid address, 
so the code actually worked fine.


Re: ReadProcessMemory + address from ollydbg

2017-06-30 Thread bauss via Digitalmars-d-learn

On Saturday, 1 July 2017 at 00:40:11 UTC, ag0aep6g wrote:

On 07/01/2017 02:30 AM, bauss wrote:

On Saturday, 1 July 2017 at 00:23:36 UTC, ag0aep6g wrote:

On 07/01/2017 01:41 AM, bauss wrote:

[...]

   if (!ReadProcessMemory(process,
 cast(PCVOID)address, cast(PVOID),


The second cast still looks suspicious. PVOID is void*, 
right? Then any mutable pointer type should implicitly 
convert to PVOID and you shouldn't need the cast.

[...]
Well the address is not a pointer. It's DWORD which is uint, 
so the cast is necessary since it stores the address.


Not that one. The other one. This one: `cast(PVOID)`.

I don't expect it to be related to your problem, but it 
shouldn't be necessary as far as I see.


Yeah, the cast was unnecessary.

So this is my code after the changes:
string ReadWinString(HANDLE process, DWORD address, size_t 
stringSize, string defaultValue = "") {

  if (!process || !address) {
return defaultValue;
  }

  SIZE_T bytesRead;
  char[1024] data;

  if (!ReadProcessMemory(process,
cast(LPCVOID)address, ,
stringSize, )) {
return defaultValue;
  }

  auto s = cast(string)data[0 .. stringSize].idup;

  return s ? s : defaultValue;
}

Results are still garbage data, correct length in bytesRead 
however.


I tried to pass the address with the main module's base address 
because I saw some posts online suggesting you might need to do 
that.


If I do that however I just get error 299 (ERROR_PARTIAL_COPY), 
so I don't think I needed the base address, but still can't 
figure out what exactly is wrong with my code and why I can't 
read the string from the address I give it, when it's a static 
address. Every time I look with ollydbg the address is the same 
and ollydbg can find the string just fine.


Re: ReadProcessMemory + address from ollydbg

2017-06-30 Thread bauss via Digitalmars-d-learn

On Saturday, 1 July 2017 at 00:23:36 UTC, ag0aep6g wrote:

On 07/01/2017 01:41 AM, bauss wrote:
string ReadWinString(HANDLE process, DWORD address, size_t 
stringSize, string defaultValue = "") {

   if (!process || !address) {
 return defaultValue;
   }

   SIZE_T bytesRead;
   char[1024] data;

   if (!ReadProcessMemory(process,
 cast(PCVOID)address, cast(PVOID),


The second cast still looks suspicious. PVOID is void*, right? 
Then any mutable pointer type should implicitly convert to 
PVOID and you shouldn't need the cast.



 stringSize, )) {
 return defaultValue;
   }

   auto s = cast(string)data[0 .. stringSize];

   return s ? s : defaultValue;


Here's an error that produces garbage.

`data` is a fixed-sized array, so the values are on the stack. 
That means `s` points to the stack. You can't return a pointer 
to the stack. It becomes invalid when the function returns. You 
can put it on the heap instead: `auto s = data[0 .. 
stringSize].idup;`.



}


Using ".idup" makes no difference in the result. I was under the 
impression the cast would already do that though, guess not. 
However the result is the same. I also tried to check "data" 
directly and it's already garbage there.


Well the address is not a pointer. It's DWORD which is uint, so 
the cast is necessary since it stores the address.




Re: ReadProcessMemory + address from ollydbg

2017-06-30 Thread bauss via Digitalmars-d-learn

On Friday, 30 June 2017 at 23:56:10 UTC, Stefan Koch wrote:

On Friday, 30 June 2017 at 23:53:19 UTC, bauss wrote:


I suspect the address is wrong, but it's the static address I 
picked up from ollydbg, so I'm kinda lost as for how ollydbg 
can get the correct string and I get the wrong one using same 
address.


You are aware that processes life in different memory spaces ?


Well it's a static address I'm trying to read from, so it 
shouldn't matter if I have the write handle to the process and 
the static address, should it?


Re: ReadProcessMemory + address from ollydbg

2017-06-30 Thread bauss via Digitalmars-d-learn

On Friday, 30 June 2017 at 23:41:19 UTC, bauss wrote:

On Friday, 30 June 2017 at 21:36:25 UTC, ag0aep6g wrote:

On Friday, 30 June 2017 at 20:14:15 UTC, bauss wrote:

[...]


I guess the first cast is necessary when `address` isn't typed 
as a pointer yet. But the other casts shouldn't be needed. If 
you get errors without them, those errors might give a hint on 
what's wrong.



[...]


bytesRead is a SIZE_T, no? Or maybe a DWORD.


It's the same.

This is my read function:
string ReadWinString(HANDLE process, DWORD address, size_t 
stringSize, string defaultValue = "") {

  if (!process || !address) {
return defaultValue;
  }

  SIZE_T bytesRead;
  char[1024] data;

  if (!ReadProcessMemory(process,
cast(PCVOID)address, cast(PVOID),
stringSize, )) {
return defaultValue;
  }

  auto s = cast(string)data[0 .. stringSize];

  return s ? s : defaultValue;
}

And this is how I call it:
auto text = ReadWinString(handleFromOpenProcess, 0x000, 16, 
"defaultString...");


where 0x000 is the address obviously.

If you can spot what I'm doing wrong it would be appreciated.


I mean I get data, it's not like the call fails or gives an 
error. It's just not the data I'm expecting.


I suspect the address is wrong, but it's the static address I 
picked up from ollydbg, so I'm kinda lost as for how ollydbg can 
get the correct string and I get the wrong one using same address.


Re: ReadProcessMemory + address from ollydbg

2017-06-30 Thread bauss via Digitalmars-d-learn

On Friday, 30 June 2017 at 21:36:25 UTC, ag0aep6g wrote:

On Friday, 30 June 2017 at 20:14:15 UTC, bauss wrote:

This is my definition:
BOOL ReadProcessMemory(HANDLE hProcess, LPCVOID lpBaseAddress, 
LPVOID lpBuffer, SIZE_T nSize, SIZE_T *lpNumberOfBytesRead);


And I'm reading it like this:
if (!ReadProcessMemory(process,
  cast(PCVOID)address, cast(PVOID),
  cast(DWORD)stringSize, cast(PDWORD))) {
  return defaultValue;
}


I guess the first cast is necessary when `address` isn't typed 
as a pointer yet. But the other casts shouldn't be needed. If 
you get errors without them, those errors might give a hint on 
what's wrong.



process is a HANDLE that I got from OpenProcess()
address is a DWORD
data is char[1024]
stringSize is size_t
bytesRead is PDWORD


bytesRead is a SIZE_T, no? Or maybe a DWORD.


It's the same.

This is my read function:
string ReadWinString(HANDLE process, DWORD address, size_t 
stringSize, string defaultValue = "") {

  if (!process || !address) {
return defaultValue;
  }

  SIZE_T bytesRead;
  char[1024] data;

  if (!ReadProcessMemory(process,
cast(PCVOID)address, cast(PVOID),
stringSize, )) {
return defaultValue;
  }

  auto s = cast(string)data[0 .. stringSize];

  return s ? s : defaultValue;
}

And this is how I call it:
auto text = ReadWinString(handleFromOpenProcess, 0x000, 16, 
"defaultString...");


where 0x000 is the address obviously.

If you can spot what I'm doing wrong it would be appreciated.


ReadProcessMemory + address from ollydbg

2017-06-30 Thread bauss via Digitalmars-d-learn
I'm currently getting garbage data when using ReadProcessMemory 
to read from another process.


This is my definition:
BOOL ReadProcessMemory(HANDLE hProcess, LPCVOID lpBaseAddress, 
LPVOID lpBuffer, SIZE_T nSize, SIZE_T *lpNumberOfBytesRead);


And I'm reading it like this:
if (!ReadProcessMemory(process,
  cast(PCVOID)address, cast(PVOID),
  cast(DWORD)stringSize, cast(PDWORD))) {
  return defaultValue;
}

process is a HANDLE that I got from OpenProcess()
address is a DWORD
data is char[1024]
stringSize is size_t
bytesRead is PDWORD

The address I obtained was from Ollydbg and it's a static 
address. I'm not sure if I however need some kind of offset etc.


I tried to search and found you might have to use 
GetModuleHandleA() but I tried that and I still get garbage data 
with the offset from that.


What am I doing wrong?


Re: Get Function Body

2017-06-30 Thread bauss via Digitalmars-d-learn

On Friday, 30 June 2017 at 16:43:33 UTC, Stefan Koch wrote:

On Friday, 30 June 2017 at 16:38:45 UTC, bauss wrote:

Is there a way to retrieve the body of a function as a string?

Scenario.

I want to pass a function to a mixin template and just mixin 
the body of the function.


Ex.

mixin template Foo(alias fun) {
void bar() {
mixin(getBodyOfFun(fun));
}
}

I'm aware that I can pass a string like mixin Foo!"a > b" but 
I would really like to avoid that.


I also can't just call "fun" as normal, unless it can be 
forced to be inline within the mixin template. The reason is 
if I mixin two mixin templates with the same function passed 
it must exist as two different function bodies executed, even 
tho they do the same.


Which means the following must have two "different" baz and 
not the actual baz.


void baz() { ... }

mixin Foo!baz;
mixin Foo!baz;

I don't know if it'll be possible without some sort of 
"parsing" the function or even without "string function 
bodies".


You need to function body as a string.
There is no way of retriving a functionBodyString from the 
compiler.

And I suspect it would be a bad idea to be able to do so.
Since the compiler may mutate the body while 
processing/optimizing.


Well in my case I don't want optimization or anything like that, 
in fact the original function wouldn't matter at all. I guess 
I'll go with the string way then though.


I'm aware this is probably not a scenario day-to-day code will 
need, but in my case I need to make my program as obscure as 
possible.


Get Function Body

2017-06-30 Thread bauss via Digitalmars-d-learn

Is there a way to retrieve the body of a function as a string?

Scenario.

I want to pass a function to a mixin template and just mixin the 
body of the function.


Ex.

mixin template Foo(alias fun) {
void bar() {
mixin(getBodyOfFun(fun));
}
}

I'm aware that I can pass a string like mixin Foo!"a > b" but I 
would really like to avoid that.


I also can't just call "fun" as normal, unless it can be forced 
to be inline within the mixin template. The reason is if I mixin 
two mixin templates with the same function passed it must exist 
as two different function bodies executed, even tho they do the 
same.


Which means the following must have two "different" baz and not 
the actual baz.


void baz() { ... }

mixin Foo!baz;
mixin Foo!baz;

I don't know if it'll be possible without some sort of "parsing" 
the function or even without "string function bodies".


Re: Advice wanted on garbage collection of sockets for c++ programmer using D

2017-06-27 Thread bauss via Digitalmars-d-learn

On Tuesday, 27 June 2017 at 10:14:16 UTC, Jonathan M Davis wrote:
On Tuesday, June 27, 2017 09:54:19 John Burton via 
Digitalmars-d-learn wrote:

[...]


Arguably, std.socket should have used structs instead of 
classes for sockets for precisely this reason (though there are 
some advantages in using inheritance with sockets). But yes, 
calling close manually is the correct thing to do. Relying on 
the GC to call a destructor/finalizer is error-prone. There is 
no guarantee that the memory will ever be freed (e.g. the 
runtime could choose to not bother doing cleanup on shutdown), 
and even if the GC does collect it, there are no guarantees 
about how soon it will do so. However, if you keep allocating 
memory with the GC, then over time, the GC will collect 
GC-allocated memory that isn't currently being used so that it 
can reuse the memory. So, you really don't need to worry about 
the memory unless it becomes a bottleneck. It will be collected 
and reused, not leaked.


[...]


I agree with that it should have been structs. The inheritance 
issue could be fixed by having a private member of the struct in 
a class, that way there could still be a class wrapper around it.


Re: Clean Executable

2017-06-27 Thread bauss via Digitalmars-d-learn

On Tuesday, 27 June 2017 at 14:21:50 UTC, FoxyBrown wrote:
How can we clean an exe from the junk library functions that 
are not actually used by an app. e.g., a hello world program 
shouldn't be 500+kb. I release there are necessary extras like 
the GC, but hell, in a hello world program is it even 
necessary? Does Writeln even use the GC to display a single 
string?


Seems like D just does not optimize the binaries size. I know 
it's only 500kb, but still.


If you want optimizations don't use DMD.


Re: GDC generate wrong .exe ("not a valid win32 application")

2017-06-22 Thread bauss via Digitalmars-d-learn

On Wednesday, 21 June 2017 at 15:55:27 UTC, David Nadlinger wrote:

On Monday, 19 June 2017 at 14:08:56 UTC, Patric Dexheimer wrote:

Fresh install of GDC. (tried with 32x ad 32_64x)


Where did you get the GDC executable from? The GDC project 
doesn't currently offer any official builds that target 
Windows; the 6.3.0 builds from https://gdcproject.org/downloads 
in fact generate Linux binaries.


 — David


I see Windows distributions below the Linux ones.


Re: Which editor to use for editing DDOCs?

2017-05-23 Thread bauss via Digitalmars-d-learn

On Tuesday, 23 May 2017 at 07:40:21 UTC, biocyberman wrote:

On Monday, 22 May 2017 at 15:33:36 UTC, Russel Winder wrote:

[...]


Adding DDOC support for D Mode require some more work 
obviously. I will see if I can make some changes to that. For 
the time being, I would like to know which editors people are 
using. Or is it a plain black and white editor ?


I just use Atom.


Re: Cheetah: Keeping track of multiple connected clients

2017-05-18 Thread bauss via Digitalmars-d-learn

On Thursday, 18 May 2017 at 11:44:57 UTC, aberba wrote:

On Tuesday, 16 May 2017 at 21:56:16 UTC, aberba wrote:

On Tuesday, 16 May 2017 at 17:49:07 UTC, bauss wrote:

[...]


It really awesome the way you responded quickly. About 
targeting a client, suppose I have clients A, B, and C.


Message can be broadcast to all using above solution. But in 
case A want to sent message to B and not C, how does server 
detect the specific destination client's id? Does 
client.send(...) allow json string with target id from browser 
client?


I'm trying to find a way to receive meesage in one language 
along with target client's id and send to the target after I 
have translated to another lang.


To reframe my question, When client A sends a message meant for 
client B, is there a facility in cheetah to identify source and 
destination clients?


 (looked through the code, did not find any obvious info on 
properties of a client or a message event)


Well it isn't based directly around Websockets, so for those to 
work you'd have to implement the websocket protocol or you could 
attempt to fork cheetah and wrap vibe.d's websocket 
implementation into it; if you don't have time or don't really 
know how to exactly, then I'd see if I can make time for it. 
However as for identifying the source, it really depends on how 
your packet protocol. Cheetah isn't meant to be a one-type only 
socket library and it's up to the user themselves to implement 
their packet protocol because it can vary from implementation to 
implementation. Some might sent raw json, some might sent xml, 
some might sent raw binary, some might sent http packets, you get 
me? I might come up with a generic version to attempt to fit them 
all, but it's quite a bit of work to do so, which is why right 
now it's up to the individual user to implement their packet 
protocol. I'd assume since you're using Websockets your protocol 
is probably json. After the whole handshake for websockets are 
done then it should be fairly simple to implement the message 
receiving.


If you want to know how the exact implementation should be, then 
you can read here.


https://tools.ietf.org/html/rfc6455

I assume you'll be able to find what you're looking for there.

Reading it raw would be something like continuously receiving a 
static amount of byte like 1024 and then keep doing that until 
all chunks make up a proper json object, then you take the 
remaining bytes (Because they might hold next packet) and keep 
doing the same thing for the next object, then simply repeating. 
Then you can simply have a property in the object that has a 
client id (Which should correspond to the id the server has given 
the client.) As for how the client itself should know the id. You 
can simply send a packet to the client when it connects which 
contains the client id.


If you want the above simplified, let me know.


Re: D equivalent of C++11's function local static initialization?

2017-05-17 Thread bauss via Digitalmars-d-learn

On Wednesday, 17 May 2017 at 03:08:39 UTC, Timothee Cour wrote:

NOTE: curious about both cases:
* thread local
* shared

On Tue, May 16, 2017 at 8:04 PM, Timothee Cour 
 wrote:
what's the best D equivalent of C++11's function local static 
initialization?

```
void fun(){
  static auto a=[](){
//some code
   return some_var;
  }
}
```

(C++11 guarantees thread safety)


I don't know the exact equivalent, mostly because I don't really 
know what the C++ statement does tbh. Tried to look it up real 
quick, but can't seem to find anything actual information on it.


However I can answer about thread local and shared.

Every global is per standard thread local in D.

For example:
int foo;

void fun() {
foo++;
writeln(foo);
}

void main() {
spawn();
spawn();
}

In D the output is:
1
1

However in other languages that doesn't have thread-local per 
standard the output may vary depending on race-conditions.


So it could be:
1
1

Or:
1
2

Then there's shared.

Shared is kind of a bottle-neck to use and if you're going to use 
it you should write all your code as shared and synchronized from 
the beginning else you'll just end up ripping your hair out. 
shared variables are required to be used in synchronized 
contexts, that's about it. It sounds simple, but implementing it 
properly is not that easy and tends to just be a bothersome in 
exchange for other safe implementation


On the contrary to shared, there's __gshared which is basically 
the equivalent to plain old globals in C.


Re: Cheetah: Keeping track of multiple connected clients

2017-05-16 Thread bauss via Digitalmars-d-learn

On Tuesday, 16 May 2017 at 16:01:49 UTC, aberba wrote:
Does anyone know how to keep track of multiple clients in 
Cheetah socket lib such that one can directly message a client 
or broadcast to all connected clients.



Something like:

onMessage(... e)
{
...
   // send to all
   e.clients.broadcast (message);

...OR...
   // target a client
e.clients[clientID].send(message);
}

Or any D lib with similar function.


I have now added an internal client-storage to the project.

The server will have a getClientById(size_t) and a getClients() 
which can be used.


Ex.

foreach (client; e.server.getClients())  {
// ... Broadcast to each client here
}

...

e.server.getClientById(clientId).send(...);

Each client will be attached to a clientId when they connect.

The client id is a property of the SocketClient class.

To enable the internal storage you must set storeClients to true 
on the server when initializing it, otherwise the storage won't 
be used.


Ex.

server.storeClients = true;

If you don't want to get latest version of it, then you can just 
make your own storage ex. an associative array and then add each 
client to it when they connect.


Right now dub doesn't seem to be able to trigger a manual update 
on the package, so you might have to fetch the updates manually 
from the Github repository.


https://github.com/bausshf/cheetah/commit/9646fd407d274a94c37dc1b0297541963aeb3e6d


Re: avoid extra variable during void pointer cast

2017-05-15 Thread Bauss via Digitalmars-d-learn

On Sunday, 14 May 2017 at 21:07:36 UTC, Marco Leise wrote:

Am Sun, 14 May 2017 20:18:24 +
schrieb Kevin Brogan :


[...]


No, that is not possible. An alias can only be assigned a 
symbol.



[...]


Let the compiler optimize the assignment away and don't worry 
much about it. Inlining also works well within the same module. 
In this case here I would probably use "consume" functions as I 
dub them:


import std.traits;
pragma(inline, true) /* Not really needed I hope ;) */
ref T consume(T)(ref void* data) if (!hasIndirections!T)
{
T* ptr = cast(T*)data;
data += T.sizeof;
return *ptr;
}

You can then rewrite your addInt function like this:

void add(T)(void* state, void* data) if (isNumeric!T)
{
state.consume!T += data.consume!T;
}


pragma(inline, true); doesn't actually do what you think it does. 
In lining is always done whenever possible and that only tells 
the compiler to spit out an error if it can't inline it.




Re: How to declare "abstract" delegates list?

2017-05-06 Thread bauss via Digitalmars-d-learn

On Saturday, 6 May 2017 at 06:07:01 UTC, bauss wrote:

On Friday, 5 May 2017 at 14:20:43 UTC, RedCAT wrote:

[...]


I would do something like this:

[...]


You could also do use alias this to use the delegate instead of 
the class encapsulating the delegate.


Re: How to declare "abstract" delegates list?

2017-05-06 Thread bauss via Digitalmars-d-learn

On Friday, 5 May 2017 at 14:20:43 UTC, RedCAT wrote:

Hello!

Is it possible to create a list of slightly different delegates?

For example, there is a class hierarchy:

class Base;
class DerivedOne : Base;
class DerivedTwo : Base;

And there are several delegates:

void delegate(int, Base);
void delegate(int, DerivedOne);
void delegate(int, DerivedTwo);

It's easy to see that the only difference in the declarations 
of these delegates is the type of the second parameter, this is 
the class inherited from Base.


How can I create a list or an array where I can add these 
delegates?


I would do something like this:

interface IMyDelegate { }

final class MyDelegate(T) : IMyDelegate {
private:
void delegate(int, T) _d;

public:
this(void delegate(int, T) d) {
_d = d;
}

void opCall(int x, T y) {
_d(x, y);
}
}

... Below is simple usage demonstration ...

private IMyDelegate[] _delegates;

void addDelegate(T)(void delegate(int, T) d) {
_delegates ~= new MyDelegate!T(d);
}

auto getDelegate(size_t index) {
return cast(MyDelegate!T)_delegates[index];
}

...

void func1(int, Base) { ... }
void func2(int, DerivedOne) { ... }
void func3(int, DerivedTwo) { ... }

...

addDelegate();
addDelegate();
addDelegate();

(getDelegate!Base)(100, base);
(getDelegate!DerivedOne)(100, derivedOne);
(getDelegate!DerivedTwo)(100, derivedTwo);

By theory that should work. It's untested, so you might need a 
few tweaks here and there.


Re: Productive vibe.d dev environment (IDE, debugger) on Linux?

2017-05-04 Thread bauss via Digitalmars-d-learn

On Wednesday, 3 May 2017 at 17:43:07 UTC, kinke wrote:

Hey guys,

can anyone recommend a more or less production-ready dev 
environment for vibe.d on Linux?
I'm evaluating vibe.d against Phoenix (Elixir/Erlang) for a new 
project. Today I gave Visual Studio Code a quick shot (with LDC 
1.1.1 and DMD 2.071/72/74), with Webfreak's plugins, but I'm 
not happy at all (gdb/lldb crashing most of the time incl. 
debugged process, no AutoComplete/IntelliSense due to problems 
when building some of the plugin dependencies etc.).


Any hints are greatly appreciated, as I'm really impressed by 
vibe.d itself so far.


I really just use Atom along with plugins to call build scripts 
that eventually calls dub for building.


Sadly there's still no actual "good" D IDE.


Re: String Comparison Operator

2017-04-30 Thread bauss via Digitalmars-d-learn

On Sunday, 30 April 2017 at 16:15:41 UTC, Xinok wrote:

On Sunday, 30 April 2017 at 15:31:39 UTC, Jolly James wrote:

Is there a String Comparison Operator in D?


Yeah, just the usual comparison operators:

"abc" == "abc"
"abc" != "ABC"


~ is for string concatenation, i.e.:

"abc" ~ "def" == "abcdef"


Just to clarify.

It's not actually a string concatenation operator, it's an array 
appending operator.


Strings are just an alias for immutable(char)[] and not actually 
a type unlike other languages like C#, Java etc. where strings 
are objects.


In fact it doesn't have any operators that doesn't work with any 
other type of arrays. Just like functions such as replace etc. 
aren't necessarily string functions, but works with any type of 
arrays.


Re: alias can't find symbol or can't use symbol

2017-04-29 Thread bauss via Digitalmars-d-learn

On Sunday, 30 April 2017 at 00:17:37 UTC, Carl Sturtivant wrote:

Consider the following.

struct member
{
int n;
}

struct outer
{
member x;
alias x this;
alias n2 = n;
}

This does not compile: alias n2 = n;
Error: undefined identifier 'n'

On the other hand if change that into
alias n2 = x.n;
then it does compile.

void main()
{
outer o;
o.n2 = 5;
}

Now this code doesn't compile: o.n2 = 5;
Error: need 'this' for 'n' of type 'int'

Given that one struct inside another is a static situation, 
this seems unnecessarily strict. It's getting in the way of 
some name management with `alias this`. What's the rationale 
here?


What exactly did you expect here?

'n' is not in the scope of 'outer'.

'n' is in the scope of 'member'.

Of course it works with 'x.n' since 'x' points to the 'member' 
declared inside 'outer'.


I mean it would have worked with classes, but structs are 
different does not have any type of actual inheritance, which is 
what you're trying to achieve.


```
class member {
int n;
}

class outer : member {
alias n2 = n; // Ok ...
}
```


Re: Why is this legal?

2017-03-30 Thread bauss via Digitalmars-d-learn

On Wednesday, 29 March 2017 at 10:08:02 UTC, abad wrote:
Related question, it seems that final methods are allowed in 
interfaces. Obviously you can't implement them anywhere, so is 
this also on purpose and on what rationale? :)


That is not necessarily true. Final doesn't imply it can't be 
implemented. It implies that it cannot be override.




Re: How to continue after the book?

2017-03-28 Thread bauss via Digitalmars-d-learn

On Tuesday, 28 March 2017 at 07:27:31 UTC, I Lindström wrote:
After getting the basics down, how did you continue when 
learning programming in general?


I do have a need for which I've been trying out a few languages 
and D seems by far the best for me. Should I just start doing 
that project and learn as I go by googling and asking here, or 
are there some other things you did before starting your first 
"real" project.


I have never actually used a book to learn. Practice is the best 
way to learn, at least for me. It differs from person to person 
how they learn best.


What I have used books for though, is improving knowledge on 
fields that I most likely know or to learn basic knowledge or 
different views on certain fields.


I haven't read a lot of books, especially not for D. I've only 
gotten Andrei's and Adam's book. Looked a tiny bit through Ali's, 
but yeah. I'm not much of a book person when it comes to learning 
programming or anything alike. I do enjoy reading them, but 
generally it's to expand my current knowledge and not to learn 
anything new.


What I usually do is to pick a certain type of project, write 
down each requirement and feature it needs and then see what 
certain skills I'd need to finish it and then take one thing at a 
time, then after each time I scrap the project and start over to 
re-write it with improvements.


Re: Howto catch SocketOSException?

2017-03-26 Thread bauss via Digitalmars-d-learn

On Sunday, 26 March 2017 at 11:46:39 UTC, Jolly James wrote:

On Sunday, 26 March 2017 at 11:35:00 UTC, Jolly James wrote:

[...]


Found out something: You cannot catch any exception thrown in 
the listen()-method in general.



■ Original code:

[...]



■ Modified one:

[...]



■ Not working try-catch:

[...]


Chances are it's invoked in another thread and thus you can't 
catch it like that.


To sum it up.

Ex.

void thisFunctionThrows() { ... }

void ableToCatch() {
try {
thisFunctionThrows();
}
catch (Exception e) {
// We can catch the exception ...
}
}

void notAbleToCatch() {
try {
spawn();
}
catch (Exception e) {
// We cannot catch the exception ...
}
}

void ableToCatchToo() {
spawn(); // We're able to handle the exception, 
because the try/catch is handled in the thread that calls the 
function that throws.

}


Re: Howto catch SocketOSException?

2017-03-25 Thread bauss via Digitalmars-d-learn

On Sunday, 26 March 2017 at 00:34:03 UTC, Jolly James wrote:

How do you catch an std.socket.SocketOSException?


The following does not work, as the exception occurs anyway and 
leads to a crash:



import ae.net.asockets;

void main(string[] args)
{
TcpServer tcp = new TcpServer();

try
{
tcp.listen(2345, "127.0.0.1c");
// '...c' makes the IP address invalid
}
catch (std.socket.SocketOSException e)
{
return;
}
catch (Exception e)
{
return;
}

socketManager.loop();
}


Output:
std.socket.SocketOSException@std\socket.d(975): getaddrinfo 
error: Unknown Host


This part:
catch (std.socket.SocketOSException e)

{
return;
}


Is redundant, because SocketOSException inherits SocketException 
which inherits Exception.


It should already be caught by catch (Exception e)

You should have a full stacktrace, chances are that it's invoked 
in your loop()?


Re: union.sizeof

2017-03-25 Thread bauss via Digitalmars-d-learn

On Saturday, 25 March 2017 at 23:36:07 UTC, kinke wrote:

On Saturday, 25 March 2017 at 22:45:22 UTC, ketmar wrote:

zabruk70 wrote:


[...]


`align(1) union Union1` will do the trick.

what you did is members packing. but the union itself is 
padded to integer size too. i.e. internal `align` will set 
aligning for *members*, and external `align` will change 
padding of the whole thing.


The union should have an implicit alignment of 1 already 
though, right? It's defined as the maximum of all member 
alignments, and both the bytes5 array and the anonymous struct 
members have an explicit alignment of 1. The alignment of the 
anonymous struct's int1 member (explicitly 1 too) shouldn't 
even matter.


Why should it have an implicit alignment of 1? The alignment 
completely depends on the definition unless specified AFAIK.


Re: questions about dub

2017-03-21 Thread bauss via Digitalmars-d-learn

On Tuesday, 21 March 2017 at 21:01:31 UTC, thorstein wrote:

Hi,

I have questions regarding the usage of 'dub'. I'm learning D 
under Win7. I have installed VisualD for the community edition 
of Visual Studio and got some file i/o working.


Next I would like to continue with the mir-tools for matrix 
manipulation. I understood that I have to build them first 
using dub. But I didn't succeed:


C:\..\AppData\Roaming\dub>dub fetch mir-algorithm
Fetching mir-algorithm 0.1.1...
Please note that you need to use `dub run ` or add it 
to dependencies of your package to actually use/run it. dub 
does not do actual installation of packages outside of its own 
ecosystem.


C:\..\AppData\Roaming\dub>dub run mir-algorithm
Building package mir-algorithm in 
C:\..\AppData\Roaming\dub\packages\mir-algorithm-0.1.1\mir-algorithm\

Fetching mir-internal 0.0.5 (getting selected version)...
Main package must have a binary target type, not sourceLibrary. 
Cannot build.


Thats where I stuck.

Beside my specific problem of how to start with the mir-tools I 
wonder how and for what purpose 'dub' is applied when building 
projects in connection with Visual Studio? Or is it just a more 
light-weight command line build tool?


Thanks for shedding some light!
Thorstein


Generally if your dub.json or dub.sdl is configured correctly 
then all you need is to run "dub build" which will invoke package 
fetching etc. and then your desired compiler.


Dependencies are defined in dub.json / dub.sdl using 
"dependencies" which takes values as "packagename" and then 
"version".


Example: "vibe-d" "~>0.7.28"

I don't know if that helps.

I'm not familiar with Visual-D and don't use it at all, so I 
don't know if dub has to be used in specific ways. I compile 
though command line only, so.


Re: How to get inner most nested struct

2017-03-16 Thread bauss via Digitalmars-d-learn

On Friday, 17 March 2017 at 01:52:20 UTC, Hussien wrote:

On Friday, 17 March 2017 at 01:19:54 UTC, Adam D. Ruppe wrote:

On Friday, 17 March 2017 at 00:34:22 UTC, Hussien wrote:

Anyway to do this?


I don't think you can, the inner anonymous structs are just to 
organize the members and group them inside the union.


;/ D should retain the structure in some way and allow for one 
to traverse it.


Declare them as separate structs and simply put them in there.

Ex.

struct Foo {
int bar;
int baz;
}

struct Foo2 {
union {
long bar;

Foo baz;
// Equal to:
/*
struct {
int bar;
int baz;
}
*/
}
}

Only way I could think of achieving this.


Re: Is there a more elegant way to do this?

2017-03-11 Thread bauss via Digitalmars-d-learn

On Sunday, 12 March 2017 at 05:13:41 UTC, bauss wrote:
I was wondering if there's a more elegant way to do something 
like this?


[...]


I saw one improvement to it which would be BitSize!ChildType 
instead of taking parent type's bit size divided by two.


Also

value = ((highValue << 16 | low));

Is supposed to be

value = ((highValue << BitSize!ChildType | low));


Is there a more elegant way to do this?

2017-03-11 Thread bauss via Digitalmars-d-learn
I was wondering if there's a more elegant way to do something 
like this?


template BitSize(T) {
enum BitSize = T.sizeof * 8;
}

struct Data(ParentType,ChildType) {
@property {
ChildType low() { return cast(ChildType)value; }
void low(ChildType lowValue) {
value = ((high << (BitSize!ParentType / 2)) | lowValue);
}

		ChildType high() { return cast(ChildType)(value >> 
(BitSize!ParentType / 2)); }

void high(ChildType highValue) {
value = ((highValue << 16 | low));
}
}

ParentType value;

alias value this;
}

Example usage:
void main() {
Data!(uint,ushort) data;
data = 14065735;

writefln("low: %s high: %s", data.low, data.high);

data.low = 41031 ;
data.high = 214;

writefln("value: %s", data.value);
}

Basically to explain what it is: You give it a parent-type and a 
corresponding child-type.


Ex. if the parent-type is uint, the child-type would be ushort.
if the parent-type is long, the child-type would be int.
etc.

What it allows you to is to either manipulate the data as the 
parent-type or as two values of the child type.


I was just wondering if there's a more elegant or performant way 
to do this, perhaps something in Phobos exist already?


Re: TLS

2017-03-10 Thread bauss via Digitalmars-d-learn

On Friday, 10 March 2017 at 07:33:44 UTC, M-exe wrote:
On Friday, 10 March 2017 at 07:17:22 UTC, rikki cattermole 
wrote:

D does not support Windows XP.
If you absolutely require it, you will have to contact Walter 
about support.


Let me care about it ;)
I just need help with the TLS :)


Mark your variables with __gshared. I would say shred, but it has 
some restrictions to it, where __gshared is the equivalent to 
global variables in C.


Re: Building a project with CMAKE

2017-03-02 Thread bauss via Digitalmars-d-learn

On Thursday, 2 March 2017 at 12:42:00 UTC, Russel Winder wrote:
On Tue, 2017-02-28 at 17:09 +, berni via 
Digitalmars-d-learn wrote:

[...]


I do not have an immediate answer, but…

CLion requires CMake, with CMake-D in a fit state we could use 
CLion with D – albeit very rough and ready way, at least 
initially. I am sure the DLanguage IDEA plugin can be made to 
work with CLion. If this combination can be made to work at 
all, then it can be improved over time.


Personally I am now at the stage that without an IDE I don't 
start a project using that language. The important IDEs are 
JetBrains family and Eclipse. Anything else is niche or an also 
ran. At least currently.


I am about to not use D for a new project because C++, Rust and 
Go have good IDEs. And I am an Emacs person. I guess I will 
have to join Emacs Anonymous as I do not use it any more except 
for LaTeX and AsciiDoc files. OK I use the Emacs bindings in 
the IDEs obviously.


Unless the combination I proposed actually works. I will give 
it a go.


While it's true that they have better IDE's, I often find IDE's 
too bulky so I often end up using Atom or something similar with 
cmd plugins in which way it kinda acts like an IDE. Only thing 
that sucks using editors like that is debugging, but generally 
it's not a big deal to just run the code in an IDE and then debug 
it.


<    1   2   3   4   5   6   >