Uploaded image for project: 'CFEngine Community'
  1. CFEngine Community
  2. CFE-2930

getindices() should return the positional index from a list

    XMLWordPrintable

    Details

    • Type: Story
    • Status: Open
    • Priority: (None)
    • Resolution: Unresolved
    • Affects Version/s: None
    • Fix Version/s: None
    • Component/s: Built-in functions
    • Labels:
    • Complexity:
      XS

      Description

      As of 3.9.0 getindices() always returns a list. If it's called on a non-existant or undefined variable it returns an empty list.

      Currently (as of 3.12.x) getindcies() when called on a list returns an empty list.

      I think it would be more useful if getindices() when called on a list, returns the positional index of the elements.

      For example:

      bundle agent main
      {
         vars:
            "list" slist => { "beta", "alpha", "gamma" };
            "list_index" slist => sort( getindices( list ), lex );
            "list_values" slist => sort( getvalues( list ), lex);
      
         reports: 
            "List index:";
            "$(list_index)";
            "List values:";
            "$(list_values)";
      }
      

      This outputs:

      R: List index:
      R: List values:
      R: alpha
      R: beta
      R: gamma
      

      I think it should output:

      R: List index:
      R: 0
      R: 1
      R: 2
      R: List values:
      R: alpha
      R: beta
      R: gamma
      

        Attachments

          Activity

            People

            • Assignee:
              Unassigned
              Reporter:
              a10042 Nick Anderson
            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:

                Summary Panel