Examples: Working with lists

  1. (Subscript). @DbName returns a list where element 1 is the server name and element 2 is the file name of the current database. This example gets the file name.
    @Prompt([Ok]; "Database name";
    {"} + @DbName[2] + {"})
  2. (Pair-wise operation). This example adds two numeric lists in a pair-wise operation. The resulting list has the four values 11, 22, 27, and 44.
    list1 := 10 : 20 : 30 : 40;
    list2 := 1 : 2 : (-3) : 4;
    list3 := list1 + list2;
    result := @Text(list1) + " + " + @Text(list2) + " = " + @Text(list3);
    @Prompt([OkCancelList]; "Result"; ""; ""; result)
  3. (Permuted operation). This example concatenates two lists in a permuted operation. The resulting list has the 12 values Blue Sedan, Blue Coupe, Blue Van, Blue Truck, Red Sedan, and so on through Yellow Truck.
    cars := "Sedan" : "Coupe" : "Van" : "Truck";
    colors := "Blue" : "Red" : "Yellow";
    result := colors + " " *+ cars;
    @Prompt([OkCancelList]; "Result"; ""; ""; result)
  4. (@Elements). This example prints a message if the Categories field has no elements, and prints the list if it does.
    @If(@Elements(Categories) = 0; @Prompt([Ok]; "Categories"; "No categories");
    @Prompt([OkCancelList]; "Categories"; ""; ""; Categories))
  5. (@Explode). This example explodes a string constant into a list using the default separators space, comma, and semicolon. The resulting list has the values Paris, London, Chicago, and Seoul.
    cityList := @Explode("Paris London,Chicago;Seoul");
    @Prompt([OkCancelList]; "List of cities"; ""; ""; cityList)
  6. (@Explode). This example explodes a string constant into a list using the separators comma and semicolon. The resulting list has the values Paris, London, New York, and Washington DC. New York and Washington DC are not separated into New, York, Washington, and DC because the space is not included as a separator.
    cityList := @Explode("Paris,London,New York;Washington DC"; ",;");
    @Prompt([OkCancelList]; "List of cities"; ""; ""; cityList)
  7. (@Explode). This example includes a blank entry between London and New York. If the third parameter is @False or is omitted, multiple consecutive separators are treated as one. Ensure that the commas are consecutive and not separated by a space.
    cityList := @Explode("Paris,London,,New York;Washington DC"; ",;"; @True);
    @Prompt([OkCancelList]; "List of cities"; ""; ""; cityList)
  8. (@Implode). This example implodes a list constant into a string variable using a space (the default) to separate the values. The resulting string has the value Minneapolis Detroit Chicago.
    city := "Minneapolis" : "Detroit" : "Chicago";
    cityString := @Implode(city);
    @Prompt([Ok]; "Imploded string"; cityString)
  9. (@Implode). This example implodes a list constant into a string variable using a comma and a space to separate the values. The resulting string has the value Minneapolis, Detroit, Chicago.
    city := "Minneapolis" : "Detroit" : "Chicago";
    cityString := @Implode(city; ", ");
    @Prompt([Ok]; "Imploded string"; cityString)
  10. (@Implode). This example implodes a list field into a string using a colon to separate the values. If the Categories field is entered as Minneapolis, Detroit, Chicago, the resulting string is Minneapolis:Detroit:Chicago.
    @Prompt([Ok]; "Categories"; @Implode(Categories; ":"))
  11. (IsMember). This agent example checks the selected documents to see if Adjusted is in the Categories list. If it is, Categories remains the same. If it is not, Adjusted is added to the Categories list.
    FIELD Categories := @If(@IsMember("Adjusted"; Categories); Categories; @Explode(@Implode(Categories; ";") + ";Adjusted"; ";"));
    SELECT @All
  12. (@IsNotMember). This example checks the selected documents to see if Adjusted and Signed off are in the Categories list. If both are not, both are added to the Categories list. If both are, Categories remains the same.
    FIELD Categories := @If(@IsNotMember("Adjusted" : "Signed off"; Categories); @Explode(@Implode(Categories; ";") + ";Adjusted;Signed off"; ";"); Categories);
    SELECT @All
  13. (@Keywords). This example finds which keywords are used in the Cities field.
    keywords := @Keywords(Cities ; "Paris" : "Moscow" : "Tokyo" : "Boston");
    @Prompt([Ok]; "Keywords"; keywords)
  14. (@Member). This example has the user pick a value from a list and displays the number of that value within the list.
    cars := "Sedan" : "Coupe" : "Van" : "Truck";
    car := @Prompt([OkCancelList] : [NoSort]; "Cars"; "Pick one"; "Sedan"; cars);
    n := @Member(car; cars);
    @Prompt([Ok]; "Your selection is ..."; "Number " + @Text(n))
  15. (@Replace). This example replaces red with scarlet and blue with turquoise in the list derived from colors.
    colors := "red" : "blue" : "yellow" : "blue" : "black" : "red";
    from := "red" : "blue";
    to := "scarlet" : "turquoise";
    result := @Replace(colors; from; to);
    @Prompt([OkCancelList] : [NoSort]; "Replacement list"; ""; ""; result)
  16. (@Subset). This example places New Orleans, London, and Frankfurt into first3, and Singapore and Sydney into last2.
    cities := "New Orleans" : "London" : "Frankfurt" : "Singapore" :"Sydney";
    first3 := @Subset(cities; 3);
    last2 := @Subset(cities; -2);
    @Prompt([OkCancelList] : [NoSort]; "First three"; ""; ""; first3);
    @Prompt([OkCancelList] : [NoSort]; "Last two"; ""; ""; last2)
  17. (@Transform and @Nothing). This example returns a list with three elements: 1, 2, and 4.
    OriginalList := 1 : 4 : -4 : 16;
    @If(OriginalList = @Nothing; @Nothing;
    @Transform(OriginalList; "x";
    @If(x >= 0; @Sqrt(x); @Nothing)))
  18. (@Unique). This example returns a list with four elements: red, blue, yellow, and black.
    colors := "red" : "blue" : "yellow" : "blue" : "black" : "red";
    result := @Unique(colors);
    @Prompt([OkCancelList] : [NoSort]; "Unique list"; ""; ""; result)