ListConcat

Two lists joined into a new one.

声明

语法

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

参数

Argument

描述

left

the first list.

right

the second list.

type

the list type of the result.

value

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

返回值

The value of the expression.

描述

a + b in LPython. Neither operand is modified; the result is a new list.

示例

(ListConcat
  :left (Var
    :v (SymbolRef 1 "a")
  )
  :right (Var
    :v (SymbolRef 1 "b")
  )
  :type (List
    :type (Integer
      :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 {
            "a" (Variable
              :parent_symtab 1
              :name "a"
              :dependencies []
              :intent :Local
              :symbolic_value nil
              :value nil
              :storage :Default
              :type (List
                :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 []
            )
            "b" (Variable
              :parent_symtab 1
              :name "b"
              :dependencies []
              :intent :Local
              :symbolic_value nil
              :value nil
              :storage :Default
              :type (List
                :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 []
            )
            "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 []
            )
          }
        )
        :name "main"
        :dependencies []
        :body [
          (Assignment
            :target (Var
              :v (SymbolRef 1 "a")
            )
            :value (ListConstant
              :args [
                (IntegerConstant
                  :n 1
                  :type (Integer
                    :kind 4
                  )
                  :intboz_type :Decimal
                )
                (IntegerConstant
                  :n 2
                  :type (Integer
                    :kind 4
                  )
                  :intboz_type :Decimal
                )
                (IntegerConstant
                  :n 3
                  :type (Integer
                    :kind 4
                  )
                  :intboz_type :Decimal
                )
              ]
              :type (List
                :type (Integer
                  :kind 4
                )
              )
            )
            :overloaded nil
            :realloc_lhs false
            :move_allocation false
          )
          (Assignment
            :target (Var
              :v (SymbolRef 1 "i")
            )
            :value (ListLen
              :arg (Var
                :v (SymbolRef 1 "a")
              )
              :type (Integer
                :kind 4
              )
              :value nil
            )
            :overloaded nil
            :realloc_lhs false
            :move_allocation false
          )
          (Assignment
            :target (Var
              :v (SymbolRef 1 "b")
            )
            :value (ListConcat
              :left (Var
                :v (SymbolRef 1 "a")
              )
              :right (Var
                :v (SymbolRef 1 "b")
              )
              :type (List
                :type (Integer
                  :kind 4
                )
              )
              :value nil
            )
            :overloaded nil
            :realloc_lhs false
            :move_allocation false
          )
          (Assignment
            :target (Var
              :v (SymbolRef 1 "b")
            )
            :value (ListRepeat
              :left (Var
                :v (SymbolRef 1 "a")
              )
              :right (IntegerConstant
                :n 2
                :type (Integer
                  :kind 4
                )
                :intboz_type :Decimal
              )
              :type (List
                :type (Integer
                  :kind 4
                )
              )
              :value nil
            )
            :overloaded nil
            :realloc_lhs false
            :move_allocation false
          )
          (Assignment
            :target (Var
              :v (SymbolRef 1 "p")
            )
            :value (ListCompare
              :left (Var
                :v (SymbolRef 1 "a")
              )
              :op :Eq
              :right (Var
                :v (SymbolRef 1 "b")
              )
              :type (Logical
                :kind 4
              )
              :value nil
            )
            :overloaded nil
            :realloc_lhs false
            :move_allocation false
          )
          (Assignment
            :target (Var
              :v (SymbolRef 1 "i")
            )
            :value (ListCount
              :arg (Var
                :v (SymbolRef 1 "a")
              )
              :ele (IntegerConstant
                :n 1
                :type (Integer
                  :kind 4
                )
                :intboz_type :Decimal
              )
              :type (Integer
                :kind 4
              )
              :value nil
            )
            :overloaded nil
            :realloc_lhs false
            :move_allocation false
          )
          (Assignment
            :target (Var
              :v (SymbolRef 1 "p")
            )
            :value (ListContains
              :left (Var
                :v (SymbolRef 1 "a")
              )
              :right (IntegerConstant
                :n 2
                :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 (ListItem
              :a (Var
                :v (SymbolRef 1 "a")
              )
              :pos (IntegerConstant
                :n 0
                :type (Integer
                  :kind 4
                )
                :intboz_type :Decimal
              )
              :type (Integer
                :kind 4
              )
              :value nil
            )
            :overloaded nil
            :realloc_lhs false
            :move_allocation false
          )
          (Assignment
            :target (Var
              :v (SymbolRef 1 "b")
            )
            :value (ListSection
              :a (Var
                :v (SymbolRef 1 "a")
              )
              :section (array_index
                :left (IntegerConstant
                  :n 0
                  :type (Integer
                    :kind 4
                  )
                  :intboz_type :Decimal
                )
                :right (IntegerConstant
                  :n 2
                  :type (Integer
                    :kind 4
                  )
                  :intboz_type :Decimal
                )
                :step (IntegerConstant
                  :n 1
                  :type (Integer
                    :kind 4
                  )
                  :intboz_type :Decimal
                )
              )
              :type (List
                :type (Integer
                  :kind 4
                )
              )
              :value nil
            )
            :overloaded nil
            :realloc_lhs false
            :move_allocation false
          )
          (ListAppend
            :a (Var
              :v (SymbolRef 1 "a")
            )
            :ele (IntegerConstant
              :n 4
              :type (Integer
                :kind 4
              )
              :intboz_type :Decimal
            )
          )
          (ListInsert
            :a (Var
              :v (SymbolRef 1 "a")
            )
            :pos (IntegerConstant
              :n 0
              :type (Integer
                :kind 4
              )
              :intboz_type :Decimal
            )
            :ele (IntegerConstant
              :n 0
              :type (Integer
                :kind 4
              )
              :intboz_type :Decimal
            )
          )
          (ListRemove
            :a (Var
              :v (SymbolRef 1 "a")
            )
            :ele (IntegerConstant
              :n 1
              :type (Integer
                :kind 4
              )
              :intboz_type :Decimal
            )
          )
          (ListClear
            :a (Var
              :v (SymbolRef 1 "a")
            )
          )
        ]
      )
    }
  )
  :items []
)

也可以看看

ListRepeat, ListAppend, List