DictContains

Whether a dictionary holds a key.

Declaration

Syntax

DictContains(expr left, expr right, ttype type, expr? value)

Arguments

Argument

Description

left

the dictionary.

right

the key looked for.

type

the logical type of the result.

value

the compile time value of the expression, when the frontend could fold it; nil otherwise.

Return values

The value of the expression.

Description

k in d. Only the keys are searched.

Examples

(DictContains
  :left (Var
    :v (SymbolRef 1 "d")
  )
  :right (IntegerConstant
    :n 1
    :type (Integer
      :kind 4
    )
    :intboz_type :Decimal
  )
  :type (Logical
    :kind 4
  )
  :value nil
)

It comes from this complete ASR text document:

(TranslationUnit
  :symtab (SymbolTable
    :id 0
    :symbols {
      "main" (Program
        :symtab (SymbolTable
          :id 1
          :symbols {
            "d" (Variable
              :parent_symtab 1
              :name "d"
              :dependencies []
              :intent :Local
              :symbolic_value nil
              :value nil
              :storage :Default
              :type (Dict
                :key_type (Integer
                  :kind 4
                )
                :value_type (Real
                  :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 []
            )
            "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 []
            )
            "x" (Variable
              :parent_symtab 1
              :name "x"
              :dependencies []
              :intent :Local
              :symbolic_value nil
              :value nil
              :storage :Default
              :type (Real
                :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 "d")
            )
            :value (DictConstant
              :keys [
                (IntegerConstant
                  :n 1
                  :type (Integer
                    :kind 4
                  )
                  :intboz_type :Decimal
                )
              ]
              :values [
                (RealConstant
                  :r 1.5
                  :type (Real
                    :kind 4
                  )
                )
              ]
              :type (Dict
                :key_type (Integer
                  :kind 4
                )
                :value_type (Real
                  :kind 4
                )
              )
            )
            :overloaded nil
            :realloc_lhs false
            :move_allocation false
          )
          (Assignment
            :target (Var
              :v (SymbolRef 1 "i")
            )
            :value (DictLen
              :arg (Var
                :v (SymbolRef 1 "d")
              )
              :type (Integer
                :kind 4
              )
              :value nil
            )
            :overloaded nil
            :realloc_lhs false
            :move_allocation false
          )
          (Assignment
            :target (Var
              :v (SymbolRef 1 "x")
            )
            :value (DictItem
              :a (Var
                :v (SymbolRef 1 "d")
              )
              :key (IntegerConstant
                :n 1
                :type (Integer
                  :kind 4
                )
                :intboz_type :Decimal
              )
              :default (RealConstant
                :r 0.0
                :type (Real
                  :kind 4
                )
              )
              :type (Real
                :kind 4
              )
              :value nil
            )
            :overloaded nil
            :realloc_lhs false
            :move_allocation false
          )
          (Assignment
            :target (Var
              :v (SymbolRef 1 "x")
            )
            :value (DictPop
              :a (Var
                :v (SymbolRef 1 "d")
              )
              :key (IntegerConstant
                :n 1
                :type (Integer
                  :kind 4
                )
                :intboz_type :Decimal
              )
              :type (Real
                :kind 4
              )
              :value nil
            )
            :overloaded nil
            :realloc_lhs false
            :move_allocation false
          )
          (Assignment
            :target (Var
              :v (SymbolRef 1 "p")
            )
            :value (DictContains
              :left (Var
                :v (SymbolRef 1 "d")
              )
              :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
          )
          (DictInsert
            :a (Var
              :v (SymbolRef 1 "d")
            )
            :key (IntegerConstant
              :n 2
              :type (Integer
                :kind 4
              )
              :intboz_type :Decimal
            )
            :value (RealConstant
              :r 2.5
              :type (Real
                :kind 4
              )
            )
          )
          (DictClear
            :a (Var
              :v (SymbolRef 1 "d")
            )
          )
        ]
      )
    }
  )
  :items []
)

See Also

DictItem, SetContains, ListContains