Re: Suggestions for ESL (was: Euphoria Standard Library on UBoard)

new topic     » goto parent     » topic index » view thread      » older message » newer message

D. Newhall wrote:
> I prefer Pete's version over Tommy's however I think enum_begin(start_value,
> step_value)
> and enum() is better because you're not so much creating an enum but instead
> starting
> one.

Let me explain why I used 'enum' and 'next'.
In languages like C#, that have built-in support for enum-types, it looks
like this:
enum DayOfWeek
{
    Monday,
    Tuesday,
    Wednesday,
    Thursday,
    Friday,
    Saturday,
    Sunday
}

So 'DayOfWeek' is the enum-type, and Monday..Sunday are the possible values.
With 'enum' and 'next', you could interpret it like this:
constant
    DAY_OF_WEEK = enum(), -- define the enum DAY_OF_WEEK
    MONDAY  = next(DAY_OF_WEEK), -- MONDAY is the next DAY_OF_WEEK value
    TUESDAY = next(DAY_OF_WEEK), -- TUESDAY is the next DAY_OF_WEEK value
...


To demonstrate how simple this concept is, here's the code from Win4Eu
that implements the enum-system:
--- ENUMERATORS ---

sequence enums
enums = {}

global function enum()
    -- Creates a new enumerator-type
    enums &= 0
    return length(enums)
end function

global function next(integer enumType)
    -- Returns the next value in an enumerator
    integer next_
    next_ = enums[enumType] + 1
    enums[enumType] = next_
    return next_
end function


--
The Internet combines the excitement of typing 
with the reliability of anonymous hearsay.

tommy online: http://users.telenet.be/tommycarlier
tommy.blog: http://tommycarlier.blogspot.com

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu