Repository navigation
Visitvalue
Home › Miscellaneous Keywords › VisitValue
Calls a visitor for one value under a name, by the rule visitfields uses for a field.
visitvalue( name, e, v )-
name: the name passed to the visitor: a string literal or any string expression. -
e: the value to visit: a variable, a field, an array element, a dereference orthis. -
v: the visitor.
visitvalue is a statement. The kind of e's value decides the call, exactly as for a field of visitfields:
e is |
The call |
|---|---|
a type with derive fields
|
v.Enter( name ), then each of its fields by the same rule, then v.Leave( )
|
a containers.Array( of U )
|
v.VisitList( name, e ) |
| anything else | v.Visit( name, e ) |
Each call is an ordinary call: overloads, conversions and constness work as written. See visitfields for the details.
Its main use is inside a visitor's VisitList. A visitor that meets containers.Array fields writes one generic for them:
declare sub VisitList( of U )( byval nm as ustring, byref a as containers.Array( of U ) )A generic body cannot tell what U is, so it cannot choose between Visit and Enter itself. Its loop calls visitvalue( "", a[ i ], this ), or passes a name of its own such as the index, and the compiler makes the choice for each instance: an Array( of int32 ) element goes to Visit, an element with derive fields goes through Enter and Leave, and an Array( of Array( of int32 ) ) element goes to VisitList again.
Keep the generic under its own name, apart from the Visit overloads: tiko, like FreeBASIC, allows one generic procedure per name and does not rank a generic against ordinary overloads of the same name.
visitvalue also works on its own, outside a visitor, on any value that is a place.
#import "std/containers"
type Point
derive fields
as float64 x, y
end type
type Dump
as integer depth
declare sub Visit( byval nm as ustring, byref x as const int32 )
declare sub Visit( byval nm as ustring, byref x as const float64 )
declare sub Enter( byval nm as ustring )
declare sub Leave( )
declare sub VisitList( of U )( byval nm as ustring, byref a as containers.Array( of U ) )
end type
sub Dump.Visit( byval nm as ustring, byref x as const int32 )
print space( depth * 2 ); nm; " ="; x
end sub
sub Dump.Visit( byval nm as ustring, byref x as const float64 )
print space( depth * 2 ); nm; " ="; x
end sub
sub Dump.Enter( byval nm as ustring )
print space( depth * 2 ); nm; " {"
depth += 1
end sub
sub Dump.Leave( )
depth -= 1
print space( depth * 2 ); "}"
end sub
'' The one generic: whatever U is, visitvalue picks Visit, Enter/Leave or VisitList for it.
sub Dump.VisitList( of U )( byval nm as ustring, byref a as containers.Array( of U ) )
print space( depth * 2 ); nm; " ["; a.Count( ); " ]"
depth += 1
for i as integer = 0 to a.Count( ) - 1
visitvalue( nm & "[" & i & "]", a[ i ], this )
next
depth -= 1
end sub
dim as int32 total = 7
dim as Point p = ( 3, 4 )
dim as containers.Array( of int32 ) row0, row1
row0.Push( 1 ) : row0.Push( 2 ) : row1.Push( 3 )
dim as containers.Array( of containers.Array( of int32 ) ) grid
grid.Push( row0 ) : grid.Push( row1 )
dim as Dump d
visitvalue( "total", total, d ) '' an int32: Visit
visitvalue( "p", p, d ) '' a derive fields type: Enter, its fields, Leave
visitvalue( "grid", grid, d ) '' an Array: VisitList, whose elements are Arrays againtotal = 7
p {
x = 3
y = 4
}
grid [ 2 ]
grid[0] [ 2 ]
grid[0][0] = 1
grid[0][1] = 2
grid[1] [ 1 ]
grid[1][0] = 3
| Mistake | Diagnostic |
|---|---|
e or v is an expression, not a place: visitvalue( "n", n + 1, d )
|
TKO1282 |
| not exactly three arguments | TKO1283 |
no Visit overload takes the value |
the ordinary overload error, TKO0698 or TKO0632 |
a derive fields value, and v has no Enter or Leave
|
the ordinary missing-member error, TKO0739 |
-
Not a reserved word. A procedure, variable or other symbol of your own named
visitvaluewins, and the built-in is then out of reach in that scope. - Unlike
visitfields,visitvaluetakes a value of any type: one withoutderive fieldssimply goes toVisit. -
visitvalueis a tiko addition.
Category: Miscellaneous Keywords Kind: statement
tiko-lang · Home · Feature Index · Keyword Index · License
FreeBASIC manual pages reproduced under the GNU FDL 1.3.
- Home
- What Is tiko-lang
- Quick Start
- Installing on macOS
- Android (experimental)
- Debugging
- Feature Index
- Compatibility
- FAQ
- AI Cheatsheet
- Generics
- Interfaces
- For Each
- Iterators
- Tuples
- Array Results
- Defer
- Move Semantics
- Match
- Lambdas
- Block Strings
- String Interpolation
- Partial Types
- String Slices
- Array Slices
- Embed
- Typed Variadics
- C Header Import
- Foreign Library Linking
- UString
- Fixed-Width Types
- Nullptr
- String Library
- Format
- Array
- Map
- Set
- LinkedList
- OrderedMap
- OrderedSet
- Sorting
- Optional
- Result
- Smart Pointers
- Date and Time (Chrono)
- Time Zones
- Filesystem
- File Streams
- Config (INI and TOML)
- Codec
- Hash
- UUID
- OS
- Hardware
- Process
- Net
- HTTP and TLS
- Math Library
- Finance
- Logging
- Terminal TUI Library
- tkControls
- sys/win
- Goroutines and Channels
- LLVM Backend
- tiko build
- tiko test
- tiko doc
- TIKO_COMPILER
- Variable Declarations
- Standard Data Types
- User Defined Types
- Procedures
- Operators
- Control Flow Statements
- Converting Data Types
- Array Functions
- String Functions
- Mathematical Functions
- Bit Manipulation
- Date and Time Functions
- File I/O Functions
- Console Functions
- User Input (Runtime Library)
- User Input Functions (Graphics Library)
- Screen Functions
- 2D Drawing Functions
- Graphics Library Reference
- Graphics Keyword List
- Memory Functions
- Threading Support Functions
- Error Handling Functions
- Operating System Functions
- Preprocessor
- Intrinsic Defines
- Miscellaneous Keywords
- Modularizing