Skip to content

Commit

Permalink
deprecate trace in favor of subscripted stack
Browse files Browse the repository at this point in the history
  • Loading branch information
kaikalii committed Nov 27, 2024
1 parent 3849cc4 commit ab05dbe
Show file tree
Hide file tree
Showing 8 changed files with 34 additions and 24 deletions.
3 changes: 3 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ This version is not yet released. If you are reading this on the website, then t
- Deprecate [`rerank ☇`](https://uiua.org/docs/rerank)
- It was basically always used with a static rank, and that functionality has been subsumed by subscripted [`deshape ♭`](https://uiua.org/docs/deshape) and/or the iterating modifiers listed above
- The dynamic behavior can still be accessed with `°⊸(⧻△)` (though when you would need this is unclear)
- Deprecate [`trace ⸮`](https://uiua.org/docs/trace)
- It is equivalent to subscripted [`stack ?`](https://uiua.org/docs/stack)
- Sequential `?`s, which formatted to [`trace ⸮`](https://uiua.org/docs/trace)s, now format to subscripted [`stack ?`](https://uiua.org/docs/stack)
- Stabilize [`sort ⍆`](https://uiua.org/docs/sort)
- Sorting is a very common operation, and it's useful to have such simple access to it
- Stabilize [`last ⊣`](https://uiua.org/docs/last)
Expand Down
10 changes: 9 additions & 1 deletion site/primitives.json
Original file line number Diff line number Diff line change
Expand Up @@ -617,6 +617,13 @@
"class": "Constant",
"description": "The number of radians in a quarter circle"
},
"eval": {
"args": 2,
"outputs": 1,
"class": "Misc",
"description": "Evalute a string as code at compile time",
"experimental": true
},
"fall": {
"glyph": "",
"args": 1,
Expand Down Expand Up @@ -1308,7 +1315,8 @@
"args": 1,
"outputs": 1,
"class": "Debug",
"description": "Debug print the top value on the stack without popping it"
"description": "Debug print the top value on the stack without popping it",
"deprecated": true
},
"transpose": {
"glyph": "",
Expand Down
7 changes: 4 additions & 3 deletions site/src/tutorial.rs
Original file line number Diff line number Diff line change
Expand Up @@ -299,13 +299,14 @@ fn TutorialBasic() -> impl IntoView {
<p><Prim prim=Pop/>" removes the top item from the stack."</p>
<p>"This is useful when you want to discard a value that you do not need."</p>
<Editor example="1 pop 2 3 4 ◌ 5 6"/>
<Hd id="stack-and-trace"><Prim prim=Stack/>" and "<Prim prim=Trace/></Hd>
<Hd id="stack"><Prim prim=Stack/></Hd>
<p><Prim prim=Stack/>" prints the entire stack."</p>
<p>"It also attaches line and column numbers."</p>
<p>"This is useful for debugging by inspecting the stack."</p>
<Editor example="√+ ? .+ ? 1 ×3 4"/>
<p><Prim prim=Trace/>" prints only the top item on the stack."</p>
<Editor example="+1 ⸮ ×4 trace ×. -3 5"/>
<p><Prim prim=Stack/>" is compatible with a language feature called "<em>"subscripts"</em>". If you add a little subscript number to the right of it, it will only print that many values from the stack."</p>
<p>"We'll talk more about subscripts later. For now, know that you can add subscripts to "<Prim prim=Stack/>" by adding consecutive "<code>"?"</code>"s. The formatter will convert it for you!"</p>
<Editor example="+1 ?? × ??? 4 ?? ×. -3 5 # Try formatting!"/>

<Hd id="challenges">"Challenges"</Hd>
<p>"At the end of most sections of this tutorial, there will be a few challenges to test your understanding."</p>
Expand Down
20 changes: 7 additions & 13 deletions site/text/code_tactility.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,31 +6,25 @@ This exercise can be likened to "feeling" the code, turning it around in your ha

This section covers a few tools that Uiua provides for making code easier to work with and debug.

## [stack]() and [trace]()
## [stack]()

Uiua already prints out any values left on the stack when the program ends. This is usually enough for smaller programs, but sometimes, you need to be able to see what values are on the stack somewhere in the middle of the code.

[stack]() and [trace]() were mentioned near the [beginning](/tutorial/basic#stack-and-trace) of this tutorial. They both print out values from the stack without removing them. [stack]() prints all values while [trace]() only prints one.
[stack]() was mentioned near the [beginning](/tutorial/basic#stack) of this tutorial. It prints out values from the stack without removing them. Subscripting [stack]() prints out only that many values.

```uiua
5 ? 1 [2 3] "uiua"
```

```uiua
5 1 ⇡3 "uiua"
5 1 ?₁ ⇡3 "uiua"
```
As you can see, the line and column number is also printed.

The formatter will convert two `?`s into [trace](). Try it below.
The formatter will convert multiple `?`s that come immediately after [stack]() a subscript. Try it below.

```uiua
?? √5
```

Multiple [trace]()'s next to each other will combine to show multiple stack values.

```uiua
⸮⸮⸮ 1 2 3 4 5
??? √5 7 10
```

[stack]() will show you the boundaries of the functions that values are used in.
Expand All @@ -41,7 +35,7 @@ F ← ×G
F 10 4
```

[stack]() and [trace]() allow you to inspect the stack at a given place in the code. They make it easy to get a quick sense of what values a function is working with.
[stack]() llows you to inspect the stack at a given place in the code. It makes it easy to get a quick sense of what values a function is working with.

## Labels

Expand All @@ -51,7 +45,7 @@ Labels allow you to tag an array with a debug-only name. They are written with a
$Numbers [1 2 3]
```

Labels are *only* visible in debugging outputs. This includes normal interpreter output as well as [stack]() and [trace]().
Labels are *only* visible in debugging outputs. This includes normal interpreter output as well as [stack]().

Labels will *not* be shown when arrays are formatted using [`&p`]() or format strings.

Expand Down
11 changes: 5 additions & 6 deletions src/lex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -999,17 +999,16 @@ impl<'a> Lexer<'a> {
"└" if self.next_char_exact("─") && self.next_char_exact("╴") => {
self.end(CloseModule, start)
}
// Stack and trace
// Stack
"?" => {
self.end(Primitive::Stack, start);
let mut n = 0;
let mut start = start;
let start = self.loc;
while self.next_char_exact("?") {
self.end(Primitive::Trace, start);
start = self.loc;
n += 1;
}
if n == 0 {
self.end(Primitive::Stack, start);
if n > 0 {
self.end(Subscr(Subscript::N(n)), start);
}
}
// Comments
Expand Down
4 changes: 4 additions & 0 deletions src/primitive/defs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3143,6 +3143,10 @@ primitive!(
/// : +×-×+
/// ex: 2_3_10 ? 17 ↯3_4⇡12
/// : ++
/// Subscripted [stack] prints that many values from the stack.
/// ex: ?₂ 1 2 3 4
/// If you type `N+1`` `?`s, it will format to [stack] subscripted with `N`.
/// ex: ??? 1 2 3 4 # Try formatting!
(0(0), Stack, Debug, ("stack", '?'), Impure),
/// Debug print the top value on the stack without popping it
///
Expand Down
1 change: 1 addition & 0 deletions src/primitive/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -535,6 +535,7 @@ impl Primitive {
"use subscripted {} or {Un}{By}({Len}{Shape}) instead",
Deshape.format()
),
Trace => format!("use subscripted {} instead", Stack.format()),
_ => return None,
})
}
Expand Down
2 changes: 1 addition & 1 deletion todo.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
## 0.14
The next version of Uiua

- Validate number literals at compile time
- Stabilize `backward`, `case`
- Optimize `group`/`partition` reduction replacement
- `do` function pack
- Allow for multi-value constant bindings
- Animated WEBP support? (`&webp`)
Expand Down

0 comments on commit ab05dbe

Please sign in to comment.