functional if (was Special Char Suggestions?)

Dar Scott dsc at
Fri May 9 10:39:01 EDT 2003

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.

Dar Scott

More information about the use-livecode mailing list