functions – How are the variables of the `Private` package accessible?

Then how my function know the value of ABC during the deferred function call (when called) if the Private` the context is not about the $ ContextPath

There is a misunderstanding here. You suppose that ABC is sought in a certain context only when my function[something] is evaluated. This is not the case.

$ Background and $ ContextPath only affects how the source code is analysis (not how expressions are evaluated). In other words, they only affect how the text you write in the package file is interpreted and converted to expressions in memory. Once the package is loaded with Getthis interpretation has already taken place. my function has been interpreted as the symbol CustomPackage`MyFunction and ABC has been interpreted as CustomPackage`Private`abc, depending on the value of $ Background and $ ContextPath at the moment everyone was read. These are the full names of these symbols and it is so that they exist in memory.

Load the package and try this:


You will see the following printed:

CustomPackage`MyFunction[CustomPackage`Private`arg1_] : =
CustomPackage`Private`arg1 + CustomPackage`Private`abc

As you can see, a context is always associated with each symbol.