functional if (was Special Char Suggestions?)

Richard Gaskin ambassador at fourthworld.com
Fri May 9 13:51:02 EDT 2003


Dar Scott wrote:

> 
> On Friday, May 9, 2003, at 04:56 AM, curry wrote:
> 
>> Lately I've been using:
>> 
>> function ? x,a,b
>> if x then
>> return a
>> else
>> return b
>> end if
>> end function
>> 
>> This is really helping in the project I'm working on.
> 
> This can be useful, but it is not as powerful as what I would want.  I
> would want the function to be lazy and not evaluate a or b unless
> needed.  I think the above function would evaluate both.  I would
> normally not have side-effects a or b expressions, so that is not a
> problem, but I would rather not waste the time.
> 
> Because of this, this should be a built-in part of the language.
> 
> I tend to use a functional style and because of that many--if not
> most--of my function definitions tend to be one command, the return.
> Sometimes that line is continued over several lines.  This is not
> always the most readable in transcript; transcript is somewhat
> imperative.  (The "put" command reminds us of the implied "you" in
> English.)  To make my code more readable I sometimes break out
> subexpressions and name them with "put" commands, perhaps hurting
> performance.  If my return "wants" to have an "if", then I break that
> out into preceding code.
> 
> I haven't made up my mind on the proposed name.  Since function with
> that name will break when/if ?: is added, that may be a reasonable name.

The few libraries I've seen with that call it "iif"

-- 
 Richard Gaskin 
 Fourth World Media Corporation
 Developer of WebMerge 2.2: Publish any database on any site
 ___________________________________________________________
 Ambassador at FourthWorld.com       http://www.FourthWorld.com
 Tel: 323-225-3717                       AIM: FourthWorldInc




More information about the use-livecode mailing list