Re: type checking ?

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

Here is how how I would do it...

<code>
---- File1
constant
strConstant1 = defineit("This a string constant from file 1")
---- end of File1

---- File2
constant
strConstant2 = defineit("This a string constant from file 2")
---- end of File2

---- File3
constant
strConstant3 = defineit("This a string constant from file 3")
---- end of File3

---- defstr.e ---
global type goodstr(object s)
    if atom(s) then return 0 end if
    is length(s) != 2 then return 0 end if
    if compare(s[1], {{"goodstr"}}) != 0 then return 0 end if
    if atom(s[2]) then return 0 end if
    for i = 1 to length(s[2]) do
        if not integer(s[2][i]) then return 0 end if
        if s[2][i] < 0 then return 0 end if
        if s[2][i] > 255 then return 0 end if
    end for
    return 1
end type

global function defineit(sequence s)
    return {{{"goodstr"}}, s}
end function
---- end of defstr.e


---- MAIN FILE
include defstr.e
include file1
include file2
include file3

procedure useit(goodstring s)
  -- process s here
  if goodstr(s) = 0 then return end if
end procedure

-- These are ok
useit(strConstant1)
useit(strConstant2)
useit(strConstant3)

-- THIS IS WRONG BECAUSE OF THE QUOTES, I DO NOT WANT TO PROCESS THIS.

useit("strConstant1")

</code>

-- 
Derek Parnell
Melbourne, Australia
Skype name: derek.j.parnell

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

Search



Quick Links

User menu

Not signed in.

Misc Menu