Re: Running LDC on a recent MacOS

2023-06-16 Thread Dave P. via Digitalmars-d-learn

On Friday, 16 June 2023 at 16:25:35 UTC, Dmitry Olshansky wrote:
On Friday, 16 June 2023 at 16:14:19 UTC, Steven Schveighoffer 
wrote:

On 6/16/23 11:56 AM, Dmitry Olshansky wrote:


Any advice from MacOS users?


Yep.

Go into settings, then privacy and security. Make sure "App 
store and identified developers" is checked.


On that page, you will see probably a thing saying "you tried 
to run ldc2 but I blocked it". Say "allow anyway".


Then try it again. This time, it will still block it, but ask 
you if you want to run it.


Yes, thanks that did the trick!



-Steve


That process is too annoying to me. I usually just remove the 
quarantine attribute instead.


```bash
$ xattr -r -d com.apple.quarantine 
ldc2-1.33.0-beta2-osx-universal.tar.xz

```


Re: Running LDC on a recent MacOS

2023-06-16 Thread Dmitry Olshansky via Digitalmars-d-learn
On Friday, 16 June 2023 at 16:14:19 UTC, Steven Schveighoffer 
wrote:

On 6/16/23 11:56 AM, Dmitry Olshansky wrote:


Any advice from MacOS users?


Yep.

Go into settings, then privacy and security. Make sure "App 
store and identified developers" is checked.


On that page, you will see probably a thing saying "you tried 
to run ldc2 but I blocked it". Say "allow anyway".


Then try it again. This time, it will still block it, but ask 
you if you want to run it.


Yes, thanks that did the trick!



-Steve





Re: Running LDC on a recent MacOS

2023-06-16 Thread Steven Schveighoffer via Digitalmars-d-learn

On 6/16/23 11:56 AM, Dmitry Olshansky wrote:
So I've got my hands on one of 'em MacPros. Great machine, nice build 
quality.


Next order of business is to run D on the box, so I've downloaded 
universal binaries off ldc's release page. When I try to run any of the 
binaries nasty message box comes out to tell me it doesn't recognise the 
author of the binary. Any attempt to bypass the message turns to failure 
for me.


Any advice from MacOS users?


Yep.

Go into settings, then privacy and security. Make sure "App store and 
identified developers" is checked.


On that page, you will see probably a thing saying "you tried to run 
ldc2 but I blocked it". Say "allow anyway".


Then try it again. This time, it will still block it, but ask you if you 
want to run it.


-Steve


Re: Private nested class instance accessed via outer class public interface

2023-06-16 Thread Anonymouse via Digitalmars-d-learn

On Friday, 16 June 2023 at 07:47:50 UTC, Murloc wrote:
And since classes can be declared locally inside methods, you 
can also do something similar this way:


```d
import std.stdio;
import std.conv;

Object getB() {
class B {
private int field = 30;
override string toString() => to!string(field);
}
return cast(Object)new B();
}

void main() {
auto b = getB();
writeln(b); // 30
}
```


This isn't fully playing to its strengths either, there's no need 
to cast it to Object if you declare the return type to be `auto`.


```
import std.stdio;
import std.conv;

auto getB() {
class B {
private int field = 30;
override string toString() => to!string(field);
}
return new B();
}

void main() {
auto b = getB();
writeln(b); // 30
}
```

I use it a lot like so:

```
import std;

auto getThing()
{
struct Thing
{
int x, y;
double weight;
int fluffiness;
}

Thing thing;
thing.x = 42;
thing.y = 128;
thing.weight = 99.9;
thing.fluffiness = 9001;
return thing;
}

void main()
{
//Thing thing;  // Unidentified identifier Thing
auto thing = getThing();
writeln(typeof(thing).stringof);  // Thing
writeln(thing);  // Thing(42, 128, 99.9, 9001)
}
```

https://wiki.dlang.org/Voldemort_types


Re: Private nested class instance accessed via outer class public interface

2023-06-16 Thread Murloc via Digitalmars-d-learn
On Friday, 16 June 2023 at 07:54:21 UTC, Richard (Rikki) Andrew 
Cattermole wrote:

Also we have a Discord server which you are welcome to join!

https://discord.gg/bMZk9Q4


Thanks for the invitation. However, I don't like Discord so I 
don't use it :)


Re: Private nested class instance accessed via outer class public interface

2023-06-16 Thread Richard (Rikki) Andrew Cattermole via Digitalmars-d-learn

Yes that is to be expected.

Also we have a Discord server which you are welcome to join!

https://discord.gg/bMZk9Q4


Re: Private nested class instance accessed via outer class public interface

2023-06-16 Thread Murloc via Digitalmars-d-learn
And since classes can be declared locally inside methods, you can 
also do something similar this way:


```d
import std.stdio;
import std.conv;

Object getB() {
class B {
private int field = 30;
override string toString() => to!string(field);
}
return cast(Object)new B();
}

void main() {
auto b = getB();
writeln(b); // 30
}
```


Private nested class instance accessed via outer class public interface

2023-06-16 Thread Murloc via Digitalmars-d-learn
I'm not sure if this behavior is desired and have any use-cases 
(should I report it as a bug?), but, for example, C# doesn't 
allow this.


```d
import std.conv;

class Outer {
private static class Inner {
private int field = 30;
override string toString() => to!string(field);
}
static Inner getInner() {
return new Inner();
}
}
```

```d
import std.stdio: writeln;
import classes; // the file above

void main() {
// Here I have an object of "some" type (B class cannot be
// accessed) and can even do something with it!
auto b = Outer.getInner();
writeln(b); // 30
}
```

Same program in C# (private members are accessible only within 
their class):

```c#
using System;

public class Program {
class Outer {
private class Inner {
private int field = 30;
public override string ToString() => field.ToString();
}
// Error: Inconsistent accessibility: return type 
'Program.Outer.Inner'
// is less accessible than method 
'Program.Outer.getInner()'

public static Inner getInner() {
return new Inner();
}
}

public static void Main() {
var b = Outer.getInner();
Console.WriteLine(b);
}
}
```


Private nested class instance accessed via outer class public interface

2023-06-16 Thread Murloc via Digitalmars-d-learn
I'm not sure if this behavior is desired and have any use-cases 
(should I report it as a bug?), but, for example, C# doesn't 
allow this.


```d
import std.conv;

class Outer {
private static class Inner {
private int field = 30;
override string toString() => to!string(field);
}
static Inner getInner() {
return new Inner();
}
}
```

```d
import std.stdio: writeln;
import classes; // the file above

void main() {
// Here I have an object of "some" type (B class cannot be
// accessed) and can even do something with it!
auto b = Outer.getInner();
writeln(b); // 30
}
```

Same program in C# (private members are accessible only within 
their class):

```c#
using System;

public class Program {
class Outer {
private class Inner {
private int field = 30;
public override string ToString() => field.ToString();
}
// Error: Inconsistent accessibility: return type 
'Program.Outer.Inner'
// is less accessible than method 
'Program.Outer.getInner()'

public static Inner getInner() {
return new Inner();
}
}

public static void Main() {
var b = Outer.getInner();
Console.WriteLine(b);
}
}
```


Re: GDC Compilation wtih Directory Present

2023-06-16 Thread Mike Parker via Digitalmars-d-learn

On Friday, 16 June 2023 at 06:38:17 UTC, Murloc wrote:



Thanks! That works well. I thought that `module pack.file1` is 
implicitly there by default :')


The compiler will use the file name as a default module name if 
you don't provide one, but that's *just* the module name. It 
doesn't take into account any directories for package names.


Re: GDC Compilation wtih Directory Present

2023-06-16 Thread Murloc via Digitalmars-d-learn
On Friday, 16 June 2023 at 06:32:21 UTC, Richard (Rikki) Andrew 
Cattermole wrote:

On 16/06/2023 6:26 PM, Murloc wrote:
Don't you need to provide a full path to these files 
relatively to the directory where the compilation process 
takes place (Test)?


Yes.

But I suspect you have not written the module statement, which 
is required.


```d
module pack.file1;

// file1.d
void printlnValueInFile2() {
 import std.stdio: writeln;
 import pack.file2: value;

 writeln(value);
}
```

```d
module pack.file2;

package(pack) int value = -120;
```

Its also a good habit to write the package attribute with 
explicit package(s).


Thanks! That works well. I thought that `module pack.file1` is 
implicitly there by default :')


Re: GDC Compilation wtih Directory Present

2023-06-16 Thread Richard (Rikki) Andrew Cattermole via Digitalmars-d-learn

On 16/06/2023 6:26 PM, Murloc wrote:
Don't you need to provide a full path to these files relatively to the 
directory where the compilation process takes place (Test)?


Yes.

But I suspect you have not written the module statement, which is required.

```d
module pack.file1;

// file1.d
void printlnValueInFile2() {
 import std.stdio: writeln;
 import pack.file2: value;

 writeln(value);
}
```

```d
module pack.file2;

package(pack) int value = -120;
```

Its also a good habit to write the package attribute with explicit 
package(s).


GDC Compilation wtih Directory Present

2023-06-16 Thread Murloc via Digitalmars-d-learn

My project structure is the following:

```
Test
|
+-- pack
|   |
|   +-- file1.d
|   |
|   +-- file2.d
|
+-- program.d
```

And here is the code inside these files:

```d
// file2.d
package int value = -120;
```

```d
// file1.d
void printlnValueInFile2() {
import std.stdio: writeln;
import pack.file2: value;

writeln(value);
}
```

```d
// program.d
void main() {
   import pack.file1;

   printlnValueInFile2(); // -120 expected
}
```

From the directory Test when I'm trying to compile the project 
with command
`gdc -o program program.d pack/file1.d pack/file2.d`, it produces 
3 errors with the following messages:


- module `file1` from file `pack/file1.d` must be imported with 
'`import file1;`' (instead of '`import pack.file1`')
- module `file2` from file `pack/file2.d` must be imported with 
'`import file2;`' (instead of '`import pack.file2`')


Don't you need to provide a full path to these files relatively 
to the directory where the compilation process takes place (Test)?


- module `file2` member '`value`' is not visible from module 
'`file1`' (however, both files are in the same directory)