Re: [RFH - Tcl/Tk] use of procedure before declaration?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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



[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]