Jump to content
  • Declaring Complex Data Types as Arguments to the Function Data Type in Spotfire® Streaming


    In general, declaring the signature for function data types in the Spotfire® Streaming Expression Language is documented in the StreamBase product documentation's Defining Functions in the StreamBase Expression Language and function Data Type sections.

    That documentation, at least as of Spotfire® Streaming 7.6.3, does not give examples of declaring functions with complex argument types. so this page provides some examples that should be helpful.

    The general syntax for the function data type is:

    function [function_name] (arg1 type, arg2 type,...) [ -> return_type ] {body}

    Notice that:

    • Both function_name and -> return_type are optional.
      • Except that function_name is not optional when the function definition is recursive.
      • When the return_type is not specified, StreamBase determines the return type from the output of the function.
    • Parentheses enclose the list of arguments.
    • Braces enclose the body of the function definition.

    For simple data types, declaring the type is very straighforward -- it's just the name of the type.

    function to_fahrenheit(cels double) -> double { (9/5 * cels) + 32 }

    But what about the complex data types -- lists, tuples, and functions?

    Here's a function whose argument type is a tuple whose schema has two fields, an integer, a, and a string, b:

    function foo (arg (a int, b string)) { "bar" }

    Here's a function that takes an argument which is a list of integers:

    function foo (arg list (int)) { 3 }

    This function has an argument that is a list of tuples; the schema of the tuples is a single int field, a.

    function foo (arg list ((a int))) { 3 }

    This one's argument is a tuple whose schema is one list(int) and one string:

    function foo (arg (a list(int), b string)) { 3 }

    In the following, function foo's argument is itself an unnamed function whose argument is an int and the argument function returns a double

    function foo (arg (a int)->double) { 3 }

    Finally, consider the following unlikely argument list for a function definition:

    function foobar (arg (a int)->(b double)->(c string)->int ) { 3 }

    • Function foobar takes a single argument that is an unnamed function,
      • which itself takes an int argument and returns an unnamed function
        • that takes a double argument and returns an unnamed function
          • that takes a string argument and returns an int. 

    User Feedback

    Recommended Comments

    There are no comments to display.


×
×
  • Create New...