Const specific for certain variable only.

Feature requests for future versions of Hollywood can be voiced here
Post Reply
Posts: 962
Joined: Sun Feb 14, 2010 7:11 pm

Const specific for certain variable only.

Post by Bugala »

I was wondering how hard would it be to make Consts that would only work with certain Variables?

An Example of what I am after:

Code: Select all

Const myvariable #ON = 1

Code: Select all

myvariable = #ON

mysecondvariable = #ON
- 1
- error

Idea behind this is Triple reason.
First of all, to avoid hitting reserved words. For example using something like #ON or #OFF is soemthing that I would be afraid of using since they could easily become reserved in future Hollywood versions (unless they already are).

Second is, that there can sometimes be situations when it could be handy, two silly examples that will however give you the idea:

Code: Select all

const switch1 #ON = 1
const switch2 #ON = 0

switch1 = #ON
switch2 = #ON

Code: Select all

const defcon #ALARM = 5
const microwave #ALARM = 0

table_checkforalerts = { defcon = 1, microwave = 100 }



alert = false
foreach (table_checkforalerts, function (key, item)
                                                     if key=#ALERT then alert = true
until alert=true
And third is that something like #ON and #OFF could be useful at many places, but their numerical values might differ, for example if there are more states than just ON and OFF.

Posts: 363
Joined: Fri May 15, 2015 5:15 pm
Location: Waterville, Minnesota USA

Re: Const specific for certain variable only.

Post by SamuraiCrow »

It sounds like you are trying to describe enumerations. C allows some rather complicated uses and abuses of the "enum" keyword. Or perhaps making a const table would be more appropriate using a perfect hash function of some sort. might be one type of that.
I'm on registered MorphOS using FlowStudio.

Post Reply