Concept guide
Values, text, and lists
Most Vision data starts with a plain name and a literal. From there, you can shape text, collect values in order, and walk the collection one item at a time.
Start with the value
Vision infers the everyday types from what you write. A number without a point is a whole; one with a point is a decimal. Quoted content is text, and yes or no is a truth value. The word nothingrepresents an absent value where absence is allowed.
The first four names in this example hold text, a whole, a decimal, and a yes/no value. There is no type ceremony around them. The compiler learns each type from its first value and checks later uses against it.
to begin:
the guide is "Field notes"
the pages is 248
the scale is 1.5
the ready is yes
the word is "café ☕"
the span is how many letters are in the word
the opening is the first 4 letters of the word
say "{the guide}: {the pages} pages at {the scale}"
say "{the word} has {the span} letters; first four: {the opening}"
when the ready is yes:
say "ready: yes"to begin:
the guide is "Field notes"
the pages is 248
the scale is 1.5
the ready is yes
the word is "café ☕"
the span is how many letters are in the word
the opening is the first 4 letters of the word
say "{the guide}: {the pages} pages at {the scale}"
say "{the word} has {the span} letters; first four: {the opening}"
when the ready is yes:
say "ready: yes"One whole type, plus bytes
Vision does not have an exact-width integer family such as i32 or u64. An ordinary whole lowers to a signed C int64_t. byte is the separate 0–255 value; a list of bytes uses packed uint8_t storage.
That byte case is useful for files, sockets, and C libraries, but it is not a general menu of integer widths. Code that needs another exact C representation currently crosses the by hand: interop boundary.
Build text around values
Put an expression inside braces to place its rendered value in a piece of text. In "{the pages} pages", the whole value becomes part of the finished sentence. Text, numbers, and enum members can fill these holes. A yes/no value cannot, so the example testsready and prints the matching words directly.
Vision's current text length and slicing operations count Unicode code points, not UTF-8 bytes. That is why "café ☕" has six letters even though some of them take more than one byte. In the syntax, the first 4 letters produces "café".
Here, “letter” means code point rather than a user-perceived grapheme. A character built from several code points will count as several. That distinction matters when you slice emoji sequences or combining marks.
Keep an ordered group
A comma-separated literal creates a list and fixes its element type. When there is no first value to infer from, name the type instead: the samples are a list of decimals makes an empty decimal list.
add grows a list in place. how many are in,the first value in, and the last value in read its shape. An each block visits the values in order and gives the current value a local name.
to begin:
the stages are 3, 5, 8
add 13 to the stages
the count is how many are in the stages
the head stage is the first value in the stages
the tail stage is the last value in the stages
the total is 0
each stage in the stages:
the total is the total plus stage
say "{the count} stages; first {the head stage}; last {the tail stage}; total {the total}"to begin:
the stages are 3, 5, 8
add 13 to the stages
the count is how many are in the stages
the head stage is the first value in the stages
the tail stage is the last value in the stages
the total is 0
each stage in the stages:
the total is the total plus stage
say "{the count} stages; first {the head stage}; last {the tail stage}; total {the total}"Numbered list access is one-based: the first item is at position 1. Insert, remove, sort, and missing-position behavior belong in the language reference; this guide keeps to the operations used in ordinary traversal.
Change the data, then predict the line
In text.vis, replace "café ☕" with"naïve 🐦". Before running it, work out the code-point count and the first four letters. The checked result is seven and"naïv".
Then add 21 to the stages. The list should report five values, a last value of 21, and a total of 50. These two edits use the same data flow as the build-report loop in Reading a Vision program, just without the described thing around it.