When defining (in a roxen modue) a function
private void Check(int time) { bla, bla, bla int newTime = time(1); more bla bla }
trying to call the function time(1) (to get the time) results in an error: Calling non function value. Renaming the method parameter to tme 'solves' the problem.
FAFAIK this is strange behaviour, or is it?
Greetings Coen
__________________________________________________________ Deze e-mail en de inhoud is vertrouwelijk en uitsluitend bestemd voor de geadresseerde(n). Indien u niet de geadresseerde bent van deze e-mail verzoeken wij u dit direct door te geven aan de verzender door middel van een reply e-mail en de ontvangen e-mail uit uw systemen te verwijderen. Als u geen geadresseerde bent, is het niet toegestaan om kennis te nemen van de inhoud, deze te kopieren, te verspreiden, bekend te maken aan derden noch anderszins te gebruiken.
The information contained in this e-mail is confidential and may be legally privileged. It is intended solely for the addressee. If you are not the intended recipient, any disclosure, copying, distribution or any action taken or omitted to be taken in reliance on it, is prohibited and may be unlawful. Please notify us immediately if you have received it in error by reply e-mail and then delete this message from your system. __________________________________________________________
On Thu, 15 May 2008 14:33:18 -0000, cschalkwijk coen.schalkwijk@rtl.nl wrote:
When defining (in a roxen modue) a function
private void Check(int time) { bla, bla, bla int newTime = time(1); more bla bla }
trying to call the function time(1) (to get the time) results in an error: Calling non function value. Renaming the method parameter to tme 'solves' the problem.
FAFAIK this is strange behaviour, or is it?
Greetings Coen
The only strange thing is that the call to 'time(1)' should issue a type violation message. Other than that, it is the same as the following C code:
#include <stdio.h> #include <time.h>
void bla(time_t(*time)(time_t*)) { printf("%d\n",time(0)); }
int main(int argc,char** argv) { bla(0); }
I really do prefer programming languages where arguments and local variables cannot override global identifiers. I want my PL to protect me from much mistakes.
Bernd
If local identifiers couldn't override global, you would not be able to add any global identifiers without breaking existing code. => dead language.
On Sat, 17 May 2008 18:10:03 +0200, Marcus Comstedt (ACROSS) (Hail Ilpalazzo!) @ Pike (-) developers forum 10353@lyskom.lysator.liu.se wrote:
If local identifiers couldn't override global, you would not be able to add any global identifiers without breaking existing code. => dead language.
Sorry Sir, but I must object: If you are able to add new global identifiers within the same class, you are able to change the signature of existing ones. If you are able to add global identifiers in the subtype, you are able to redefine the signature of existing ones.
It is all a matter of namespace management through inheritance. I have to admit, it requires a more complicated approach to inheritance and the decoupling to names and methods.
I think there is a sematical confusion here. "global identifiers" are those which are not (conceptually at least) part of any class. Like "time" for example. Or "MIME", or "Protocols". Adding a new global identifer (by adding a new module, for example) does not change the signature of any existing classes.
Hi Marcus,
I think the confusion is not on semantics, but on the discussion level. I have absolutely no doubt that it is impossible to disable override of global identifiers by local identifiers in Pike as it currently stands. I fully agree with your reservations that this would create huge software engineering problems.
On the other hand, I have now been a member of the ECMA standardization committee for Eiffel for the last 5 years, and this language does not allow local identifiers to have the same name as global identifiers. The language was designed around that with very different namespacing rules and renaming possibilities when compared to Pike. So I had to object to what I perceived as "over-generalization".
Bernd
Well, the context here is the language Pike, so please realize that when talking about "global identifiers", this refers to the Pike concept of global identifiers, unless otherwise specified. And I will assume that the same goes for when someone talks about classes and signatures.
You probably want to explore the #pragma strict_types.
pike test.pike test.pike:5: Warning: Unused local variable newTime. test.pike:5:Calling non function value. test.pike:5:Expected: function test.pike:5:Got : int Pike: Failed to compile script: Compilation failed.
why is it strange? you can't have both a variable and a function named time. when you create a local variable (or any other symbol) it overwrites the global one. you can still access the time() function by using predef::time();
greetings, martin.
Why is it strange?
private void Check(int time) ^^^^^^^^ ok, so in the scope of this function "time" is an actual parameter of type int.
{ bla, bla, bla int newTime = time(1); ^^^^^ here, you try to call "time", which is an actual parameter of type int. ints can't be called, so you get an error more bla bla }
pike-devel@lists.lysator.liu.se