DictItem

The value stored under a key.

Declaration

Syntax

DictItem(expr a, expr key, expr? default, ttype type, expr? value)

Arguments

Argument

Description

a

the dictionary.

key

the key to look up.

default

the value to produce when the key is absent, or nil.

type

the value type of the dictionary.

value

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

Return values

The value of the expression.

Description

d[k], and d.get(k, default) when default is given. Without a default, looking up a key the dictionary does not hold is an error at run time.

Examples

(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
)

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

DictInsert, DictPop, DictContains