A code style question
Ken Ray
kray at sonsothunder.com
Wed Jan 21 12:54:14 EST 2015
> local baseID
>
> function baseID newID
> put iff(validID(newID),newID, \
> iff(validID(baseID), baseID,"this card")) into baseID
> return baseID
> end baseID3
Of course you could reduce it one step further:
function baseID newID
return iff(validID(newID),newID, \
iff(validID(baseID), baseID,"this card"))
end baseID3
I use a similar inline "switch":
put stsSwitch(the platform,"MacOS=Finder","Win32=Explorer","*=Desktop") into tReference
easier/shorter then:
switch (the platform)
case "MacOS"
put "Finder" into tReference
break
case "Win32"
put "Explorer" into tReference
break
default
put "Desktop" into tReference
break
end switch
For anyone interested, here’s the code:
function stsSwitch
-- does a quick inline switch/case; separate multiple matches with a comma
-- param 1 is <checkValue>
-- params 2+ is in the form <matchValue(s)>=<returnValue>; if there is a match to one
-- or more items in <matchValue(s)>, return <returnValue>
-- otherwise empty is returned (unless a matchValue is "*", in which case return the associated value)
put param(1) into tCheckValue
set the itemDel to "="
put "" into tDefault
repeat with x = 2 to the paramCount
put param(x) into tCheck
put item 1 of tCheck into tMatch
put item 2 of tCheck into tRetVal
replace "," with "=" in tMatch
if tCheckValue is among the items of tMatch then return tRetVal
if tMatch = "*" then
if tRetVal = "*" then
put tCheckValue into tDefault
else
put tRetVal into tDefault
end if
end if
end repeat
return tDefault
end stsSwitch
:D
Ken Ray
Sons of Thunder Software, Inc.
Email: kray at sonsothunder.com <applewebdata://52553A11-C1AF-4926-9DEF-C77D655DC26B/kray@sonsothunder.com>
Web Site: http://www.sonsothunder.com/ <http://www.sonsothunder.com/>
More information about the use-livecode
mailing list