Help get this topic noticed by sharing it on Twitter, Facebook, or email.

Variable Expressions

In the tutorial I see some math expressions. It would be great to see a list of all operators available.

Right now, I am most interested in text expressions.
I think 'X' + 'Y' will return 'XY'...but what else is supported?
For example LEFT(sourcetext, 5) or MID(sourcetext,3,1) or FIND or even Regex?

Rather than shoot in the dark, could you guys list what is and isn't doable!
Thanks. 4.0 rocks.
1 person has
this question
+1
Reply
  • 2
    Here are list of things you can do with Variable Expressions in Android app. iOS app has 2-3 extra functions.

    * It supports following Math functions:
    'sin', 'cos', 'tan', 'log', 'ln', 'exp', 'abs', 'sqrt', 'asin', 'acos', 'atan', 'sinh', 'cosh', 'tanh', 'ceil', 'floor', 'round', 'rint', 'dtor', 'rtod'

    * Check here to know about these functions: http://developer.android.com/referenc...

    * Single or double quote around a text or number will treat it as String
    You can use single quote inside double, or vice versa. Example: “That’s great.” or ‘He said, “Hello”.’

    * You can add double quote inside double quote using forward slash, same for single quote. Example: “He said, \”Hello\”.” or ‘That\’s cool.’

    * If you add a variable to a string, output will be a string. Example: “2” + 3 will return “23” instead of 5.

    * It supports addition, subtraction, multiplication & division.

    * If there is no value assigned in a variable, expression will use 0 for it
    Variable name should have $ at beginning & at end like $name$

    * If you add a variable inside a string, it won’t evaluate any value. Example, if $x$ = 5, “x = $x$” will return as “x = $x$”. But “x = “+$x$ will return as “x = 5”.
  • (some HTML allowed)
    How does this make you feel?
    Add Image
    I'm

    e.g. happy, confident, thankful, excited kidding, amused, unsure, silly indifferent, undecided, unconcerned sad, anxious, confused, frustrated

  • I thought this had been discussed before, but now cannot find any reference to it.

    What is the order of evaluation in an expression?

    It is crucial to know what is evaluated first when using mathematical expressions. How does iRule do it? The std. way is to evaluate * and / first, then + and - and often brackets would be used to further define what needs to be done first.

    Could we have some clear explanation of how iRule does this?
  • (some HTML allowed)
    How does this make you feel?
    Add Image
    I'm

    e.g. happy, confident, thankful, excited kidding, amused, unsure, silly indifferent, undecided, unconcerned sad, anxious, confused, frustrated

  • Still no answer to question above and here's another:-

    What are the extra functions that iOS supports and why mention that they exist but not actually say what they are?

    Specifically, are min and max supported in iOS?

    There are quite a few functions listed on the linked page that Mohammad doesn't mention. I originally inferred from his post that all those are the supported functions, but then it might be the case that only some of them are actually supported, in which case that linked page of functions is entirely misleading.

    I'm exasperated that there is no clear documentation on any of this. Having introduced this capability, the docs should indicate EXACTLY what functions are supported AND how they work. We shouldn't be directed to some other development page that lists a load of functions that may or may not be supported. This shouldn't have to be trial and error.

    So, min, max? Supported? If not, I'd like to suggest their inclusion.
  • (some HTML allowed)
    How does this make you feel?
    Add Image
    I'm

    e.g. happy, confident, thankful, excited kidding, amused, unsure, silly indifferent, undecided, unconcerned sad, anxious, confused, frustrated

  • I just tried using max() but the result was just a text string so I guess neither that nor min() is supported which is a shame as they seem a pretty basic requirement.

    As I said, could I request these be included?
  • (some HTML allowed)
    How does this make you feel?
    Add Image
    I'm

    e.g. happy, confident, thankful, excited kidding, amused, unsure, silly indifferent, undecided, unconcerned sad, anxious, confused, frustrated

  • We used 3rd party libraries for evaluating expression. We didn’t have chance to check their source codes. I assume it evaluates * & / first and then + & -. If there are parentheses they should evaluate first.

    We didn’t implement all functions listed on that Android developer page. I posted the link to provide reference of those functions we implemented. I apologize if that link is misleading.

    We do not have plan to implement max & min functions at this moment.

    Here are list of all functions supported in iOS:
    "sin", "cos”, "tan", "log", "log2”, "ln", "exp", "abs", "sqrt", "asin", "acos", "atan”, "sinh", "cosh", "tanh", "asinh", "acosh", "atanh", "ceil", "floor", "round", "trunc", "rint", "near", “dtor" & “rtod"

    Here is our official document about variable expression:
    https://irule.desk.com/customer/porta...
  • (some HTML allowed)
    How does this make you feel?
    Add Image
    I'm

    e.g. happy, confident, thankful, excited kidding, amused, unsure, silly indifferent, undecided, unconcerned sad, anxious, confused, frustrated

  • Thanks for that info. But it would appear the documentation is still rather incomplete. For example, there is still no indication of what "near", “dtor" & “rtod" do since they are not mentioned at all in the article linked to as an explanation of all the functions you do support. Also, no mention on your support page of the evaluation order, nor that parentheses are supported which will be of great benefit, I was under the impression they were not, so that's good news.

    As for max() and min(), they really should be included as they are a somewhat more fundamentally useful requirement than the more esoteric trig functions that quite frankly I cannot imagine ever needing to use in a remote control app.
  • (some HTML allowed)
    How does this make you feel?
    Add Image
    I'm

    e.g. happy, confident, thankful, excited kidding, amused, unsure, silly indifferent, undecided, unconcerned sad, anxious, confused, frustrated

  • Thanks for your suggestions. I will let our support & developer team know about it.
  • (some HTML allowed)
    How does this make you feel?
    Add Image
    I'm

    e.g. happy, confident, thankful, excited kidding, amused, unsure, silly indifferent, undecided, unconcerned sad, anxious, confused, frustrated

  • Can you let me know in which scenario you might need max() and min()?
    • view 2 more comments
    • As I think you've realised, max() will EXACTLY solve my problem.

      Using a conditional is all very well, but first of all, it's long winded when you have a lot of them to incorporate and the code becomes long and harder to manage within the Builder environment.

      Also, it is IMPOSSIBLE to do when it needs to be inserted inside an existing conditional, because sadly we cannot nest conditionals. Well, I say impossible but sometimes it is possible to get around it with multiple conditions, but it's not always possible to do that, makes horribly convoluted code and is slow to process. so It's not really an option.

      Max(), that would do it in one :-)
    • Ok, I am posting a ticket requesting this feature in our issue tracking system. If it is approved, hopefully you will get it in one of the future releases :-)
  • (some HTML allowed)
    How does this make you feel?
    Add Image
    I'm

    e.g. happy, confident, thankful, excited kidding, amused, unsure, silly indifferent, undecided, unconcerned sad, anxious, confused, frustrated

  • 1
    dtor (degrees to radians)
    rtod (radians to degrees)
  • (some HTML allowed)
    How does this make you feel?
    Add Image
    I'm

    e.g. happy, confident, thankful, excited kidding, amused, unsure, silly indifferent, undecided, unconcerned sad, anxious, confused, frustrated

  • >>That is just my current requirement, but I'm sure there are others, unlike converting between degrees and radians or other general trigonometry which as I said before seems highly unlikely to ever be needed in a remote control app. <<

    I suspect they were included not for any probable utility in this app, but instead as a part of a standard function library. C++?
  • (some HTML allowed)
    How does this make you feel?
    Add Image
    I'm

    e.g. happy, confident, thankful, excited kidding, amused, unsure, silly indifferent, undecided, unconcerned sad, anxious, confused, frustrated

  • So, did we get max() and/or min() yet?

    Someone please explain to me why we might need 'degrees to radians' or the reverse in a remote control app, when max and min are far more fundamental, yet have been mysteriously omitted.

    And 1 year later, still no word on their possible inclusion :-(
  • (some HTML allowed)
    How does this make you feel?
    Add Image
    I'm

    e.g. happy, confident, thankful, excited kidding, amused, unsure, silly indifferent, undecided, unconcerned sad, anxious, confused, frustrated

  • I’m confident
    min and max are easy to add using maths, so long as abs (absolute value) is supported, which it is.

    min(a,b) = (a + b - abs(a - b))/2
    max(a,b) = (a + b + abs(a - b))/2

    Something programmers of the 1980s learned with their mother's milk, because most languages had no min and max functions (or log or power functions either, which were a bit tougher to replace!)
    • Yes, this has already been covered elsewhere. I should have been able to work it out for myself, but I didn't, so this is kinda useful. But not as compact as if we had real max() and min() functions. By the time you've put in your long variable names, the resulting expression is hard to read, runs out of space and the way the Builder wraps text is less than helpful.

      Of course if we could pass parameters to Global Macros, max and min GMs could be created and used, but since we can't, the additional setting of variables required to use GMs as defined functions in this way makes it not worth while.

      So while the above calculation does do what is required, it is not as convenient and compact and is no doubt slower than built-in functions that let's face it, they could easily build-in themselves using the above formulae without having to resort to buying in someone else's code.

      My gripe with the iRule team is that they HAVE included a load of built-in functions that are of no value, just because it was easy for them to do so. Yet when specifically requested for far more useful max() and min(), they did nothing for a whole year, then when prompted again rather rudely dismissed it with, "nah, no chance". Which quite frankly is not the response one should get from a caring sharing customer service oriented company. Well, not if it wants to keep its customers anyway.
  • (some HTML allowed)
    How does this make you feel?
    Add Image
    I'm

    e.g. happy, confident, thankful, excited kidding, amused, unsure, silly indifferent, undecided, unconcerned sad, anxious, confused, frustrated

  • UKenGB,

    Why don't you go check out Command Fusion, which has EVERY programming feature you are asking for? Similar to Javascript, if I recall correctly. It will also work with Global Cache devices, although they don't promote it heavily.

    Mike
  • (some HTML allowed)
    How does this make you feel?
    Add Image
    I'm

    e.g. happy, confident, thankful, excited kidding, amused, unsure, silly indifferent, undecided, unconcerned sad, anxious, confused, frustrated

  • We have added max() & min() functions to the variable expressions in the latest version 4.7.0.
  • (some HTML allowed)
    How does this make you feel?
    Add Image
    I'm

    e.g. happy, confident, thankful, excited kidding, amused, unsure, silly indifferent, undecided, unconcerned sad, anxious, confused, frustrated

  • (some HTML allowed)
    How does this make you feel?
    Add Image
    I'm

    e.g. happy, confident, thankful, excited kidding, amused, unsure, silly indifferent, undecided, unconcerned sad, anxious, confused, frustrated