Re: Error when using `import`.

2024-02-24 Thread Paul Backus via Digitalmars-d-learn
On Saturday, 24 February 2024 at 10:31:06 UTC, Liam McGillivray 
wrote:


`Unit.d` & `Map.d` are longer files. `Map.d` begins with 
`import Tile;`, and `Unit.d` begins with `import Map;`.


Why are the errors happening? What's the problem? Why is it 
`currentclass.importedclass` instead of simply the imported 
class?


You can't give a class the same name as the file it's in. If you 
do, then when you try to use it from another file, the compiler 
will get confused and think you're referring to the file instead 
of the class (that's what "import is used as a type" means).


The easiest way around this is to change the name of the file to 
lower case. So, for example, you could change the name of the 
file with the `Unit` class in it to `unit.d`, and then write 
`import unit;` to access it from your other files.


Re: Searching for i" in the forum

2024-02-24 Thread Lysander via Digitalmars-d-learn

On Friday, 23 February 2024 at 23:18:12 UTC, kdevel wrote:

How do I search for

   i"

in the forum? I get the following errors:

   i" -> Error: malformed MATCH expression: [i"] (1)
   i\" -> Error: malformed MATCH expression: [i\"] (1)
   'i"' -> Error: malformed MATCH expression: ['i"'] (1)
   `i"` -> Error: malformed MATCH expression: [`i"`] (1)
   "i\"" -> Error: malformed MATCH expression: ["i\""] (1)


Use the i\" in the exact phrase box from the advanced search.
Advanced search button is on the error page from the malformed 
match search


Re: Error when using `import`.

2024-02-24 Thread Richard (Rikki) Andrew Cattermole via Digitalmars-d-learn



On 24/02/2024 11:51 PM, Liam McGillivray wrote:
On Saturday, 24 February 2024 at 10:34:25 UTC, Richard (Rikki) Andrew 
Cattermole wrote:

A few things.

Module names should be lower case.


I capitalised the first letter in the class names so that I can make 
instances of them in lowercase. Should I rename the classes, modules, 
and filenames to all be lowercase?


It appears to be solved now after adding module declarations to the 
beginning of each file in all-lowercase. This is despite the classes and 
the class names still being capitalized. I'm still getting errors, but 
they appear to be unrelated.


Thank you.


As far as naming goes, the recommendations from the D style guidelines 
are quite good.


https://dlang.org/dstyle.html

However I suspect that you are treating module names as symbols, and 
while this is the case it can be done, you should avoid doing that until 
you understand the basics.


https://ddili.org/ders/d.en/modules.html


Re: Error when using `import`.

2024-02-24 Thread Liam McGillivray via Digitalmars-d-learn
On Saturday, 24 February 2024 at 10:34:25 UTC, Richard (Rikki) 
Andrew Cattermole wrote:

A few things.

Module names should be lower case.


I capitalised the first letter in the class names so that I can 
make instances of them in lowercase. Should I rename the classes, 
modules, and filenames to all be lowercase?


It appears to be solved now after adding module declarations to 
the beginning of each file in all-lowercase. This is despite the 
classes and the class names still being capitalized. I'm still 
getting errors, but they appear to be unrelated.


Thank you.


Re: Error when using `import`.

2024-02-24 Thread Richard (Rikki) Andrew Cattermole via Digitalmars-d-learn

A few things.

Module names should be lower case.

Each file, needs the full module declaration.


source/foo/bar.d:

```d

module foo.bar;

```


source/app.d:

```d

module app;

import foo.bar;

```


Directories matter, this allows the import path search (via the use of 
the -I switch) to locate modules based upon the filename relative to the 
directory in the search.





Error when using `import`.

2024-02-24 Thread Liam McGillivray via Digitalmars-d-learn
I am trying to make a tactical role-playing game which I am 
likely to open-source. Right now the code is very simple, with 
only 3 files each containing a class with the same name.


The files are `Map.d`, `Tile.d`, and `Unit.d`. Each of these 
files contains an `import` line to access one of the others. I 
got the following errors when trying to compile all 3 files with 
DMD, and the same errors after switching to DUB.


```
source/Unit.d(6,17): Error: import `Unit.Map` is used as a type
source/Unit.d(16,5): Error: import `Unit.Map` is used as a type
source/Tile.d(9,15): Error: import `Tile.Unit` is used as a type
source/Map.d(6,22): Error: import `Map.Tile` is used as a type
source/Map.d(19,11): Error: import `Map.Tile` is used as a type
```

I thought that the circular chain of imports may be the problem, 
but removing all references to `Unit` in `Tile.d` did not fix the 
problem.


Here are the contents of Tile.d:
```
import Unit;

class Tile
{
private bool allowStand = true;
private bool allowFly = true;
public int stickyness = 0;

public Unit* occupant;

bool allowUnit(bool isFlyer) {
if (isFlyer) return this.allowFly;
else return this.allowStand;
}
}
```

`Unit.d` & `Map.d` are longer files. `Map.d` begins with `import 
Tile;`, and `Unit.d` begins with `import Map;`.


Why are the errors happening? What's the problem? Why is it 
`currentclass.importedclass` instead of simply the imported class?