Constant statement limitations.

Keith Clarke keith.clarke at clarkeandclarke.co.uk
Tue May 29 05:12:09 EDT 2012


Forgive the naiveté (I have no formal development background) - and so maybe there is a subtlety about the formal definition of constants in computer science that I'm missing - but to have a mathematical constant available outside of handlers, can we not choose from script variables, global variables or custom properties (at card or stack levels), depending on the scope required?
Best,
Keith..

On 29 May 2012, at 09:55, Alex Tweedly wrote:

> No.  What tripped me up was
> 
>> <?livecode
>> put "lc version is" && the version & "<br>"
>> constant x = 4
>> put "this web page shows the problem" & "<br>"
>> put "here x = " && x & "<br>"
>> 
>> on somehandler
>>  put "within a handler, x =" && x & "<br>"
>> end somehandler
>> 
>> somehandler
>> put "and finally x still =" && x & "<br>"
>> ?>
> Constants do not take effect *outside* handlers. You rarely, if ever, have code outside a handler in "traditional" livecode - but revserver has changed that, so I think it's a reasonable request to enhance it to work for non-handle code.
> 
> But I am worried there's some obvious case that I haven't thought of that would prevent that being a good idea. If no-one comes up with a reason to keep this constraint, I'll submit an enhancement request.
> 
> -- Alex.
> 
> On 29/05/2012 04:57, dunbarx at aol.com wrote:
>> Alex.
>> 
>> 
>> I have found that if you say this:
>> 
>> 
>> contant x = 4
>> 
>> 
>> on mouseup
>>   answer x
>> end mouseup
>> 
>> 
>> You get a "4"
>> 
>> 
>> But, if you place the contstant statement below the handler, you geet "x".
>> 
>> 
>> Is this what tripped you up?
>> 
>> 
>> Craig Newman
>> 
>> 
>> 
>> -----Original Message-----
>> From: Alex Tweedly<alex at tweedly.net>
>> To: How to use LiveCode<use-livecode at lists.runrev.com>
>> Sent: Mon, May 28, 2012 7:02 pm
>> Subject: Constant statement limitations.
>> 
>> 
>> The dictionary entry for constant says:
>>> If you place the constant statement in a handler, you can use the
>>> constant anywhere in the handler. If you place the constant statement
>>> in a script outside any handler, you can use the constant anywhere in
>>> the handlers of that script.
>> NB - "can use the constant anywhere *in the handlers* of that script".
>> 
>> That was a reasonable limitation in traditional Livecode - but seems
>> less reasonable in the context of revserver. It is (I think) common
>> practice, and it's certainly possible, to have quite a lot of the
>> "top-level" code be in the script itself, perhaps with html intermingled
>> with it, i.e. not be in a handler.
>> 
>> So the obvious, simple code fragment
>> 
>> constant K = 3.14159
>> put $_POST["diameter"] * K
>> 
>> doesn't give the expected result :-)
>> 
>> Anyone see any reason why constants *shouldn't* be usable outside handlers ?
>> 
>> Thanks
>> -- Alex.





More information about the use-livecode mailing list