Thanks Paul, you channelled my thinking exactly correctly. I am not an expert on C++, but I think that's roughly how C++ namespaces work. Any C++ coders care to confirm or correct me? Steve On Wed, May 05, 2021 at 12:05:56PM +0100, Paul Moore wrote:
On Wed, 5 May 2021 at 11:33, Matt del Valle
wrote: To give an example:
def spam(): return "spam spam spam!"
def eggs(): return spam()
namespace Shop: def spam(): return "There's not much call for spam here." def eggs(): return spam()
print(eggs()) # should print "spam spam spam!" print(Shop.eggs()) # should print "There's not much call for spam here."
I'm guessing this was a typo and you meant to type:
print(spam()) # should print "spam spam spam!" print(Shop.spam()) # should print "There's not much call for spam here."
Because if you did, then this is precisely how it would work under this proposal. :)
I'm not the OP, but I read their question precisely as it was written. The global eggs() returns the value from calling spam() and should use the *global* spam. The eggs in namespace Shop calls spam and returns its value, and I'd expect that call to resolve to Shop.spam, using the namespace eggs is defined in. If that's not how you imagine namespaces working, I think they are going to be quite non-intuitive for at least a certain set of users (including me...)
Paul