Skip to content

‘When-Otherwise’ Condition Expression

February 9, 2010

In Quantity System Calculator (DLR)  I’ve implemented a new way of conditional expression that can be written continuously and fits into one line.

I called it  ‘when-otherwise’ expression

‘[true result] when [test] otherwise [false result] when …’

let us define a simple function with it

f(x)  = x when x< 10 otherwise x^2 when x<20 otherwise x^5

I know that I am going against the famous ‘if-then’ statement, however ‘if-then’ statement is an imperative syntax, and I needed a functional statement that fits in one line.

when I was thinking about this new syntax I also didn’t ignore the question syntax of C,C++, C#

‘Test?True Part, False Part’ , but also this syntax is somehow complex to use, and give me a headache actually.

thats why I invented it this way. You can see that the result part precede the condition part and the syntax is truly easy to remember (hard to type) but easy to extend.

Advertisements

From → Uncategorized

Leave a Comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: