NamedExpr

An assignment that is also an expression.

Declaración

Sintaxis

NamedExpr(expr target, expr value, ttype type)

Argumentos

Argument

Descripción

target

the variable assigned to.

value

the value assigned, which is also the value of the expression.

type

the type of the expression.

Valores devueltos

The value of the expression.

Descripción

This is Python’s x := v. It has no Fortran spelling. The value is stored in target and is also the result of the expression, so it can be used where a value is expected.

Ejemplos

(NamedExpr
  :target (Var
    :v (SymbolRef 1 "i")
  )
  :value (IntegerConstant
    :n 5
    :type (Integer
      :kind 4
    )
    :intboz_type :Decimal
  )
  :type (Integer
    :kind 4
  )
)

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 []
            )
            "j" (Variable
              :parent_symtab 1
              :name "j"
              :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 []
            )
          }
        )
        :name "main"
        :dependencies []
        :body [
          (Assignment
            :target (Var
              :v (SymbolRef 1 "j")
            )
            :value (NamedExpr
              :target (Var
                :v (SymbolRef 1 "i")
              )
              :value (IntegerConstant
                :n 5
                :type (Integer
                  :kind 4
                )
                :intboz_type :Decimal
              )
              :type (Integer
                :kind 4
              )
            )
            :overloaded nil
            :realloc_lhs false
            :move_allocation false
          )
        ]
      )
    }
  )
  :items []
)

Ver también

Assignment, Expr