Re: [RFH - Tcl/Tk] use of procedure before declaration?
- From
Philip Oakley <philipoakley@iee.org>
- Date
- Jan 17, 2017, 23:33 UTC
- Message-ID
- <826895153F394EB29B0D27F3EB9A67C9@PhilipOakley>
- In-Reply-To
- <alpine.DEB.2.20.1701171218260.3469@virtualbox>
From: "Johannes Schindelin" <Johannes.Schindelin@gmx.de>
Show 67 quoted lines
> Hi Philip,
>
> On Mon, 16 Jan 2017, Philip Oakley wrote:
>
>> In
>> https://github.com/git/git/blob/master/git-gui/lib/choose_repository.tcl#L242
>> the procedure `_unset_recentrepo` is called, however the procedure isn't
>> declared until line 248. My reading of the various Tcl tutorials suggest
>> (but not explictly) that this isn't the right way.
>
> Indeed, calling a procedure before it is declared sounds incorrect.
>
> Since documentation can be treacherous, let's just test it. With a `tclsh`
> whose `$tcl_version` variable claims that this is version 8.6, this
> script:
>
> ```tcl
> hello Philip
>
> proc hello {arg} {
> puts "Hi, $arg"
> }
> ```
>
> ... yields the error message:
>
> invalid command name "hello"
> while executing
> "hello Philip"
>
> ... while this script:
>
> ```tcl
> proc hello {arg} {
> puts "Hi, $arg"
> }
>
> hello Philip
> ```
>
> ... prints the expected "Hi, Philip".
>
> Having said that, in the code to which you linked, the procedure is not
> actually called before it is declared, as the call is inside another
> procedure.
>
> Indeed, the entire file declares one object-oriented class, so no code
> gets executed in that file:
>
> https://github.com/git/git/blob/d7dffce1c/git-gui/lib/choose_repository.tcl#L4
>
> (I guess proper indentation would make it easier to understand that this
> file is defining a class, not executing anything yet).
>
> And it is perfectly legitimate to use not-yet-declared procedures in other
> procedures, otherwise recursion would not work.
>
>> Should 3c6a287 ("git-gui: Keep repo_config(gui.recentrepos) and
>> .gitconfig
>> in sync", 2010-01-23) have declared `proc _unset_recentrepo {p}` before
>> `proc _get_recentrepos {}` ?
>
> Given the findings above, I believe that the patch is actually correct.
>
> Ciao,
> Dscho
>Thanks for the clarification. I'll update the old patch series and see if we can get this fixed.
Philip