Intermediate
This lesson covers the two most common compound data types: strings (text) and lists (ordered collections).
| Primitive | Inputs | Output | Description |
|---|---|---|---|
concat | a, b | string | Join two strings |
length | string | integer | Number of characters |
to-string | any | string | Convert to text |
split | string, separator | list | Split into parts |
trim | string | string | Remove leading/trailing whitespace |
replace | string, old, new | string | Replace occurrences |
A list is an ordered collection. Elements can be any type and can be mixed. Lists are 1-indexed in Phograph (the first element is at position 1).
| Primitive | Inputs | Output | Description |
|---|---|---|---|
get-nth | list, index | element | Get element at position (1-indexed) |
append | list, element | list | Add element to end |
length | list | integer | Number of elements |
sort | list | list | Sort in ascending order |
empty? | list | boolean | True if list is empty |
There is no list-literal node yet. To build a list, start with an empty list
and append elements:
Load String Processing > String Concatenation from the Example Browser.
This example concatenates "Hello, " and "Phograph!",
then logs the result. It demonstrates the concat primitive.
greet (1 input, 1 output) that prepends "Hello, " to the input and appends "!".concat nodes chained together.greet from main with "World"."Hello, World!"."one,two,three,four".split with separator "," to get a list of words.length on the resulting list.4.Write a recursive method reverse (1 input, 1 output):
empty? with nextCaseOnFailure).
If true, return the empty list.get-nth with index 1),
get the rest of the list (you may need a slice or rest primitive),
recursively reverse the rest, and append the first element to the result.If a rest primitive is not available, you can use a recursive
approach where you get-nth the last element, append
it to a new list, and shrink the input. Alternatively, use the built-in
sort as inspiration — the important thing is to practice
recursion with cases.
concat, split, length, etc.append starting from an empty list.to-string converts any value to its text representation.