Public Access of Namespaced Identifiers

General FreeBASIC programming questions.
Munair
Posts: 374
Joined: Oct 19, 2017 15:00
Location: 't Zand, NL
Contact:

Public Access of Namespaced Identifiers

Postby Munair » Nov 14, 2017 15:25

I was wondering, is it possible to make identifiers in a namespace public? I tried a few things but I get compiler errors. The idea is this:

Code: Select all

namespace main
   extern foo as integer
   dim foo as integer
   ' or
   public foo as integer
end namespace

foo = 10
print foo
end

This way one could make Module members public or keep them private. I know, it could be sort of simulated by creating a type (with a name related to the module) but that would be more like a class rather than a module.
D.J.Peters
Posts: 7191
Joined: May 28, 2005 3:28

Re: Public Access of Namespaced Identifiers

Postby D.J.Peters » Nov 14, 2017 16:53

A namespace is primary to group things to gether or sepperate things from global module (name)space.

print mynamespace.mygroup.mything
mynamespace.mygroup.mything = 1

looks like you mean something this:
using mynamespace.mygroup
print mything
mything = 1

Joshy
Munair
Posts: 374
Joined: Oct 19, 2017 15:00
Location: 't Zand, NL
Contact:

Re: Public Access of Namespaced Identifiers

Postby Munair » Nov 14, 2017 19:02

D.J.Peters wrote:A namespace is primary to group things to gether or sepperate things from global module (name)space.

print mynamespace.mygroup.mything
mynamespace.mygroup.mything = 1

looks like you mean something this:
using mynamespace.mygroup
print mything
mything = 1

Joshy

No, I really mean the possibility for identifiers to be used cross-module explicitely with or without their namespace prefix, and even to keep identifiers private, meaning they cannot be used cross-module, something like this:

Code: Select all

namespace module1

' cannot be used cross module (implicit)
[private] dim HideMe as integer = 1
[private] dim HideMeToo as integer = 2

' can be used cross module but only with module prefix (explicit)
protected const MyName = "module1"

' can be used everywhere without module prefix (explicit)
declare public function ShowMe() as integer

public function ShowMe() as integer
  return HideMe + HideMeToo
end function

end namespace

This way a namespace would be very much like an object, but without instantiation, constructors etc. There would also be no need to 'dim share' or 'extern' an identifier to give it global scope.

Return to “General”

Who is online

Users browsing this forum: Bing [Bot] and 3 guests