1. Scalar Type Function
- Posted by Larry Gregg <lgregg at BIG12.METROBBS.COM> Apr 28, 1998
- 495 views
- Last edited Apr 29, 1998
Some one on the list mentioned that it would be useful to guarantee that a sequence does not contain sequences. So, I wrote the following type. -- clip ------------------------------------------------------------------- -- Is a sequence a scalar? That is, it must be m x 1, -- that is, the sequence must not contain sub-sequences. -- And because of all the discussion of second languages: -- Esperanto: La jena speca funkcio garantias ke sekvenco -- ne havas internan sekvencon. global type skalaro( object v ) -- Checks argument v, returns 0 if not a sequence or it is a sequence -- which contains internal sequences; returns 1 otherwise. if sequence(v) then for i = 1 to length(v) do if sequence (v[i]) then return 0 end if end for return 1 else return 0 -- for atoms return 0, but could interpret an atom -- as one a dimensional sequence, and return 1. -- Opinions, anyone? end if end type -- Test the skalaro type function. (scalar data type function) integer n sequence a skalaro s n = 1 ? n if skalaro(n) then printf(1,"\nn=%d\n",n) else printf(1,"%s\n\n",{"N is not a scalar sequence."}) end if a = {{}} ? a if skalaro(a) then printf(1,"a=%s\n",a) else printf(1,"%s\n\n",{"\"A\" ne estas skalara sekvo."}) end if -- let us see what happens when we try to assign values to type skalaro s = "a sequence" -- this works ? s s[1] = "first element" -- this fails ? s -- clip ------------------------------------------------------------------- Respond to list, or: Larry Gregg lgregg at metrodowntown.com