ListItem¶
One element of a list.
Declaration¶
Syntax¶
ListItem(expr a, expr pos, ttype type, expr? value)
Arguments¶
Argument |
Description |
|---|---|
|
the list. |
|
the index. |
|
the element type. |
|
the compile time value of the expression, when the frontend could fold it; |
Return values¶
The value of the expression.
Description¶
a[i], counting from zero. Reading past the end is an error at run time.
Examples¶
(ListItem
:a (Var
:v (SymbolRef 1 "a")
)
:pos (IntegerConstant
:n 0
:type (Integer
:kind 4
)
:intboz_type :Decimal
)
: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 []
)