new functions?

Ivers, Doug E Doug_Ivers at lord.com
Mon Dec 30 20:00:38 EST 2002


the logical expression (there is a group "myG") 
has an equivalent function:  exists(group "myG") 
which I prefer 

it would be nice to have an equivalent for (n is an integer) 
thus:  isInteger(n) 
and optionally:  isInteger(n,0,4) 
which returns true if n is 0, 1, 2, 3, or 4

here's another:  isArray(a) 
and optionally:  isArray(a,8) 
which returns true if a is an array with 8 elements 

these are simple enough to write and i'll code my own for now and add them to my library, but are such functions being added to transcript over time?  How is the decision made regarding whether a new function belongs in the language, or should be left to the programmer?

if such elementary functions are not going to be added to the language, seems that us programmers should be sharing them amongst ourselves.

Here are some handlers i'll share right now:
function forceBoolean T
  return (T = true)
end forceBoolean
on forceBoolean @T
  if (T <> true) then put false into T
end forceBoolean

the above are useful when processing optional arguments of a function

function forceInteger N lowestN highestN
  -- lowestN <= highestN is not verified herein
  if (N is not a number) then put 0 into N
  if (lowestN is a number and N < lowestN) then return lowestN
  if (highestN is a number and N > highestN) then return highestN
  return trunc(N)
end forceInteger
on forceInteger @N lowestN highestN
  put forceInteger(N,lowestN,highestN) into N
end forceInteger
on testForceInteger
  answer "forceInteger(1.234) = "& forceInteger(1.234)
  answer "forceInteger("&quote&"int"&quote&") = "& forceInteger("int")
  answer "forceInteger(-4.4,2,5) = "& forceInteger(-4.4,2,5)
  answer "forceInteger(4.4,-5,-1) = "& forceInteger(4.4,-5,-1)
  put 1.234 into int
  forceInteger int
  answer "forceInteger 1.234 = "& int
  put -4.4 into int
  forceInteger int,2
   answer "forceInteger -4.4,2 = "& int 
end testForceInteger

(note that args 2 and 3 are optional)


Why don't I see "@" in the Transcript Dictionary? 


-- D 
doug_ivers at lord.com 



More information about the use-livecode mailing list