A code style question

Geoff Canyon gcanyon at gmail.com
Wed Jan 21 13:54:41 EST 2015


I was thinking of doing a switch version, so thanks!

On Wed, Jan 21, 2015 at 11:54 AM, Ken Ray <kray at sonsothunder.com> wrote:

> > 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/>
> _______________________________________________
> use-livecode mailing list
> use-livecode at lists.runrev.com
> Please visit this url to subscribe, unsubscribe and manage your
> subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode
>



More information about the use-livecode mailing list