[ nice-Bugs-798312 ] local function param namespace
"SourceForge.net" <[email protected]>
| Newsgroups | gmane.comp.lang.nice.devel |
|---|---|
| Message-ID | <[email protected]> |
Bugs item #798312, was opened at 2003-08-31 16:37
Message generated for change (Comment added) made by igouy
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=112788&aid=798312&group_id=12788
Category: None
Group: None
Status: Open
Resolution: None
Priority: 5
Submitted By: Isaac Gouy (igouy)
Assigned to: Nobody/Anonymous (nobody)
Summary: local function param namespace
Initial Comment:
My guess is that this is a feature request?
These comments refer to the code in
WordfreqIntermediateExample.
I made the formatLine package function a local function
(mainly so I could reuse the StringBuffer) and
discovered that the parameter name 'word' clashed with
the variable name 'word'. Of course, we can rename the
parameter in some arbitrary way like 'wordX' (although
the keyword parameters mean that's not so good and
perhaps we need to go back and rename the local
var...).
void main(String[] args){
var String word;
...
String formatLine(String wordX, Cell count){
...
buffer.append(wordX);
...
}
... formatLine(wordX: e.getKey(), count: e.getValue())
}
----------------------------------------------------------------------
>Comment By: Isaac Gouy (igouy)
Date: 2003-09-01 08:33
Message:
Logged In: YES
user_id=536291
> more important to show different aspects of Nice
I agree! And its important to show a practical style.
> redeclaration of local variables is not allowed
Let me step through what surprises me:
This compiles:
void main1(String[] args){
void F(String word){}
var String word;
}
but this doesn't:
void main2(String[] args){
var String word;
void F(String word){}
}
\test\t.nice: line 3, column 23:
Symbol word is already defined.
Previous definition: \test\t.nice: line 2, column 15
1) I hadn't realized declaration order mattered
void main3(String[] args){
word = "test";
void F(String word){}
}
\test\t.nice: line 2, column 4:
word is not declared
2) It seems that the parameter of functional F doesn't exist
beyond the scope of F. So the name clash of main3 is
surprising to me. (And of course I don't experience that name
clash in other languages.)
void main4(String[] args){
word = "test";
void F(){ var String word; }
}
\test\t.nice: line 2, column 4:
word is not declared
void main5(String[] args){
var String word;
void F(){ var String word; }
}
\test\t.nice: line 3, column 25:
Symbol word is already defined.
Previous definition: \test\t.nice: line 2, column 15
3) Same as #2 but with a variable local to F.
Given that the param and var are local to F, I only "expect"
that they will have name clashes in that local scope.
Aside from the bad 'surprise', the main consequence is more
debug/editing when a function is moved, and a 'forced'
arbitrary naming of vars and params to get around the name
clash (rather than express intent).
Nice compiler version 0.9.2 (build 2003.09.01, 08:24:05 UTC)
----------------------------------------------------------------------
Comment By: Arjan Boeijink (arjanb)
Date: 2003-09-01 05:30
Message:
Logged In: YES
user_id=688815
This is not a bug, redeclaration of local variables is not
allowed because it mostly indicates an error or bad code
practise.
BTW I changed the code in that example because it
contained to much optimization tricks. I know the code comes
form a benchmark but I think it's more important to show
different aspects of Nice than showing how to squeeze out a
few percent more perfomance.
----------------------------------------------------------------------
Comment By: Daniel Bonniot (bonniot)
Date: 2003-09-01 01:27
Message:
Logged In: YES
user_id=88952
Idem, please submit something we can copy paste and compile
(without "..."). It's also good if you can remove irrelevant
parts, so the code is as short as possible.
It's also not clear from your message was is the bug (you
seem to have to identifiers with the same name, isn't a
"clash" expected?), or what feature you request.
----------------------------------------------------------------------
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=112788&aid=798312&group_id=12788
-------------------------------------------------------
This sf.net email is sponsored by:ThinkGeek
Welcome to geek heaven.
http://thinkgeek.com/sf