1. Re: Win32Lib --Duh

>If you're serious about optimizing this kind of code (for speed - what
else)
>then try these ....
>I haven't bothered with types or multi-level sequences, sorry Ralf.
>blink


Just declare them as types, rather than functions. It is what they are. You
return a 1 or a 0, as appropiately, and they will thus work fine, being
declared as types. The only advantage they have, is that you can say:

numeric text

text = "456"
text = "Hello!"        -- Crash!

And maintaining your (prolly fastest) approaches, however supporting
orbiturary objects, though speed up in favor of one dimensional sequences...
... this is as fast as it gets: (with all the new features on, and be 100%
fool-proof)

constant TRUE = 1, FALSE = 0

type numeric(object s)
object item
integer c

    if sequence (s) then
        for i=1 to length(s) do
            item=s[i]
            if integer(item) then
                c = item
                if c<'0' then return FALSE
                elsif c>'9' then return FALSE
                end if
            elsif sequence (item) then
                if not numeric (item) then
                    return FALSE
                end if
            else
                return FALSE
            end if
        end for
        return TRUE
    elsif integer(s)
        c = s
        if c<'0' then return FALSE
        elsif c>'9' then return FALSE
        end if
        return TRUE
    else
        return FALSE
    end if
end type




type numeric(object s)
object item
integer c

    if sequence (s) then
        for i=1 to length(s) do
            item=s[i]
            if integer(item) then
                c = item
                if c<='Z' then
                    if c<'A' then return FALSE end if
                elsif c>='a' then
                   if c>'z' then return FALSE end if
                end if
            elsif sequence (item) then
                if not numeric (item) then
                    return FALSE
                end if
            else
                return FALSE
            end if
        end for
        return TRUE
    elsif integer(s)
        c = s
        if c<='Z' then
            if c<'A' then return FALSE end if
        elsif c>='a' then
            if c>'z' then return FALSE end if
        end if
        return TRUE
    else
        return FALSE
    end if
end type

Ralf Nieuwenhuijsen
nieuwen at xs4all.nl
ralf_n at email.com
UIN: 9389920

new topic     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu