Re: Logging logs in Windows

2023-02-07 Thread Kagamin via Digitalmars-d-learn
On Saturday, 4 February 2023 at 13:31:41 UTC, Alexander Zhirov 
wrote:
I understand that programming under Windows is a shame for a 
programmer, but is there really no ready-made solution for 
using the system log in Windows?


It would be a logging library like log4j that would have 
different logging backends.


Re: ImportC "no include path set"

2023-02-07 Thread Elfstone via Digitalmars-d-learn

On Wednesday, 8 February 2023 at 04:14:21 UTC, ryuukk_ wrote:

On Tuesday, 7 February 2023 at 14:01:00 UTC, Elfstone wrote:

On Tuesday, 7 February 2023 at 13:10:44 UTC, ryuukk_ wrote:

On Tuesday, 7 February 2023 at 06:25:59 UTC, Elfstone wrote:

On Monday, 6 February 2023 at 14:35:53 UTC, bachmeier wrote:

[...]


Thanks, it worked, but I still get the link error.
I wasn't expecting to configure include paths and link the 
right libc myself. The doc says the simple "dmd hello.c" 
should create "hello.exe". It must be a bug.


You need to run dmd from the developer command prompt on 
windows


I always found this requirement weird

From an UX point of view, what would the better experience 
be? Could DMD ship with the required files? I have 0 
knowledge how the whole thing works so..


That I tried, and I got link error(s) - see my first post. :(


Oh my bad, i misread your comment

Make sure your visual studio install is up to date, maybe you 
have one component missing?


https://learn.microsoft.com/en-us/cpp/build/vscpp-step-0-installation

If you installed/updated VS without reboot, maybe a reboot 
could do the trick?


I believe all three versions (2017,2019,2022) of my VS are up to 
date, and I have working C/C++ projects on them.
But you encouraged me to give a few more tries, and I found out I 
had been using ..bin64/dmd.exe. Running ..bin/dmd.exe in VS 
Command Prompt turned out successful. Thx!


Re: ImportC "no include path set"

2023-02-07 Thread ryuukk_ via Digitalmars-d-learn

On Tuesday, 7 February 2023 at 14:01:00 UTC, Elfstone wrote:

On Tuesday, 7 February 2023 at 13:10:44 UTC, ryuukk_ wrote:

On Tuesday, 7 February 2023 at 06:25:59 UTC, Elfstone wrote:

On Monday, 6 February 2023 at 14:35:53 UTC, bachmeier wrote:

[...]


Thanks, it worked, but I still get the link error.
I wasn't expecting to configure include paths and link the 
right libc myself. The doc says the simple "dmd hello.c" 
should create "hello.exe". It must be a bug.


You need to run dmd from the developer command prompt on 
windows


I always found this requirement weird

From an UX point of view, what would the better experience be? 
Could DMD ship with the required files? I have 0 knowledge how 
the whole thing works so..


That I tried, and I got link error(s) - see my first post. :(


Oh my bad, i misread your comment

Make sure your visual studio install is up to date, maybe you 
have one component missing?


https://learn.microsoft.com/en-us/cpp/build/vscpp-step-0-installation

If you installed/updated VS without reboot, maybe a reboot could 
do the trick?


Re: Default arguments

2023-02-07 Thread Salih Dincer via Digitalmars-d-learn

On Tuesday, 7 February 2023 at 09:49:46 UTC, Salih Dincer wrote:
Is it a feature or a bug that the code below can be compiled 
without arguments?


You should use `@disable this()` recommended in the relevant 
article: 
https://dlang.org/spec/struct.html#disable_default_construction


```d
void main()
{
auto noArgument = Sarr!char(); // no compile
}
```

On Tuesday, 7 February 2023 at 09:49:46 UTC, Salih Dincer wrote:
I want to learn one more thing. Why can't the default argument 
be used in alias of structs?


```d
void main()
{
auto bar = Sarr!()(dlang.dup); // complied
assert(is(typeof(bar.arr[0]) == char));
}
```
😀

SDB@79




Wrong compiler error message regarding overload sets

2023-02-07 Thread Andre Pany via Digitalmars-d-learn

Hi,

for the source code below, the compiler says:

app.d(26): constructor `app.TObject.this` hides base class 
function `app.DelphiObject.this`
app.d(26): add `alias this = app.DelphiObject.this` to 
`app.TObject`'s body to merge the overload sets


But if I add `alias this = app.DelphiObject.this` then the 
compiler says, the syntax is wrong:


Error: identifier or `new` expected following `.`, not `this`
app.d(20): Error: cannot use syntax `alias this = 
app.DelphiObject`, use `alias app.DelphiObject this` instead


But If I use `alias app.DelphiObject this` then another error is 
shown:

app.d(22): Error: no identifier for declarator `app.DelphiObject`
app.d(22):`this` is a keyword, perhaps append `_` to make 
it an identifier


What is the correct "alias this" syntax to be able to access the 
super constructor (DelphiObjectReference)?


``` d
struct DelphiObjectReference
{
ptrdiff_t reference;
}

mixin template PascalClass(string name)
{
this (DelphiObjectReference r){}
}

class DelphiObject
{
this(){}
this (DelphiObjectReference r){}
}

class TObject : DelphiObject
{
mixin PascalClass!("System.TObject");

this(TObject AOwner){}
}

void main()
{
new TObject(DelphiObjectReference(123));
}
```

Kind regards
André


Re: Non-ugly ways to implement a 'static' class or namespace?

2023-02-07 Thread ProtectAndHide via Digitalmars-d-learn

On Tuesday, 7 February 2023 at 16:16:48 UTC, Ali Çehreli wrote:

On 2/6/23 23:33, ProtectAndHide wrote:
> On Monday, 6 February 2023 at 21:46:29 UTC, Ali Çehreli wrote:

>> And as 'static class' and 'static struct' are already usable
in D, a
>> newcomer would definitely be confused with your "terrible"
conclusion.

> You being a little agressive don't you think?

I see how wrong that came out. Apologies! What I meant was 
"your conclusion [about something here being] terrible".


> My observation is very reasonable, and correct,

Agreed.

> The compiler will allow you to do all these things

Agreed.

> I can see no reason why anyone would want to do these things,
in this
> context.

Agreed.

> Nor can I see any reason, whatsoever, why the compiler would
allow you
> to do these things, in this context.

My understanding is that these are side-effects of trying to 
have orthogonal features. Some combinations don't make sense.


Having said that, since D does not use 'static class' for 
namespacing, should it go out of its way to implement logic to 
ban that combination at module scope? Perhaps. People have been 
discovering meaningless combinations of attributes in D all the 
time. (I forgot why that is so.)


If D disallowed 'static' at module scope, we wouldn't be having 
this discussion anyway. If that happened, then 'class' would be 
accepted for being used for creating objects.


Ali


Well, in C++ I can just mark the destructor as = delete;

The compiler now won't let me do those things that D would allow.

D could do something similar I guess, with: @disable ~this();

In fact, a static class is a very useful abstraction.

C# just makes it 'easy' for the programmer to define it as such, 
without all the nonsense other languages require. In addition, 
the C# compiler WILL prevent nonsense code, which is exactly what 
I want from a compiler ;-)


When a compiler allows nonsense code, my confidence in it begins 
to wane...





Re: Non-ugly ways to implement a 'static' class or namespace?

2023-02-07 Thread Ali Çehreli via Digitalmars-d-learn

On 2/6/23 23:33, ProtectAndHide wrote:
> On Monday, 6 February 2023 at 21:46:29 UTC, Ali Çehreli wrote:

>> And as 'static class' and 'static struct' are already usable in D, a
>> newcomer would definitely be confused with your "terrible" conclusion.

> You being a little agressive don't you think?

I see how wrong that came out. Apologies! What I meant was "your 
conclusion [about something here being] terrible".


> My observation is very reasonable, and correct,

Agreed.

> The compiler will allow you to do all these things

Agreed.

> I can see no reason why anyone would want to do these things, in this
> context.

Agreed.

> Nor can I see any reason, whatsoever, why the compiler would allow you
> to do these things, in this context.

My understanding is that these are side-effects of trying to have 
orthogonal features. Some combinations don't make sense.


Having said that, since D does not use 'static class' for namespacing, 
should it go out of its way to implement logic to ban that combination 
at module scope? Perhaps. People have been discovering meaningless 
combinations of attributes in D all the time. (I forgot why that is so.)


If D disallowed 'static' at module scope, we wouldn't be having this 
discussion anyway. If that happened, then 'class' would be accepted for 
being used for creating objects.


Ali



Re: Non-ugly ways to implement a 'static' class or namespace?

2023-02-07 Thread Ali Çehreli via Digitalmars-d-learn

On 2/6/23 23:45, ProtectAndHide wrote:

> Well I don't agree that D should boast about things that's its
> implemented in an unprincipled way.

Here, "unprincipled"[1] is just a descriptive word meaning that D does 
not insist on certain software engineering methodologies e.g. unlike 
Java where "everything is a class" or unlike some functional programming 
languages where "everything must be immutable".[2]


> an unprincipled
> implementation of something that just allows you do make mistakes, then
> it should be looked at further, so see if it can be improved.

Agreed. But the lack of 'static class' in D or its approximations are 
not in that category. I can imagine someone coming up ingeniously with a 
harmful way of using 'static class' but unless that is a real problem 
that affects D users then there is no issue.


Ali

[1] I remember reading or hearing "unprincipled" from Andrei 
Alexandrescu long time ago.


[2] Actually, const and immutable being transitive can be seen as 
counter examples of D having a strong point on something. I think this 
"turtles all the way down" is not agreed by many users.




Re: ImportC "no include path set"

2023-02-07 Thread Elfstone via Digitalmars-d-learn

On Tuesday, 7 February 2023 at 13:10:44 UTC, ryuukk_ wrote:

On Tuesday, 7 February 2023 at 06:25:59 UTC, Elfstone wrote:

On Monday, 6 February 2023 at 14:35:53 UTC, bachmeier wrote:

[...]


Thanks, it worked, but I still get the link error.
I wasn't expecting to configure include paths and link the 
right libc myself. The doc says the simple "dmd hello.c" 
should create "hello.exe". It must be a bug.


You need to run dmd from the developer command prompt on windows

I always found this requirement weird

From an UX point of view, what would the better experience be? 
Could DMD ship with the required files? I have 0 knowledge how 
the whole thing works so..


That I tried, and I got link error(s) - see my first post. :(


Re: ImportC "no include path set"

2023-02-07 Thread ryuukk_ via Digitalmars-d-learn

On Tuesday, 7 February 2023 at 06:25:59 UTC, Elfstone wrote:

On Monday, 6 February 2023 at 14:35:53 UTC, bachmeier wrote:

On Monday, 6 February 2023 at 06:55:02 UTC, Elfstone wrote:


So how am I supposed to set the include path?


https://dlang.org/spec/importc.html#preprocessor

The -Ppreprocessorflag switch passes preprocessorflag to the 
preprocessor.


So if you normally use `-I/foo`, you'd add `-P-I/foo`.


Thanks, it worked, but I still get the link error.
I wasn't expecting to configure include paths and link the 
right libc myself. The doc says the simple "dmd hello.c" should 
create "hello.exe". It must be a bug.


You need to run dmd from the developer command prompt on windows

I always found this requirement weird

From an UX point of view, what would the better experience be? 
Could DMD ship with the required files? I have 0 knowledge how 
the whole thing works so..




Default arguments

2023-02-07 Thread Salih Dincer via Digitalmars-d-learn

Hi All...

Is it a feature or a bug that the code below can be compiled 
without arguments?


```d
import std.stdio, std.conv : to;
void main()
{
auto noArgument = Sarr!char(); // it works no argument...
assert(noArgument.length == 8);

string dlang = "D-lang";
const len = dlang.length;

auto withArgument = Sarr!char(dlang.dup); // complied
assert(withArgument.arr[0..len].to!string == dlang);
}

template Sarr(alias T = char)
{
enum s = size_t.sizeof / T.sizeof;
struct Sarr
{
T[s] arr = T(0);
auto length = s;

this(A)(A[] arr) in(s >= arr.length)
{
foreach(i, e; arr)
{
this.arr[i] = cast(T)e;
}
}
}
}
```

I want to learn one more thing. Why can't the default argument be 
used in alias of structs? Voldemort types work just fine for 
example:


```d
template Farr(alias T = char)
{
enum s = size_t.sizeof / T.sizeof;
struct Result
{
T[s] arr = T(0);
auto length = s;
}
Result Farr(A)(A[] arr) in(s >= arr.length)
{
Result result;
foreach(i, e; arr)
{
result.arr[i] = cast(T)e;
}
return result;
}
}

import std.stdio;
void main()
{
auto arr = [ 'd', 'e' ];
auto foo = Farr(arr);
foo.writeln; // Result("de\0\0\0\0\0\0", 8)

// auto bar = Sarr(arr); // no complied
}

unittest
{
  auto arr = [ 'd', 'e' ];
  ref auto addAndReturn(T)(ref T[] arr) {
auto a = arr[$-1];
return arr ~= ++a;
  }

  auto len2 = Sarr!int(arr);
  assert(len2.length == 2);

  auto len4 = Sarr!short(addAndReturn(arr)); // add 'f'
  assert(len4.length == 4);

  auto len8 = Sarr!byte(addAndReturn(arr));  // add'g'
  assert(len8.length == 8);
}
```

SDB@79