Kevin Glynn wrote: > David Hopwood writes: > > Torsten Anders wrote: > > > > Actually, when there is a variable you intent not to use (e.g. to comply > > > some given interface), you may just call it _. > > > > Erlang has a convention where variables that are intended to be unused have > > names starting with _ (including _ itself). The compiler warns only about > > non-use of variables that do not have a leading _. This is useful because > > the _ acts as documentation that the variable is not used, but has very low > > syntactic overhead. > > > > I like this convention much better than unconditionally warning about > unused > > variables. In code that I write, unused variables are not infrequent, but > > *almost* always occur only for code that is unfinished (and obviously so), > or > > for parameters that are intentionally not used by a particular > implementation > > of a function/procedure/method. > > Yes, I think this would be a good idea too, it is often good > documentation to give an unused var a name. I think Haskell does the > same.
It does: <http://hackage.haskell.org/trac/haskell-prime/wiki/Underscore> > However, we have the additional issue that in Oz '_' can be used > anywhere to introduce a fresh unbound variable. This is also true in Erlang (both being derived partly from Prolog). Note that the syntax of variable names (Table C.9 in CTM) would have to be changed to: <variable> ::= ['_'] (uppercase char) { (alphanumeric char) } (it could be ('_' | (uppercase char)) { (alphanumeric char) }, but I think that the character after the _ should still be uppercase for consistency). > So, > > - Is '_X' equivalent to writing '_' or is it just a variable name that > bypasses the unused var check (or even is it a variable that is > introduced wthout declaration)? It is just a variable name that bypasses the unused var check (and that gives a warning if used -- see below). In principle it could be introduced without declaration, but I think it is more consistent to have the same declaration rules as any other variable (the primary uses of these variables are for parameters and patterns; "local _Foo in ... end" would be legal but rare). '_' would remain equivalent to 'local X in X end' (with no warning if X happens to shadow another variable). > i.e., in (case Exp of _X then {F _X} end) are they different vars or > the same? The same, but this code would result in a warning because _X is used. > - Can one write ..... {F _X _X} where _X is not in scope and introduce > a fresh var? I recommend not. > I think _X should be a first class variable name that only bypasses > the unused var check. > > - Should the compiler warn when a variable starting with underscore > *is* used? > > I am undecided, but I lean to yes. I agree. This ensures that the documentation aspect of the name is consistent with whether the variable is actually used. -- David Hopwood <[EMAIL PROTECTED]> _________________________________________________________________________________ mozart-users mailing list [email protected] http://www.mozart-oz.org/mailman/listinfo/mozart-users
