Re: type checking ?

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

Derek Parnell wrote:
> 
> Here is how how I would do it...

(SCNR)
Seems fine but sub-optimal to me, instead I would do this:

---- defstr.e ---
sequence defset
         defset={}

type flatstring(object o) -- if really needed
object ch
  if not sequence(o) then return 0 end if
  for i=1 to length(o) do
    ch=o[i]
    if not integer(o) or o<#00 or o>#FF then return 0 end if
--  (nb: use of "or" above may be suboptimal[?])
  end for
  return 1
end type

global function defineit(flatstring f)
   defset=append(defset,f)
   return length(defset)
end function

global function getstr(integer idx) -- or make defset global
  if idx<1 or idx> length(defset) then ?9/0 end if
  return defset[idx]
end function
---- end of defstr.e

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

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

procedure useit(integer idx)
sequence s
   s = getstr(idx) -- or just s=defset[idx]
   -- process s here
end procedure
 
-- This is ok
useit(strConstant1)

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

useit("strConstant1")
 


Simply put, making strConstant1 (etc) an INTEGER INDEX solves half the problem
right off the bat.

Regards,
Pete

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

Search



Quick Links

User menu

Not signed in.

Misc Menu