Page 1 of 1

Inline if

Posted: 24 Jul 2016 06:00
by pmgnt
To automate stuff on windows pc im using an amazing tool called QuickMacros which can be found here (http://www.quickmacros.com).
Its programming language is not too hard and well documented and supported.

A function i use very often is 'Inline if'
It saves alot of lines and typing in complex codes and you dont have to bother enclosing anything.

It would be great to have it in AM script.

Here its documented: http://www.quickmacros.com/help/Functions/IDP_IIF.html

Could you add it?

Thanks alot!

Re: Inline if

Posted: 24 Jul 2016 06:52
by Bushmills
"To bother enclosing anything" isn't necessary even now, apart from the tested condition itself.

Code: Select all

if (x) a;
is legal Automagic syntax.

Unix shells commonly allow constructs like

Code: Select all

x && a

Code: Select all

x || b
which need even less brackets, parentheses and the like.

Re: Inline if

Posted: 24 Jul 2016 06:55
by MURTUMA
I don't think this would be necessary. The way that is used here is so simple logic that it shouldn't be too hard to understand.

Case: If expression "x" returns true, execute "a", otherwise execute "b".

Quickmacro:
iif(x a b)

Automagic:
if (x) {a} ELSE {b};

I think the difference isn't large enough to make the need for added function. Also, the former can handle only single expressions and script blocks are strictly prohibited from it. That makes it usable only for very basic operations.

Re: Inline if

Posted: 24 Jul 2016 07:17
by Bushmills
Quick scan of my uses of "if" indicates that about 80 to 90% of its uses is without "else". This is partly due to active avoidance.

Notice also that a construct, commonly written as

Code: Select all

if (x)
{
  result = a
}
else
{
  result = b
}
can alternatively be written as

Code: Select all

result = if (x) a else b;

Re: Inline if

Posted: 24 Jul 2016 10:36
by pmgnt
Thank you guys!

I didnt know u could put it all into a single line like:

result = if (x) {a} else {b}

I thought the curly brackets have to be in seperated lines and inside a for or while loop it uses alot of space and confused me more than once.. however,
this is perfect

result = if(x) a else b;

Thanks

Re: Inline if

Posted: 24 Jul 2016 15:37
by MURTUMA
When using very long expressions or large script blocks, splitting them in different lines helps to maintain readability. There's no other function in that. In theory, you could write infinitely long script in a single line.