[bitc-dev] No operator precedence [was: Syntax: procedure call.]

Sandro Magi naasking at higherlogics.com
Mon Apr 19 11:37:47 PDT 2010


On 11/04/2010 6:30 PM, Jonathan S. Shapiro wrote:
> // curried:
> def fact x =
>   if (x < 0) then - (fact (-x))
>   else if (x == 0) then 1
>   else x * fact (x - 1)
> 
> // non-curried:
> def fact x =
>   if (x < 0) then - fact(-x)
>   else if (x == 0) then 1
>   else x * fact(x - 1)

Just a stylistic suggestion: I now rather dislike the if-else form, and
prefer pattern-matching like forms.

Consequently, I tend to now use ternary operators in my C and C# code
which results in such a clearer form. The above function would look
something like:

def fact x =
  (x == 0) ? 1:
  (x < 0)  ? - fact(-x):
             x * fact(x - 1);

I'm not suggesting ternary operators or pattern matching here, just
supporting the idea of a syntax for conditionals where nested/chained
conditionals have a more readable structure.

Sandro



More information about the bitc-dev mailing list