• Import ::json::json2dict does not work

    From Cecil Westerhof@21:1/5 to All on Thu Mar 9 19:02:25 2023
    When i do interactively:
    package require json

    It responds with:
    1.3.4

    I then do:
    namespace import ::json::json2dict

    But the command json2dict is not available after that.
    Am I doing something wrong?

    --
    Cecil Westerhof
    Senior Software Engineer
    LinkedIn: http://www.linkedin.com/in/cecilwesterhof

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Peter Dean@21:1/5 to Cecil Westerhof on Fri Mar 10 05:43:50 2023
    On 10/3/23 04:02, Cecil Westerhof wrote:
    When i do interactively:
    package require json

    It responds with:
    1.3.4

    I then do:
    namespace import ::json::json2dict

    But the command json2dict is not available after that.
    Am I doing something wrong?

    json2dict isn't exported by the library.

    man n namespace

    "All the commands that match a pattern string and which are currently exported from their namespace are added to the current namespace. "

    pd

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Cecil Westerhof@21:1/5 to Peter Dean on Thu Mar 9 21:56:46 2023
    Peter Dean <[email protected]> writes:

    On 10/3/23 04:02, Cecil Westerhof wrote:
    When i do interactively:
    package require json
    It responds with:
    1.3.4
    I then do:
    namespace import ::json::json2dict
    But the command json2dict is not available after that.
    Am I doing something wrong?

    json2dict isn't exported by the library.

    Of-course. That is what I do in my package. But if it is not done,
    then it will not work.

    I would have expected that an import that imports nothing would be an
    error, but that is only my way of thinking.

    --
    Cecil Westerhof
    Senior Software Engineer
    LinkedIn: http://www.linkedin.com/in/cecilwesterhof

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Rich@21:1/5 to Cecil Westerhof on Thu Mar 9 23:36:54 2023
    Cecil Westerhof <[email protected]> wrote:
    Peter Dean <[email protected]> writes:

    On 10/3/23 04:02, Cecil Westerhof wrote:
    When i do interactively:
    package require json
    It responds with:
    1.3.4
    I then do:
    namespace import ::json::json2dict
    But the command json2dict is not available after that.
    Am I doing something wrong?

    json2dict isn't exported by the library.

    Of-course. That is what I do in my package. But if it is not done,
    then it will not work.

    I would have expected that an import that imports nothing would be an
    error, but that is only my way of thinking.

    The manpage does not define what happens when there are no matching
    exports. So a no error situation is one possible outcome.

    Since json does not export anything, and presumably you want to have
    the effect of an 'import', you can use an interp alias to achieve
    "import like" semantics:

    % interp alias {} json2dict {} ::json::json2dict

    And you'll have a "json2dict" command that calls the namespaced
    command.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Peter Dean@21:1/5 to Rich on Fri Mar 10 11:47:05 2023
    On 10/3/23 09:36, Rich wrote:
    Cecil Westerhof <[email protected]> wrote:
    Peter Dean <[email protected]> writes:

    On 10/3/23 04:02, Cecil Westerhof wrote:
    When i do interactively:
    package require json
    It responds with:
    1.3.4
    I then do:
    namespace import ::json::json2dict
    But the command json2dict is not available after that.
    Am I doing something wrong?

    json2dict isn't exported by the library.

    Of-course. That is what I do in my package. But if it is not done,
    then it will not work.

    I would have expected that an import that imports nothing would be an
    error, but that is only my way of thinking.

    The manpage does not define what happens when there are no matching
    exports. So a no error situation is one possible outcome.

    Since json does not export anything, and presumably you want to have
    the effect of an 'import', you can use an interp alias to achieve
    "import like" semantics:

    % interp alias {} json2dict {} ::json::json2dict

    And you'll have a "json2dict" command that calls the namespaced
    command.

    another way is to add to namespace path

    package require json
    % namespace path [list ::json ::tcl::mathop ::tcl::mathfunc]

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Cecil Westerhof@21:1/5 to Rich on Fri Mar 10 08:01:57 2023
    Rich <[email protected]d> writes:

    Cecil Westerhof <[email protected]> wrote:
    Peter Dean <[email protected]> writes:

    On 10/3/23 04:02, Cecil Westerhof wrote:
    When i do interactively:
    package require json
    It responds with:
    1.3.4
    I then do:
    namespace import ::json::json2dict
    But the command json2dict is not available after that.
    Am I doing something wrong?

    json2dict isn't exported by the library.

    Of-course. That is what I do in my package. But if it is not done,
    then it will not work.

    I would have expected that an import that imports nothing would be an
    error, but that is only my way of thinking.

    The manpage does not define what happens when there are no matching
    exports. So a no error situation is one possible outcome.

    Since json does not export anything, and presumably you want to have
    the effect of an 'import', you can use an interp alias to achieve
    "import like" semantics:

    % interp alias {} json2dict {} ::json::json2dict

    And you'll have a "json2dict" command that calls the namespaced
    command.

    At the moment I only call it once. So that is overkill I think.
    But when I will use it more often I will use it.

    --
    Cecil Westerhof
    Senior Software Engineer
    LinkedIn: http://www.linkedin.com/in/cecilwesterhof

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)