SetInsert

Adds an element to a set.

Declaration

Sintaxe

SetInsert(expr a, expr ele)

Argumentos

Argument

Descrição

a

the set.

ele

the element to add.

Valores de retorno

Nenhum.

Descrição

Adding an element the set already contains does nothing, which is what makes the operation different from ListAppend.

Exemplos

(SetInsert
  :a (Var
    :v (SymbolRef 1 "s")
  )
  :ele (IntegerConstant
    :n 3
    :type (Integer
      :kind 4
    )
    :intboz_type :Decimal
  )
)

It comes from this complete ASR text document:

(TranslationUnit
  :symtab (SymbolTable
    :id 0
    :symbols {
      "main" (Program
        :symtab (SymbolTable
          :id 1
          :symbols {
            "i" (Variable
              :parent_symtab 1
              :name "i"
              :dependencies []
              :intent :Local
              :symbolic_value nil
              :value nil
              :storage :Default
              :type (Integer
                :kind 4
              )
              :type_declaration nil
              :abi :Source
              :access :Public
              :presence :Required
              :value_attr false
              :target_attr false
              :contiguous_attr false
              :bindc_name nil
              :is_volatile false
              :is_protected false
              :pass_attr :NotMethod
              :self_argument nil
              :codims []
            )
            "p" (Variable
              :parent_symtab 1
              :name "p"
              :dependencies []
              :intent :Local
              :symbolic_value nil
              :value nil
              :storage :Default
              :type (Logical
                :kind 4
              )
              :type_declaration nil
              :abi :Source
              :access :Public
              :presence :Required
              :value_attr false
              :target_attr false
              :contiguous_attr false
              :bindc_name nil
              :is_volatile false
              :is_protected false
              :pass_attr :NotMethod
              :self_argument nil
              :codims []
            )
            "s" (Variable
              :parent_symtab 1
              :name "s"
              :dependencies []
              :intent :Local
              :symbolic_value nil
              :value nil
              :storage :Default
              :type (Set
                :type (Integer
                  :kind 4
                )
              )
              :type_declaration nil
              :abi :Source
              :access :Public
              :presence :Required
              :value_attr false
              :target_attr false
              :contiguous_attr false
              :bindc_name nil
              :is_volatile false
              :is_protected false
              :pass_attr :NotMethod
              :self_argument nil
              :codims []
            )
          }
        )
        :name "main"
        :dependencies []
        :body [
          (Assignment
            :target (Var
              :v (SymbolRef 1 "s")
            )
            :value (SetConstant
              :elements [
                (IntegerConstant
                  :n 1
                  :type (Integer
                    :kind 4
                  )
                  :intboz_type :Decimal
                )
                (IntegerConstant
                  :n 2
                  :type (Integer
                    :kind 4
                  )
                  :intboz_type :Decimal
                )
              ]
              :type (Set
                :type (Integer
                  :kind 4
                )
              )
            )
            :overloaded nil
            :realloc_lhs false
            :move_allocation false
          )
          (Assignment
            :target (Var
              :v (SymbolRef 1 "i")
            )
            :value (SetLen
              :arg (Var
                :v (SymbolRef 1 "s")
              )
              :type (Integer
                :kind 4
              )
              :value nil
            )
            :overloaded nil
            :realloc_lhs false
            :move_allocation false
          )
          (Assignment
            :target (Var
              :v (SymbolRef 1 "p")
            )
            :value (SetContains
              :left (Var
                :v (SymbolRef 1 "s")
              )
              :right (IntegerConstant
                :n 1
                :type (Integer
                  :kind 4
                )
                :intboz_type :Decimal
              )
              :type (Logical
                :kind 4
              )
              :value nil
            )
            :overloaded nil
            :realloc_lhs false
            :move_allocation false
          )
          (Assignment
            :target (Var
              :v (SymbolRef 1 "i")
            )
            :value (SetPop
              :a (Var
                :v (SymbolRef 1 "s")
              )
              :type (Integer
                :kind 4
              )
              :value nil
            )
            :overloaded nil
            :realloc_lhs false
            :move_allocation false
          )
          (SetInsert
            :a (Var
              :v (SymbolRef 1 "s")
            )
            :ele (IntegerConstant
              :n 3
              :type (Integer
                :kind 4
              )
              :intboz_type :Decimal
            )
          )
          (SetRemove
            :a (Var
              :v (SymbolRef 1 "s")
            )
            :ele (IntegerConstant
              :n 2
              :type (Integer
                :kind 4
              )
              :intboz_type :Decimal
            )
          )
          (SetClear
            :a (Var
              :v (SymbolRef 1 "s")
            )
          )
        ]
      )
    }
  )
  :items []
)

Veja Também

SetRemove, SetClear, Set, SetContains