Re: "Error: function expected before (), not module *module* of type void

2018-09-22 Thread ag0aep6g via Digitalmars-d-learn

On 09/22/2018 04:51 AM, Samir wrote:
Thanks for your help, Adam!  Right after posting my question, I started 
reading this site:

https://www.tutorialspoint.com/d_programming/d_programming_modules.htm


Better read the original:

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


Re: "Error: function expected before (), not module *module* of type void

2018-09-21 Thread Samir via Digitalmars-d-learn
On Saturday, 22 September 2018 at 01:58:57 UTC, Adam D. Ruppe 
wrote:
You probably shouldn't name a module the same as a member 
anyway, and it should also have two names, like "module 
myproject.isprime;"


But the fix here is to just use the full name.

import isPrime;
void main() {
  isPrime.isPrime(x); // module_name.member_name
}

or change the import:

import isPrime : isPrime; // specify you want the same-named 
member



Both files are in the same directory. When compiling main.d,


When compiling, be sure to pass both modules to it, or use the 
dmd -i if on a new version.


dmd -i main.d

or

dmd main.d isPrime.d

main.d:(.text._Dmain[_Dmain]+0x83): undefined reference to 
`_D7isPrime3isPFiZb'


this likely means you forgot to compile in the isPrime module, 
so use the above dmd lines


Thanks for your help, Adam!  Right after posting my question, I 
started reading this site:

https://www.tutorialspoint.com/d_programming/d_programming_modules.htm

Based on that and your recommendation, here is what I ended up 
doing:
I changed the filename of isPrime.d to isprime.d and put that in 
the subdirectory func/:


func/isprime.d:
module func.isprime;
bool isPrime(int n) {
// check to see if n is prime
}

I then changed main.d to:
import func.isprime;
void main() {
isPrime(x);
}

Finally, per your suggestion, I compiled it using:
dmd -i main.d

Thanks again!


Re: "Error: function expected before (), not module *module* of type void

2018-09-21 Thread Adam D. Ruppe via Digitalmars-d-learn

On Saturday, 22 September 2018 at 01:51:33 UTC, Samir wrote:

main.d:
import isPrime;
void main() {
isPrime(x);
}


You probably shouldn't name a module the same as a member anyway, 
and it should also have two names, like "module 
myproject.isprime;"


But the fix here is to just use the full name.

import isPrime;
void main() {
  isPrime.isPrime(x); // module_name.member_name
}

or change the import:

import isPrime : isPrime; // specify you want the same-named 
member



Both files are in the same directory. When compiling main.d,


When compiling, be sure to pass both modules to it, or use the 
dmd -i if on a new version.


dmd -i main.d

or

dmd main.d isPrime.d

main.d:(.text._Dmain[_Dmain]+0x83): undefined reference to 
`_D7isPrime3isPFiZb'


this likely means you forgot to compile in the isPrime module, so 
use the above dmd lines


Re: "Error: function expected before (), not module *module* of type void

2018-09-21 Thread Samir via Digitalmars-d-learn
On Monday, 24 March 2008 at 17:41:11 UTC, Steven Schveighoffer 
wrote:
I know you fixed the problem, but just an FYI, the reason is 
because when you import rollDice, you bring both rollDice the 
module and rollDice the function into the global namespace 
(which confuses the compiler 'cause it doesn't know what symbol 
you want to use).  This is normally avoided in libraries by 
having a package tree.  So for example, if you created 
everything in the subdirectory foo, and had your modules be:


module foo.diceroller;
import foo.rollDice;

Then the import would import the module foo.rollDice, and the 
function rollDice, and the compiler would no longer be confused 
about what you are trying to call.


IMO, this makes it difficult to write multi-file applications 
that live in one directory.  It would be nice if this was 
changed...


-Steve


I know this thread is quite old but I still seem to be getting a 
similar error and don't understand how to resolve it. I currently 
have a program isPrime.d that I would like to reuse in other 
programs:


isPrime.d:
bool isPrime(int n) {
// logic to check if n is prime
}

main.d:
import isPrime;
void main() {
isPrime(x);
}

Both files are in the same directory. When compiling main.d, I 
get:
Error: function expected before (), not module isPrime of type 
void


I've tried changing the name of the function isPrime in isPrime.d 
to something else (as well as changing the name in the main 
program) but then I get an error similar to:

In function `_Dmain':
main.d:(.text._Dmain[_Dmain]+0x83): undefined reference to 
`_D7isPrime3isPFiZb'

collect2: error: ld returned 1 exit status
Error: linker exited with status 1

Thanks in advance.