You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
- Implement [`under ⍜`](https://uiua.org/docs/under)[`regex`](https://uiua.org/docs/regex) for replacing using regex (called `gsub` in some other languages)
Copy file name to clipboardExpand all lines: parser/src/defs.rs
+29Lines changed: 29 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -3062,6 +3062,35 @@ primitive!(
3062
3062
/// [path] is designed to be maximally flexible, so it can be used with graphs or grids or any other structure.
3063
3063
((2)[2],Path,Algorithm,"path"),
3064
3064
/// Execute a recursive or tree algorithm
3065
+
///
3066
+
/// Takes three functions.
3067
+
/// The first function checks for a base case.
3068
+
/// The second function gets a node's children.
3069
+
/// The third function combines parent and child nodes.
3070
+
///
3071
+
/// If the first function returns a boolean, it determines whether a given node is a leaf node. The second function will only be called on non-leaf nodes.
3072
+
/// The third function is passed the results of all a node's children. If it takes at least 2 arguments, it will also be passed the parent node on top.
3073
+
///
3074
+
/// Many of the examples here can be better expressed using array operations, and are merely demonstrative.
3075
+
///
3076
+
/// We can express a simple recursive factorial function like so.
3077
+
/// ex: Fact ← recur(<2|-1|×)
3078
+
/// : Fact 5
3079
+
/// : Fact 7
3080
+
/// The [less than]`2` determines when to cease recursion. The [subtract]`1` is the next recursive call, the "child node". The [multiply] gets called on a node and the result of its child.
3081
+
///
3082
+
/// We can express the classic recursive fibanacci function in a similar way. In this example, the second function returns two children. The third function ignores the parent node and simply adds the results of the children.
3083
+
/// ex: Fib ← recur(<2|⊃[-1|-2]|/+)
3084
+
/// : Fib 10
3085
+
/// Because a boolean result from the first function returns a node as its own result, that example interprets the 0th fibonacci number to be `0``.
3086
+
/// If we instead want the 0th fibonacci to be `1`, we can return a list of 0 or 1 items from the first function instead. A 1-item list is interpreted as a leaf node, with that item as the result.
3087
+
/// ex: Fib ← recur(▽⊙1<2|⊃[-1|-2]|/+)
3088
+
/// : Fib 10
3089
+
///
3090
+
/// The results of a node's children will be passed to the third function as an array. The creation of this array will fail if the results of the children have incompatible shapes. There is an acception for box lists, which will be [join]ed instead of used as rows. This makes it possible to combine variable-length lists.
3091
+
/// One example use case for this is listing all files in all subdirectories.
0 commit comments