|
Joined: Jun 2003
Posts: 6
Nutrimatic drinks dispenser
|
OP
Nutrimatic drinks dispenser
Joined: Jun 2003
Posts: 6 |
global declareation of variables outside of scripts
example;
var %t = 7 on *:signal:test:{ echo 4 -a variable t is %t }
|
|
|
|
Joined: Jun 2003
Posts: 114
Vogon poet
|
Vogon poet
Joined: Jun 2003
Posts: 114 |
All variables in mIRC are global... so... thats pretty pointless. mIRC doesn't run through each script like C++ does. You'd have to use like, on start to declare a variable before a script runs.
------------- I am the self-appointed God of needlessly complex mIRCscript.
|
|
|
|
Joined: Dec 2002
Posts: 2,809
Hoopy frood
|
Hoopy frood
Joined: Dec 2002
Posts: 2,809 |
All variables are NOT global in mIRC. /var is local, /set is global. However I agree that ON START is the way it should be done, at least in mIRC.
|
|
|
|
Joined: Apr 2003
Posts: 210
Fjord artisan
|
Fjord artisan
Joined: Apr 2003
Posts: 210 |
variables set with /var are local variables only accessible in the routine in which they were set. Only variables defined with /set are global.
Set would be more appropriate than /var for this feature. Also this feature could work. The parser would just scan the script for lines beginning with SET, just like it scans for ALIAS, RAW, etc etc.
Although I personally don't see any use for it, Maybe the poster can elaborate on it's potential uses.
|
|
|
|
Joined: Dec 2002
Posts: 32
Ameglian cow
|
Ameglian cow
Joined: Dec 2002
Posts: 32 |
I agree I personally like the simplicity of the scope of defined variables in mirc. set is global and exsists always and var is for program flow. I think one of the major hinderences of C and C++ is the complexity of variable declaration and scope.
It's only called insanity if you're poor. I stay alive to spite those that wish me dead.
|
|
|
|
Joined: Feb 2003
Posts: 2,812
Hoopy frood
|
Hoopy frood
Joined: Feb 2003
Posts: 2,812 |
Actually, I'd like to rephrase this suggestion, as I think it's a good idea...
declaration of constants localized to the scope of the script.
example;
const %t = 7 on *:signal:test:{ echo 4 -a constant t is %t }
This would be useful for script specific settings, without having to store global variables that are accessible to all loaded scripts, and vulnerable to /unsetall.
It would be nice if you could declare a bunch of %constants that would be accessible to all events and aliases, but inside that script alone. You would be able to modify the value of a %constant the same way you normally would with %var = value.
Constants would fit into the access priority as follows:
Local Variables, declared by /var command. Local Constants, declared by /const command. Global Variables, declared by /set command.
If you declared a Variable with /set, then all events/aliases in all scripts have access to it. If you declare a like-named Constant with /const, then events/aliases in that script alone would have access to it instead of the Set Variable. If you declared a like-named Variable with /var, then that event or alias alone would have access to it instead of the Const or Set Variable.
Does this make any more sense, or win any more favor?
The only downside to this, is that the script file would be in constant modification whenever a %const value is changed, and possibly make the file more prone to corruption in the event of a power failure. This presently holds true if you use #groups (/enable,/disable) in a script.
- Raccoon
Well. At least I won lunch. Good philosophy, see good in bad, I like!
|
|
|
|
Joined: Dec 2002
Posts: 2,809
Hoopy frood
|
Hoopy frood
Joined: Dec 2002
Posts: 2,809 |
You would be able to modify the value of a %constant the same way you normally would with %var = value. Umm well to say that makes it sound like you don't know what a constant is. A constant is something that does and and can not be changed. So if your idea is script scope variables, I already suggested that a long time ago. If your suggesting constants, well then constants can't be modified.
|
|
|
|
Joined: Feb 2003
Posts: 2,812
Hoopy frood
|
Hoopy frood
Joined: Feb 2003
Posts: 2,812 |
Well, considering that mIRC doesn't actually compile, there'd really be no point in prohibiting the value from being changed. I suppose you could call it a Script Scope Variable, but most people can relate to the term Constant, and it can be used as such for all intents and purposes (unless they choose to modify the value, which is up to them.)
But yes, I understand the dictionary definition of the word Constant. I guess my problem stems from the fact that science has both proven and refuses to accept the fact that there are no constants in the universe but that EVERYTHING is relative, including the speed of light (which has been proven variable).
- Raccoon
Well. At least I won lunch. Good philosophy, see good in bad, I like!
|
|
|
|
Joined: Dec 2002
Posts: 2,809
Hoopy frood
|
Hoopy frood
Joined: Dec 2002
Posts: 2,809 |
There are constants, it's just a matter of whether you are willing to accept them. Yes the speed of light is relative, thats been theorized for about 80 years. But there are other constants that are still recognized and no one has managed to come up with anything to disprove them, the that quickly come to mind are the Planck Constant and Hubble's Constant. For the purpose of not boring the forum readers who hate physics, I won't explain what those are, but those and other constants are recognized as existing. Oh and btw, the whole speed of light is relative thing, well thats really an insignifigant discovery in and of itself. It's the implications of that finding that are important, such as the fact that it leads to the relativity of time.
But anyway, thats irrelevant. The word constant and the appreviation const refer to without change. The word variable, and the appreviation var refer to having variation, or with change. They are exact opposites. For the sake of correctness, you should not call something a constant if it is not, and you shouldn't call something a variable if it is not. If you want to call %const a constant, than I can just as easily call 2 a variable. And if you are allowed to do such things, confusion will result.
Oh and also just on an abstract note, the speed of light is relative (according to Einstein) to a larger body of reference which is itself constant. Thus to make the observation that the speed of light is relative, you must accept that a constant body of reference exists.
|
|
|
|
Joined: Feb 2003
Posts: 2,812
Hoopy frood
|
Hoopy frood
Joined: Feb 2003
Posts: 2,812 |
Then I suppose this means you're willing to accept the fact that $identifiers are $identifiers and not meant to be %variables? ![shocked shocked](/images/graemlins/mirc/shocked.gif) (Anyway, I still disbelieve that any constant exists in the universe. Just as the speed of light was thought to be constant simply because our atmosphere made it difficult to see otherwise, all constants you try and present are directly effected by some other variable, whether we're aware of it yet or not... except for perhaps Absolute Zero, which is more of a concept than a constant. To acheive Absolute Zero temperature, all atoms in the universe must cool to the point where not a single sub-atomic particle is in motion relative to any other sub-atomic particle anywhere else in the universe. Absolute Zero is an infinitesimal, and acheiving it is much like trying to exceed the speed of light (or rather, the speed of the universe... which is the speed of the fastest moving "xray") which is also an infinite, because there is no object outside the universe to measure this speed. Just wait until the universe goes on to collapse again... things will get a mite hot, and all science out the window. This will happen when Absolute Zero and The Speed Of Light equal, for a brief moment. We can only speculate that there will be attractive forces at work to bring things back together. Consider 'Reverse Entropy'. ![smirk smirk](/images/graemlins/mirc/smirk.gif) ) - Raccoon
Well. At least I won lunch. Good philosophy, see good in bad, I like!
|
|
|
|
Joined: Dec 2002
Posts: 32
Ameglian cow
|
Ameglian cow
Joined: Dec 2002
Posts: 32 |
regaurdless that's all meaning less in the scope of programming in programming constants exsist all that is required is the proper declaration. What it sounds like to me is that you want a variable with it's scope being limited to a script. kind of like in C were the variable isn't declared ext. so other included files will not be able to manipulate said variable. (not counting indirection). I could see this type of variable as being advantadges to the plugin coders. However in no way would I even imply that a variable with such scope would perhaps be a constant. A constant implies a value that cannot be changed and inwhich is completely global.
It's only called insanity if you're poor. I stay alive to spite those that wish me dead.
|
|
|
|
Joined: Feb 2003
Posts: 2,812
Hoopy frood
|
Hoopy frood
Joined: Feb 2003
Posts: 2,812 |
Constants are rarely completely global, unless it is absolutely necessary for them to be.
Well. At least I won lunch. Good philosophy, see good in bad, I like!
|
|
|
|
Joined: Dec 2002
Posts: 2,809
Hoopy frood
|
Hoopy frood
Joined: Dec 2002
Posts: 2,809 |
Constants are almost ALWAYS global. Seriously, do you even do programming? You talk about programming like you are an expert at it, but when you actually say things, it's just wrong. In C, C++, Java, and even PHP it is VERY common to declare "bitflags" as global constants. This is done in thousands of programs, in fact, any C/C++ program that is more than "return 0" includes constants whether the programmer knows it or not. In C/C++ as soon as you include any of the standard header files you are adding constants to your program. So if every C/C++ program in existence uses constants, in a global scope why would you say it is rare? In fact, up until a change in the C standard, constants were REQUIRED to be global, there was no way to make a constant that wasn't global.
Oh and btw about your 'absolute zero' stuff, how about you stop stating unproven theory as fact? For every statement you stated in that little message of yours, I can give you 2-3 credible refutations by other competing theories. And some of what you said is just wrong, xrays are the fastest EM? Not even close, Gamma rays are far faster. And btw you quote the speed of the universe, well stating that the universe has a speed suggests that the universe is moving. This indicates one of two things. Either a.) you mean it is moving with respect to a CONSTANT body of reference, or b.) it is expanding by laws defined by Hubble's CONSTANT. And the universe collapsing? Ever heard of Friedmann's three models of the universe? Well they follow logically from the fact that the General Theory of Relativity predicts that there is no cosmological constant. It predicts three possible universes, either a closed universe that will contract and implode with a "big crunch", a universe that grows asymptotically close to the point of collapse, or a universe that grows infinitely. First off just general statistics show that there is only a 33% chance the universe will contract, and in recent years with newer theories the universe is viewed to be a "saddle" which is predicted by the model of the universe suggesting infinite expansion.
There is a difference between fact and opinion, your commentary on absolute zero (and constants in general) seems to neglect that issue.
|
|
|
|
Joined: Jun 2003
Posts: 114
Vogon poet
|
Vogon poet
Joined: Jun 2003
Posts: 114 |
Oops. Never really used /var, I'm too lazy. I stick with %variable = <whatever> and then just unset it at the end of the function. And I name them like <function>.variable so I won't accidentally overwrite anything.
------------- I am the self-appointed God of needlessly complex mIRCscript.
|
|
|
|
Joined: Jun 2003
Posts: 114
Vogon poet
|
Vogon poet
Joined: Jun 2003
Posts: 114 |
I've always been under the impression that the only real useful.. use.. of constants is when you are creating a program that you want to be able to easily modify later, or you want to make it easy for others to modify it...
For example, if you make a program that uses a group name like 'Blah' in the program and says, 'Welcome to Blah'.. and it also uses the name many more times later in the program. Instead of using cout<<"Blah", you use cout<<const... then, you only have to modify the variable once before compiling to change all occurences of Blah to something else.
------------- I am the self-appointed God of needlessly complex mIRCscript.
|
|
|
|
Joined: Dec 2002
Posts: 2,809
Hoopy frood
|
Hoopy frood
Joined: Dec 2002
Posts: 2,809 |
Yes thats one use, things like a version_number constant, so instead of having to dig though the source code and change each place the version number is used, you just change the constant. But another common is use for bitflags, which is easier to remember,
the_options & option_1 (checks if option_1 is set)
or
the_options & 0x0001 (checks the same thing)
Making option_1 a constant that = 0x0001 makes it a lot easier to work with since you never have to worry about forgetting which bitflags represent which values. There are also a couple other uses, for example some programs have a constant called "debug" which is set to false, but simply changing that one line so that debug is true enables debugging. Thats very helpful since you can have your release version without the debugging code, but only have to change one line when you want to reenable it to make sure it works.
|
|
|
|
Joined: Jun 2003
Posts: 114
Vogon poet
|
Vogon poet
Joined: Jun 2003
Posts: 114 |
Since you sound like you would know... if a constant is evaluated in an if statement in C++ then, on compiling, are the ifs evaluated and excluded that do not apply?
For example, if I have constant int b = 0 and later I have if (b == 1) { doSomething(); } then will the compiler itself exclude the entire thing since it will never = 1?
I'll assume ahead of time it probly depends on the compiler.. so I use.. uhh.. some Linux compiler (on RedHat). I don't run the actual linux box, so I don't have access to any documentation about the compiler. I guess for this question best guess would work.. not all that important to me, just curious as large amounts of debug (like you described) would take up a li`l bit of extra space.
------------- I am the self-appointed God of needlessly complex mIRCscript.
|
|
|
|
Joined: Dec 2002
Posts: 2,809
Hoopy frood
|
Hoopy frood
Joined: Dec 2002
Posts: 2,809 |
Yes you were right, it does depend on the compiler, and it also depends on a few issues. For example in C++ (in Racoon's defense kinda) it is possible, though highly frowned upon, to modify a constant. Really the only reason for that feature to exist is to be compatible with old code that didn't use constants for certain things. For example, if you are familiar with the std::string class, when you use the std::string::c_str function, it returns a const char *, old C programs use char *, not const char *. So if you try and pass a const char * when a char * is expected, C++ complains, so the const_cast<>() operator was introduced. If you use this operator, and again it is frowned on, the compiler will NOT discard those kind of statements because it is possible that the value might change. As for if you just use it in a normal sense of always being constant, assuming you use g++ on Linux, and a semi-recent version (3.x) it will most likely optimize unneeded statements like that away. I even saw one compiler, though I can't remember the name, that in the situation you described it would generate a message like "constant is set to 0, yet expected to be 1" or something to that effect to let you know that the particular statement is probably a programming error. The way I described it is a bit more simple than it really is, a good compiler will do more checking than what I said, some will even remove it even if const_cast<>() is used if it determines that the value isn't modified. Basically, assume that it might remove it, but don't expect that it will.
|
|
|
|
Joined: Jan 2003
Posts: 2,523
Hoopy frood
|
Hoopy frood
Joined: Jan 2003
Posts: 2,523 |
And some of what you said is just wrong, xrays are the fastest EM? Not even close, Gamma rays are far faster.
See what happens when scripters/programmers start a conversation about physics? They say utterly inaccurate things. All electromagnetic waves (gamma rays, x-rays, ultra violet, visible light, radio waves etc) have the SAME speed, the speed of light, c. They only differ in frequency, which has nothing to do with speed. You might want to study some basic wave physics before you even attempt to tackle cosmology.
/.timerQ 1 0 echo /.timerQ 1 0 $timer(Q).com
|
|
|
|
Joined: Dec 2002
Posts: 2,809
Hoopy frood
|
Hoopy frood
Joined: Dec 2002
Posts: 2,809 |
I know the difference between frequency and speed, do you know the difference between typo and false information? Are you going to tell me you've never thought one word while typing another? I'm sorry a typo offended you so greatly, I'll make sure to check all my messages so that it never happens again.
|
|
|
|
|