>> 'foo/bar/baz == foo/bar/baz
Paths are a series of values delimited by slashes (
/). They are a type of
block! that are limited in the types of values that they can contain.
paren! values are supported.
Path! is a member of the following typesets:
Path! values can be created using literal syntax, or at runtime by using a
make constructor or
>> make path! [foo bar baz] == foo/bar/baz
You can create an empty path of a given size by supplying an integer value as an argument to
>> make path! 10 ==
>> to path! "foo bar baz" == foo/bar/baz
It is possible to create
>> mold to path! [a #(b: 2) c 1.2 /z] == "a/#(^/ b: 2^/)/c/1.2//z" >> load mold to path! [a #(b: 2) c 1.2 /z] *** Syntax Error: invalid path! at "a/#( b: 2)/c/1.2//z" *** Where: do *** Stack: load
3. Literal syntax
<path-literal> ::= <path-head>/<selector> <path-head> ::= <word-literal> | <path-literal> <selector> ::= <integer> | <word-literal> | :<word-literal> | <paren>
path: [word! some selector] selector: [#"/" [integer! | word! | get-word! | paren!]]
Path-head datatypes: word!,
4. Evaluation Steps
Paths lead to a nested value, or to a more specific behavior in a function call. They must start with a word, and the value that the word refers to determines how the path will be evaluated.
If the value is a function, the following expressions in the path must be
word!values. These words are treated as refinements in the function call.
>> append/only [foo] == [42 [foo]]
An error will be raised if no corresponding refinement exists in the function:
>> append/xyz [foo] *** Script Error: append has no refinement called xyz *** Where: append *** Stack:
If the value is not a function, the following rules apply:
If the next expression in the path is a word, it is used to
selectfrom the path-head value. The path-head value must be of a type that supports
>> blk: [foo bar baz] == [foo bar baz] >> blk/bar == baz
If the selection does not exist in the path-head value,
select will return
>> blk/sheboygan == none
Word! expressions in paths, after the first, are not evaluated. If you want to evaluate them, use
paren!in the path.
>> selector: 'bar == bar >> my-block: [foo bar baz] == [foo bar baz] >> my-block/:selector == baz
>> my-block/('bar) == baz
If the next expression in the path is an integer, it is used to
pickfrom the path-head value. The path-head value must be of a type that supports
>> blk: [foo bar baz qux] == [foo bar baz qux] >> blk/3 ; pick from the third index of blk == baz
If the integer falls outside the bounds of the path-head value,
>> length? blk == 4 >> blk/7 == none >> blk/-1 == none
5. Testing values
path? to check if a value is of the
>> path? 'foo/bar == true
type? to return the datatype of a given value.
>> type? 'foo/bar == path!
6. Pre-defined words