2

I was perusing the kynetx docs, when I came across this operator in regards to twitter API

=>

What does it mean? It looks like the terenary operator in C++/C#/C etc.

Is it?

flag

2 Answers

2

The => symbol is used in KRL as the condition separator in conditional expressions and as the separator for names in actions.

Conditional expressions are denoted by the following syntax:

<pred> => <expr1> | <expr2>

where the meaning is that is executed and returned if is true and is executed and returns otherwise.

These can be nested to create complex conditional expressions like so:

<pred0> => <expr0> |
<pred1> => <expr1> |
<pred2> => <expr2> |
 ...
          | <exprn>

Note that this is an expression and returns a result. It can only be used where expressions are valid.

Actions in KRL can have names. The purpose is to allow multiple actions in a single rule to be identified in the analytics. The name is separated from the action uing the => symbol.

{
  notify_1 =>
    notify("Title here", msg1)
  notify_2 =>
    notify("Another title here", msg2)
}
link|flag
Ah thank you for this! It is much appreciated! – Alex Mar 2 at 3:28
0

Why yes! It is exactly like the ternary operator! If you don't know what that is, don't worry, the => operator (? operator in other languages) is used like this:

someBool => notify("True", "someBool is true!"); : notify("False", "someBool is false");

this is equivalent to (in KRL):

if (someBool)
 then 
   notify("True", "someBool is true!");
else 
   notify("False", "someBool is false");

This operator is especially useful in variable assignments, as you can assign different values based on how it evaluates. For example:

pre {
       someBoolVar = someOtherBool => true : false;
}

This statement says someBoolVar is true of someOtherBool is true, else assign someBoolVar to false.

link|flag
Conditional expressions cannot be used to choose actions (like notify) as you show above. Actions do not have "else" clauses, only a premise specified by the condition in the action. – Phil Mar 2 at 1:10

Your Answer

Get an OpenID
or

Not the answer you're looking for? Browse other questions tagged or ask your own question.